@graphql-mesh/grpc 0.94.2 → 0.94.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -20,6 +20,8 @@ const grpc_js_1 = require("@grpc/grpc-js");
20
20
  const proto_loader_1 = require("@grpc/proto-loader");
21
21
  const directives_js_1 = require("./directives.js");
22
22
  require("./patchLongJs.js");
23
+ const graphql_scalars_2 = require("graphql-scalars");
24
+ const scalars_js_1 = require("./scalars.js");
23
25
  const utils_js_1 = require("./utils.js");
24
26
  const { Root } = protobufjs_1.default;
25
27
  const QUERY_METHOD_PREFIXES = ['get', 'list', 'search'];
@@ -240,6 +242,15 @@ class GrpcHandler {
240
242
  };
241
243
  }
242
244
  processDirectives({ schema, creds }) {
245
+ const schemaTypeMap = schema.getTypeMap();
246
+ for (const scalarTypeName in graphql_scalars_2.resolvers) {
247
+ if (scalarTypeName in schemaTypeMap) {
248
+ (0, scalars_js_1.addExecutionLogicToScalar)(schemaTypeMap[scalarTypeName], graphql_scalars_2.resolvers[scalarTypeName]);
249
+ }
250
+ }
251
+ if ('ObjMap' in schemaTypeMap) {
252
+ (0, scalars_js_1.addExecutionLogicToScalar)(schemaTypeMap.ObjMap, directives_js_1.ObjMapScalar);
253
+ }
243
254
  const queryType = schema.getQueryType();
244
255
  const rootJsonAnnotations = (0, utils_2.getDirective)(schema, queryType, 'grpcRootJson');
245
256
  const rootJsonMap = new Map();
package/cjs/scalars.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGraphQLScalar = exports.isScalarType = void 0;
3
+ exports.addExecutionLogicToScalar = exports.getGraphQLScalar = exports.isScalarType = void 0;
4
4
  const SCALARS = new Map([
5
5
  ['bool', 'Boolean'],
6
6
  ['bytes', 'Byte'],
@@ -30,3 +30,23 @@ function getGraphQLScalar(scalarType) {
30
30
  return SCALARS.get(scalarType);
31
31
  }
32
32
  exports.getGraphQLScalar = getGraphQLScalar;
33
+ function addExecutionLogicToScalar(nonExecutableScalar, actualScalar) {
34
+ Object.defineProperties(nonExecutableScalar, {
35
+ serialize: {
36
+ value: actualScalar.serialize,
37
+ },
38
+ parseValue: {
39
+ value: actualScalar.parseValue,
40
+ },
41
+ parseLiteral: {
42
+ value: actualScalar.parseLiteral,
43
+ },
44
+ extensions: {
45
+ value: {
46
+ ...actualScalar.extensions,
47
+ ...nonExecutableScalar.extensions,
48
+ },
49
+ },
50
+ });
51
+ }
52
+ exports.addExecutionLogicToScalar = addExecutionLogicToScalar;
package/esm/index.js CHANGED
@@ -15,8 +15,10 @@ import { readFileOrUrl } from '@graphql-mesh/utils';
15
15
  import { getDirective, getDirectives, getRootTypes } from '@graphql-tools/utils';
16
16
  import { credentials, loadPackageDefinition } from '@grpc/grpc-js';
17
17
  import { fromJSON } from '@grpc/proto-loader';
18
- import { grpcConnectivityStateDirective, grpcMethodDirective, grpcRootJsonDirective, } from './directives.js';
18
+ import { grpcConnectivityStateDirective, grpcMethodDirective, grpcRootJsonDirective, ObjMapScalar, } from './directives.js';
19
19
  import './patchLongJs.js';
20
+ import { resolvers as scalarResolvers } from 'graphql-scalars';
21
+ import { addExecutionLogicToScalar } from './scalars.js';
20
22
  import { addIncludePathResolver, addMetaDataToCall, getTypeName } from './utils.js';
21
23
  const { Root } = protobufjs;
22
24
  const QUERY_METHOD_PREFIXES = ['get', 'list', 'search'];
@@ -237,6 +239,15 @@ export default class GrpcHandler {
237
239
  };
238
240
  }
239
241
  processDirectives({ schema, creds }) {
242
+ const schemaTypeMap = schema.getTypeMap();
243
+ for (const scalarTypeName in scalarResolvers) {
244
+ if (scalarTypeName in schemaTypeMap) {
245
+ addExecutionLogicToScalar(schemaTypeMap[scalarTypeName], scalarResolvers[scalarTypeName]);
246
+ }
247
+ }
248
+ if ('ObjMap' in schemaTypeMap) {
249
+ addExecutionLogicToScalar(schemaTypeMap.ObjMap, ObjMapScalar);
250
+ }
240
251
  const queryType = schema.getQueryType();
241
252
  const rootJsonAnnotations = getDirective(schema, queryType, 'grpcRootJson');
242
253
  const rootJsonMap = new Map();
package/esm/scalars.js CHANGED
@@ -25,3 +25,22 @@ export function getGraphQLScalar(scalarType) {
25
25
  }
26
26
  return SCALARS.get(scalarType);
27
27
  }
28
+ export function addExecutionLogicToScalar(nonExecutableScalar, actualScalar) {
29
+ Object.defineProperties(nonExecutableScalar, {
30
+ serialize: {
31
+ value: actualScalar.serialize,
32
+ },
33
+ parseValue: {
34
+ value: actualScalar.parseValue,
35
+ },
36
+ parseLiteral: {
37
+ value: actualScalar.parseLiteral,
38
+ },
39
+ extensions: {
40
+ value: {
41
+ ...actualScalar.extensions,
42
+ ...nonExecutableScalar.extensions,
43
+ },
44
+ },
45
+ });
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-mesh/grpc",
3
- "version": "0.94.2",
3
+ "version": "0.94.3",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@graphql-mesh/cross-helpers": "^0.4.0",
@@ -1,2 +1,4 @@
1
+ import { GraphQLScalarType } from 'graphql';
1
2
  export declare function isScalarType(type: string): boolean;
2
3
  export declare function getGraphQLScalar(scalarType: string): string;
4
+ export declare function addExecutionLogicToScalar(nonExecutableScalar: GraphQLScalarType, actualScalar: GraphQLScalarType): void;
@@ -1,2 +1,4 @@
1
+ import { GraphQLScalarType } from 'graphql';
1
2
  export declare function isScalarType(type: string): boolean;
2
3
  export declare function getGraphQLScalar(scalarType: string): string;
4
+ export declare function addExecutionLogicToScalar(nonExecutableScalar: GraphQLScalarType, actualScalar: GraphQLScalarType): void;