@graphql-mesh/grpc 0.95.3-alpha-20230822080151-fa4ac7163 → 0.95.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/directives.js +10 -1
- package/cjs/index.js +37 -10
- package/esm/directives.js +9 -0
- package/esm/index.js +40 -13
- package/package.json +1 -1
- package/typings/directives.d.cts +1 -0
- package/typings/directives.d.ts +1 -0
package/cjs/directives.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.grpcRootJsonDirective = exports.ObjMapScalar = exports.grpcConnectivityStateDirective = exports.grpcMethodDirective = void 0;
|
|
3
|
+
exports.grpcRootJsonDirective = exports.ObjMapScalar = exports.EnumDirective = exports.grpcConnectivityStateDirective = exports.grpcMethodDirective = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
exports.grpcMethodDirective = new graphql_1.GraphQLDirective({
|
|
6
6
|
name: 'grpcMethod',
|
|
@@ -32,6 +32,15 @@ exports.grpcConnectivityStateDirective = new graphql_1.GraphQLDirective({
|
|
|
32
32
|
},
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
|
+
exports.EnumDirective = new graphql_1.GraphQLDirective({
|
|
36
|
+
name: 'enum',
|
|
37
|
+
locations: [graphql_1.DirectiveLocation.ENUM_VALUE],
|
|
38
|
+
args: {
|
|
39
|
+
value: {
|
|
40
|
+
type: graphql_1.GraphQLString,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
35
44
|
exports.ObjMapScalar = new graphql_1.GraphQLScalarType({
|
|
36
45
|
name: 'ObjMap',
|
|
37
46
|
serialize: value => JSON.stringify(value),
|
package/cjs/index.js
CHANGED
|
@@ -262,8 +262,9 @@ class GrpcHandler {
|
|
|
262
262
|
}
|
|
263
263
|
const rootTypes = (0, utils_2.getRootTypes)(schema);
|
|
264
264
|
for (const rootType of rootTypes) {
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
const rootTypeFields = rootType.getFields();
|
|
266
|
+
for (const fieldName in rootTypeFields) {
|
|
267
|
+
const field = rootTypeFields[fieldName];
|
|
267
268
|
const directives = (0, utils_2.getDirectives)(schema, field);
|
|
268
269
|
if (directives?.length) {
|
|
269
270
|
for (const directiveObj of directives) {
|
|
@@ -299,6 +300,24 @@ class GrpcHandler {
|
|
|
299
300
|
}
|
|
300
301
|
}
|
|
301
302
|
}
|
|
303
|
+
const typeMap = schema.getTypeMap();
|
|
304
|
+
for (const typeName in typeMap) {
|
|
305
|
+
const type = typeMap[typeName];
|
|
306
|
+
if ((0, graphql_1.isEnumType)(type)) {
|
|
307
|
+
const values = type.getValues();
|
|
308
|
+
for (const value of values) {
|
|
309
|
+
const enumAnnotations = (0, utils_2.getDirective)(schema, value, 'enum');
|
|
310
|
+
if (enumAnnotations?.length) {
|
|
311
|
+
for (const enumAnnotation of enumAnnotations) {
|
|
312
|
+
const enumSerializedValue = enumAnnotation.value;
|
|
313
|
+
if (enumSerializedValue) {
|
|
314
|
+
value.value = JSON.parse(enumSerializedValue);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
302
321
|
}
|
|
303
322
|
visit({ nested, name, currentPath, rootJsonName, rootJson, rootLogger: logger, loadOptions, }) {
|
|
304
323
|
const pathWithName = [...currentPath, ...name.split('.')].filter(Boolean);
|
|
@@ -318,20 +337,28 @@ class GrpcHandler {
|
|
|
318
337
|
}
|
|
319
338
|
const typeName = pathWithName.join('_');
|
|
320
339
|
if ('values' in nested) {
|
|
321
|
-
const
|
|
322
|
-
name: typeName,
|
|
323
|
-
values: {},
|
|
324
|
-
description: nested.comment,
|
|
325
|
-
};
|
|
340
|
+
const enumValues = {};
|
|
326
341
|
const commentMap = nested.comments;
|
|
327
342
|
for (const [key, value] of Object.entries(nested.values)) {
|
|
328
343
|
logger.debug(`Visiting ${currentPath}.nested.values[${key}]`);
|
|
329
|
-
|
|
330
|
-
|
|
344
|
+
enumValues[key] = {
|
|
345
|
+
directives: [
|
|
346
|
+
{
|
|
347
|
+
name: 'enum',
|
|
348
|
+
args: {
|
|
349
|
+
value: JSON.stringify(value),
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
],
|
|
331
353
|
description: commentMap?.[key],
|
|
332
354
|
};
|
|
333
355
|
}
|
|
334
|
-
this.schemaComposer.
|
|
356
|
+
this.schemaComposer.addDirective(directives_js_1.EnumDirective);
|
|
357
|
+
this.schemaComposer.createEnumTC({
|
|
358
|
+
name: typeName,
|
|
359
|
+
values: enumValues,
|
|
360
|
+
description: nested.comment,
|
|
361
|
+
});
|
|
335
362
|
}
|
|
336
363
|
else if ('fields' in nested) {
|
|
337
364
|
const inputTypeName = typeName + '_Input';
|
package/esm/directives.js
CHANGED
|
@@ -29,6 +29,15 @@ export const grpcConnectivityStateDirective = new GraphQLDirective({
|
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
31
|
});
|
|
32
|
+
export const EnumDirective = new GraphQLDirective({
|
|
33
|
+
name: 'enum',
|
|
34
|
+
locations: [DirectiveLocation.ENUM_VALUE],
|
|
35
|
+
args: {
|
|
36
|
+
value: {
|
|
37
|
+
type: GraphQLString,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
32
41
|
export const ObjMapScalar = new GraphQLScalarType({
|
|
33
42
|
name: 'ObjMap',
|
|
34
43
|
serialize: value => JSON.stringify(value),
|
package/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable import/no-duplicates */
|
|
2
2
|
import globby from 'globby';
|
|
3
|
-
import { buildSchema, specifiedDirectives, } from 'graphql';
|
|
4
|
-
import { SchemaComposer } from 'graphql-compose';
|
|
3
|
+
import { buildSchema, isEnumType, specifiedDirectives, } from 'graphql';
|
|
4
|
+
import { SchemaComposer, } from 'graphql-compose';
|
|
5
5
|
import { GraphQLBigInt, GraphQLByte, GraphQLJSON, GraphQLUnsignedInt, GraphQLVoid, } from 'graphql-scalars';
|
|
6
6
|
import lodashGet from 'lodash.get';
|
|
7
7
|
import lodashHas from 'lodash.has';
|
|
@@ -15,7 +15,7 @@ import { readFileOrUrl } from '@graphql-mesh/utils';
|
|
|
15
15
|
import { getDirective, getDirectives, getRootTypes, GraphQLStreamDirective, } 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, ObjMapScalar, } from './directives.js';
|
|
18
|
+
import { EnumDirective, grpcConnectivityStateDirective, grpcMethodDirective, grpcRootJsonDirective, ObjMapScalar, } from './directives.js';
|
|
19
19
|
import './patchLongJs.js';
|
|
20
20
|
import { resolvers as scalarResolvers } from 'graphql-scalars';
|
|
21
21
|
import { addExecutionLogicToScalar } from './scalars.js';
|
|
@@ -259,8 +259,9 @@ export default class GrpcHandler {
|
|
|
259
259
|
}
|
|
260
260
|
const rootTypes = getRootTypes(schema);
|
|
261
261
|
for (const rootType of rootTypes) {
|
|
262
|
-
|
|
263
|
-
|
|
262
|
+
const rootTypeFields = rootType.getFields();
|
|
263
|
+
for (const fieldName in rootTypeFields) {
|
|
264
|
+
const field = rootTypeFields[fieldName];
|
|
264
265
|
const directives = getDirectives(schema, field);
|
|
265
266
|
if (directives?.length) {
|
|
266
267
|
for (const directiveObj of directives) {
|
|
@@ -296,6 +297,24 @@ export default class GrpcHandler {
|
|
|
296
297
|
}
|
|
297
298
|
}
|
|
298
299
|
}
|
|
300
|
+
const typeMap = schema.getTypeMap();
|
|
301
|
+
for (const typeName in typeMap) {
|
|
302
|
+
const type = typeMap[typeName];
|
|
303
|
+
if (isEnumType(type)) {
|
|
304
|
+
const values = type.getValues();
|
|
305
|
+
for (const value of values) {
|
|
306
|
+
const enumAnnotations = getDirective(schema, value, 'enum');
|
|
307
|
+
if (enumAnnotations?.length) {
|
|
308
|
+
for (const enumAnnotation of enumAnnotations) {
|
|
309
|
+
const enumSerializedValue = enumAnnotation.value;
|
|
310
|
+
if (enumSerializedValue) {
|
|
311
|
+
value.value = JSON.parse(enumSerializedValue);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
299
318
|
}
|
|
300
319
|
visit({ nested, name, currentPath, rootJsonName, rootJson, rootLogger: logger, loadOptions, }) {
|
|
301
320
|
const pathWithName = [...currentPath, ...name.split('.')].filter(Boolean);
|
|
@@ -315,20 +334,28 @@ export default class GrpcHandler {
|
|
|
315
334
|
}
|
|
316
335
|
const typeName = pathWithName.join('_');
|
|
317
336
|
if ('values' in nested) {
|
|
318
|
-
const
|
|
319
|
-
name: typeName,
|
|
320
|
-
values: {},
|
|
321
|
-
description: nested.comment,
|
|
322
|
-
};
|
|
337
|
+
const enumValues = {};
|
|
323
338
|
const commentMap = nested.comments;
|
|
324
339
|
for (const [key, value] of Object.entries(nested.values)) {
|
|
325
340
|
logger.debug(`Visiting ${currentPath}.nested.values[${key}]`);
|
|
326
|
-
|
|
327
|
-
|
|
341
|
+
enumValues[key] = {
|
|
342
|
+
directives: [
|
|
343
|
+
{
|
|
344
|
+
name: 'enum',
|
|
345
|
+
args: {
|
|
346
|
+
value: JSON.stringify(value),
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
],
|
|
328
350
|
description: commentMap?.[key],
|
|
329
351
|
};
|
|
330
352
|
}
|
|
331
|
-
this.schemaComposer.
|
|
353
|
+
this.schemaComposer.addDirective(EnumDirective);
|
|
354
|
+
this.schemaComposer.createEnumTC({
|
|
355
|
+
name: typeName,
|
|
356
|
+
values: enumValues,
|
|
357
|
+
description: nested.comment,
|
|
358
|
+
});
|
|
332
359
|
}
|
|
333
360
|
else if ('fields' in nested) {
|
|
334
361
|
const inputTypeName = typeName + '_Input';
|
package/package.json
CHANGED
package/typings/directives.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GraphQLDirective, GraphQLScalarType } from 'graphql';
|
|
2
2
|
export declare const grpcMethodDirective: GraphQLDirective;
|
|
3
3
|
export declare const grpcConnectivityStateDirective: GraphQLDirective;
|
|
4
|
+
export declare const EnumDirective: GraphQLDirective;
|
|
4
5
|
export declare const ObjMapScalar: GraphQLScalarType<any, string>;
|
|
5
6
|
export declare const grpcRootJsonDirective: GraphQLDirective;
|
package/typings/directives.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GraphQLDirective, GraphQLScalarType } from 'graphql';
|
|
2
2
|
export declare const grpcMethodDirective: GraphQLDirective;
|
|
3
3
|
export declare const grpcConnectivityStateDirective: GraphQLDirective;
|
|
4
|
+
export declare const EnumDirective: GraphQLDirective;
|
|
4
5
|
export declare const ObjMapScalar: GraphQLScalarType<any, string>;
|
|
5
6
|
export declare const grpcRootJsonDirective: GraphQLDirective;
|