@graphql-mesh/grpc 0.94.1 → 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 +15 -2
- package/cjs/scalars.js +21 -1
- package/esm/index.js +16 -3
- package/esm/scalars.js +19 -0
- package/package.json +1 -1
- package/typings/scalars.d.cts +2 -0
- package/typings/scalars.d.ts +2 -0
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'];
|
|
@@ -36,9 +38,9 @@ class GrpcHandler {
|
|
|
36
38
|
}
|
|
37
39
|
async processReflection(creds) {
|
|
38
40
|
this.logger.debug(`Using the reflection`);
|
|
39
|
-
const
|
|
41
|
+
const reflectionEndpoint = string_interpolation_1.stringInterpolator.parse(this.config.endpoint, { env: cross_helpers_1.process.env });
|
|
40
42
|
this.logger.debug(`Creating gRPC Reflection Client`);
|
|
41
|
-
const reflectionClient = new grpc_reflection_js_1.Client(
|
|
43
|
+
const reflectionClient = new grpc_reflection_js_1.Client(reflectionEndpoint, creds);
|
|
42
44
|
const subId = this.pubsub.subscribe('destroy', () => {
|
|
43
45
|
reflectionClient.grpcClient.close();
|
|
44
46
|
this.pubsub.unsubscribe(subId);
|
|
@@ -64,6 +66,7 @@ class GrpcHandler {
|
|
|
64
66
|
else {
|
|
65
67
|
fileName = this.config.source;
|
|
66
68
|
}
|
|
69
|
+
fileName = string_interpolation_1.stringInterpolator.parse(fileName, { env: cross_helpers_1.process.env });
|
|
67
70
|
const absoluteFilePath = cross_helpers_1.path.isAbsolute(fileName)
|
|
68
71
|
? fileName
|
|
69
72
|
: cross_helpers_1.path.join(this.baseDir, fileName);
|
|
@@ -114,6 +117,7 @@ class GrpcHandler {
|
|
|
114
117
|
else {
|
|
115
118
|
fileGlob = this.config.source;
|
|
116
119
|
}
|
|
120
|
+
fileGlob = string_interpolation_1.stringInterpolator.parse(fileGlob, { env: cross_helpers_1.process.env });
|
|
117
121
|
const fileNames = await (0, globby_1.default)(fileGlob, {
|
|
118
122
|
cwd: this.baseDir,
|
|
119
123
|
});
|
|
@@ -238,6 +242,15 @@ class GrpcHandler {
|
|
|
238
242
|
};
|
|
239
243
|
}
|
|
240
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
|
+
}
|
|
241
254
|
const queryType = schema.getQueryType();
|
|
242
255
|
const rootJsonAnnotations = (0, utils_2.getDirective)(schema, queryType, 'grpcRootJson');
|
|
243
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'];
|
|
@@ -33,9 +35,9 @@ export default class GrpcHandler {
|
|
|
33
35
|
}
|
|
34
36
|
async processReflection(creds) {
|
|
35
37
|
this.logger.debug(`Using the reflection`);
|
|
36
|
-
const
|
|
38
|
+
const reflectionEndpoint = stringInterpolator.parse(this.config.endpoint, { env: process.env });
|
|
37
39
|
this.logger.debug(`Creating gRPC Reflection Client`);
|
|
38
|
-
const reflectionClient = new Client(
|
|
40
|
+
const reflectionClient = new Client(reflectionEndpoint, creds);
|
|
39
41
|
const subId = this.pubsub.subscribe('destroy', () => {
|
|
40
42
|
reflectionClient.grpcClient.close();
|
|
41
43
|
this.pubsub.unsubscribe(subId);
|
|
@@ -61,6 +63,7 @@ export default class GrpcHandler {
|
|
|
61
63
|
else {
|
|
62
64
|
fileName = this.config.source;
|
|
63
65
|
}
|
|
66
|
+
fileName = stringInterpolator.parse(fileName, { env: process.env });
|
|
64
67
|
const absoluteFilePath = path.isAbsolute(fileName)
|
|
65
68
|
? fileName
|
|
66
69
|
: path.join(this.baseDir, fileName);
|
|
@@ -111,6 +114,7 @@ export default class GrpcHandler {
|
|
|
111
114
|
else {
|
|
112
115
|
fileGlob = this.config.source;
|
|
113
116
|
}
|
|
117
|
+
fileGlob = stringInterpolator.parse(fileGlob, { env: process.env });
|
|
114
118
|
const fileNames = await globby(fileGlob, {
|
|
115
119
|
cwd: this.baseDir,
|
|
116
120
|
});
|
|
@@ -235,6 +239,15 @@ export default class GrpcHandler {
|
|
|
235
239
|
};
|
|
236
240
|
}
|
|
237
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
|
+
}
|
|
238
251
|
const queryType = schema.getQueryType();
|
|
239
252
|
const rootJsonAnnotations = getDirective(schema, queryType, 'grpcRootJson');
|
|
240
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
package/typings/scalars.d.cts
CHANGED
|
@@ -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;
|
package/typings/scalars.d.ts
CHANGED
|
@@ -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;
|