@graphql-mesh/grpc 0.96.0-alpha-20230908150504-73894e2d1 → 0.96.0

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.
Files changed (3) hide show
  1. package/cjs/index.js +54 -16
  2. package/esm/index.js +54 -16
  3. package/package.json +7 -7
package/cjs/index.js CHANGED
@@ -277,11 +277,23 @@ class GrpcHandler {
277
277
  objPath,
278
278
  creds,
279
279
  });
280
- field.resolve = this.getFieldResolver({
281
- client,
282
- methodName,
283
- isResponseStream: responseStream,
284
- });
280
+ if (rootType.name === 'Subscription') {
281
+ field.subscribe = this.getFieldResolver({
282
+ client,
283
+ methodName,
284
+ isResponseStream: responseStream,
285
+ });
286
+ field.resolve = function identityFn(root) {
287
+ return root;
288
+ };
289
+ }
290
+ else {
291
+ field.resolve = this.getFieldResolver({
292
+ client,
293
+ methodName,
294
+ isResponseStream: responseStream,
295
+ });
296
+ }
285
297
  break;
286
298
  }
287
299
  case 'grpcConnectivityState': {
@@ -311,7 +323,9 @@ class GrpcHandler {
311
323
  for (const enumAnnotation of enumAnnotations) {
312
324
  const enumSerializedValue = enumAnnotation.value;
313
325
  if (enumSerializedValue) {
314
- value.value = JSON.parse(enumSerializedValue);
326
+ const serializedValue = JSON.parse(enumSerializedValue);
327
+ value.value = serializedValue;
328
+ type._valueLookup.set(serializedValue, value);
315
329
  }
316
330
  }
317
331
  }
@@ -431,22 +445,25 @@ class GrpcHandler {
431
445
  for (const methodName in nested.methods) {
432
446
  const method = nested.methods[methodName];
433
447
  const rootFieldName = [...pathWithName, methodName].join('_');
448
+ const fieldConfigTypeFactory = () => {
449
+ const baseResponseTypePath = method.responseType?.split('.');
450
+ if (baseResponseTypePath) {
451
+ const responseTypePath = this.walkToFindTypePath(rootJson, pathWithName, baseResponseTypePath);
452
+ return (0, utils_js_1.getTypeName)(this.schemaComposer, responseTypePath, false);
453
+ }
454
+ return 'Void';
455
+ };
434
456
  const fieldConfig = {
435
457
  type: () => {
436
- const baseResponseTypePath = method.responseType?.split('.');
437
- if (baseResponseTypePath) {
438
- const responseTypePath = this.walkToFindTypePath(rootJson, pathWithName, baseResponseTypePath);
439
- let typeName = (0, utils_js_1.getTypeName)(this.schemaComposer, responseTypePath, false);
440
- if (method.responseStream) {
441
- typeName = `[${typeName}]`;
442
- }
443
- return typeName;
458
+ const typeName = fieldConfigTypeFactory();
459
+ if (method.responseStream) {
460
+ return `[${typeName}]`;
444
461
  }
445
- return 'Void';
462
+ return typeName;
446
463
  },
447
464
  description: method.comment,
448
465
  };
449
- fieldConfig.args = {
466
+ const fieldConfigArgs = {
450
467
  input: () => {
451
468
  if (method.requestStream) {
452
469
  return 'File';
@@ -460,6 +477,7 @@ class GrpcHandler {
460
477
  return undefined;
461
478
  },
462
479
  };
480
+ fieldConfig.args = fieldConfigArgs;
463
481
  const methodNameLowerCased = methodName.toLowerCase();
464
482
  const prefixQueryMethod = this.config.prefixQueryMethod || QUERY_METHOD_PREFIXES;
465
483
  const rootTypeComposer = prefixQueryMethod.some(prefix => methodNameLowerCased.startsWith(prefix))
@@ -482,6 +500,26 @@ class GrpcHandler {
482
500
  ],
483
501
  },
484
502
  });
503
+ if (method.responseStream) {
504
+ this.schemaComposer.Subscription.addFields({
505
+ [rootFieldName]: {
506
+ args: fieldConfigArgs,
507
+ description: method.comment,
508
+ type: fieldConfigTypeFactory,
509
+ directives: [
510
+ {
511
+ name: 'grpcMethod',
512
+ args: {
513
+ rootJsonName,
514
+ objPath,
515
+ methodName,
516
+ responseStream: true,
517
+ },
518
+ },
519
+ ],
520
+ },
521
+ });
522
+ }
485
523
  }
486
524
  const connectivityStateFieldName = pathWithName.join('_') + '_connectivityState';
487
525
  this.schemaComposer.addDirective(directives_js_1.grpcConnectivityStateDirective);
package/esm/index.js CHANGED
@@ -274,11 +274,23 @@ export default class GrpcHandler {
274
274
  objPath,
275
275
  creds,
276
276
  });
277
- field.resolve = this.getFieldResolver({
278
- client,
279
- methodName,
280
- isResponseStream: responseStream,
281
- });
277
+ if (rootType.name === 'Subscription') {
278
+ field.subscribe = this.getFieldResolver({
279
+ client,
280
+ methodName,
281
+ isResponseStream: responseStream,
282
+ });
283
+ field.resolve = function identityFn(root) {
284
+ return root;
285
+ };
286
+ }
287
+ else {
288
+ field.resolve = this.getFieldResolver({
289
+ client,
290
+ methodName,
291
+ isResponseStream: responseStream,
292
+ });
293
+ }
282
294
  break;
283
295
  }
284
296
  case 'grpcConnectivityState': {
@@ -308,7 +320,9 @@ export default class GrpcHandler {
308
320
  for (const enumAnnotation of enumAnnotations) {
309
321
  const enumSerializedValue = enumAnnotation.value;
310
322
  if (enumSerializedValue) {
311
- value.value = JSON.parse(enumSerializedValue);
323
+ const serializedValue = JSON.parse(enumSerializedValue);
324
+ value.value = serializedValue;
325
+ type._valueLookup.set(serializedValue, value);
312
326
  }
313
327
  }
314
328
  }
@@ -428,22 +442,25 @@ export default class GrpcHandler {
428
442
  for (const methodName in nested.methods) {
429
443
  const method = nested.methods[methodName];
430
444
  const rootFieldName = [...pathWithName, methodName].join('_');
445
+ const fieldConfigTypeFactory = () => {
446
+ const baseResponseTypePath = method.responseType?.split('.');
447
+ if (baseResponseTypePath) {
448
+ const responseTypePath = this.walkToFindTypePath(rootJson, pathWithName, baseResponseTypePath);
449
+ return getTypeName(this.schemaComposer, responseTypePath, false);
450
+ }
451
+ return 'Void';
452
+ };
431
453
  const fieldConfig = {
432
454
  type: () => {
433
- const baseResponseTypePath = method.responseType?.split('.');
434
- if (baseResponseTypePath) {
435
- const responseTypePath = this.walkToFindTypePath(rootJson, pathWithName, baseResponseTypePath);
436
- let typeName = getTypeName(this.schemaComposer, responseTypePath, false);
437
- if (method.responseStream) {
438
- typeName = `[${typeName}]`;
439
- }
440
- return typeName;
455
+ const typeName = fieldConfigTypeFactory();
456
+ if (method.responseStream) {
457
+ return `[${typeName}]`;
441
458
  }
442
- return 'Void';
459
+ return typeName;
443
460
  },
444
461
  description: method.comment,
445
462
  };
446
- fieldConfig.args = {
463
+ const fieldConfigArgs = {
447
464
  input: () => {
448
465
  if (method.requestStream) {
449
466
  return 'File';
@@ -457,6 +474,7 @@ export default class GrpcHandler {
457
474
  return undefined;
458
475
  },
459
476
  };
477
+ fieldConfig.args = fieldConfigArgs;
460
478
  const methodNameLowerCased = methodName.toLowerCase();
461
479
  const prefixQueryMethod = this.config.prefixQueryMethod || QUERY_METHOD_PREFIXES;
462
480
  const rootTypeComposer = prefixQueryMethod.some(prefix => methodNameLowerCased.startsWith(prefix))
@@ -479,6 +497,26 @@ export default class GrpcHandler {
479
497
  ],
480
498
  },
481
499
  });
500
+ if (method.responseStream) {
501
+ this.schemaComposer.Subscription.addFields({
502
+ [rootFieldName]: {
503
+ args: fieldConfigArgs,
504
+ description: method.comment,
505
+ type: fieldConfigTypeFactory,
506
+ directives: [
507
+ {
508
+ name: 'grpcMethod',
509
+ args: {
510
+ rootJsonName,
511
+ objPath,
512
+ methodName,
513
+ responseStream: true,
514
+ },
515
+ },
516
+ ],
517
+ },
518
+ });
519
+ }
482
520
  }
483
521
  const connectivityStateFieldName = pathWithName.join('_') + '_connectivityState';
484
522
  this.schemaComposer.addDirective(grpcConnectivityStateDirective);
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@graphql-mesh/grpc",
3
- "version": "0.96.0-alpha-20230908150504-73894e2d1",
3
+ "version": "0.96.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/cross-helpers": "^0.4.0",
7
- "@graphql-mesh/store": "^0.95.2",
8
- "@graphql-mesh/types": "^0.95.2",
9
- "@graphql-mesh/utils": "^0.95.2",
6
+ "@graphql-mesh/cross-helpers": "^0.4.1",
7
+ "@graphql-mesh/store": "^0.95.7",
8
+ "@graphql-mesh/types": "^0.95.7",
9
+ "@graphql-mesh/utils": "^0.95.7",
10
10
  "@graphql-tools/utils": "^9.2.1 || ^10.0.0",
11
11
  "graphql": "*",
12
12
  "tslib": "^2.4.0"
13
13
  },
14
14
  "dependencies": {
15
15
  "@ardatan/grpc-reflection-js": "^0.0.2",
16
- "@graphql-mesh/string-interpolation": "^0.5.1",
16
+ "@graphql-mesh/string-interpolation": "^0.5.2",
17
17
  "@grpc/grpc-js": "^1.1.7",
18
18
  "@grpc/proto-loader": "^0.7.8",
19
19
  "globby": "^11.1.0",
20
20
  "graphql-compose": "^9.0.10",
21
- "graphql-scalars": "^1.22.2",
21
+ "graphql-scalars": "^1.22.4",
22
22
  "lodash.get": "^4.4.2",
23
23
  "lodash.has": "^4.5.2",
24
24
  "long": "4.0.0",