@omnigraph/grpc 0.2.1 → 0.2.2-alpha-20250117111022-41cb57e51d721fa0c43fb3af2cbc7d7124178c93
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/grpcLoaderHelper.js +25 -3
- package/esm/grpcLoaderHelper.js +25 -3
- package/package.json +2 -1
package/cjs/grpcLoaderHelper.js
CHANGED
|
@@ -6,6 +6,7 @@ const globby_1 = tslib_1.__importDefault(require("globby"));
|
|
|
6
6
|
const graphql_1 = require("graphql");
|
|
7
7
|
const graphql_compose_1 = require("graphql-compose");
|
|
8
8
|
const graphql_scalars_1 = require("graphql-scalars");
|
|
9
|
+
const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
|
|
9
10
|
const protobufjs_1 = tslib_1.__importDefault(require("protobufjs"));
|
|
10
11
|
const index_js_1 = tslib_1.__importDefault(require("protobufjs/ext/descriptor/index.js"));
|
|
11
12
|
const grpc_reflection_js_1 = require("@ardatan/grpc-reflection-js");
|
|
@@ -385,9 +386,30 @@ class GrpcLoaderHelper extends disposablestack_1.DisposableStack {
|
|
|
385
386
|
fieldConfig.args = fieldConfigArgs;
|
|
386
387
|
const methodNameLowerCased = methodName.toLowerCase();
|
|
387
388
|
const prefixQueryMethod = this.config.prefixQueryMethod || QUERY_METHOD_PREFIXES;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
389
|
+
let rootTypeComposer;
|
|
390
|
+
if (this.config.selectQueryOrMutationField) {
|
|
391
|
+
const selection = this.config.selectQueryOrMutationField.find(selection => (0, micromatch_1.default)([rootFieldName], selection.fieldName).length > 0);
|
|
392
|
+
const rootTypeName = selection?.type?.toLowerCase();
|
|
393
|
+
if (rootTypeName) {
|
|
394
|
+
if (rootTypeName === 'query') {
|
|
395
|
+
rootTypeComposer = this.schemaComposer.Query;
|
|
396
|
+
}
|
|
397
|
+
else if (rootTypeName === 'mutation') {
|
|
398
|
+
rootTypeComposer = this.schemaComposer.Mutation;
|
|
399
|
+
}
|
|
400
|
+
else if (rootTypeName === 'subscription') {
|
|
401
|
+
rootTypeComposer = this.schemaComposer.Subscription;
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
throw new Error(`Unknown type provided ${selection.type} for ${rootFieldName}; available options are Query, Mutation and Subscription`);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (rootTypeComposer == null) {
|
|
409
|
+
rootTypeComposer = prefixQueryMethod.some(prefix => methodNameLowerCased.startsWith(prefix))
|
|
410
|
+
? this.schemaComposer.Query
|
|
411
|
+
: this.schemaComposer.Mutation;
|
|
412
|
+
}
|
|
391
413
|
this.schemaComposer.addDirective(directives_js_1.grpcMethodDirective);
|
|
392
414
|
rootTypeComposer.addFields({
|
|
393
415
|
[rootFieldName]: {
|
package/esm/grpcLoaderHelper.js
CHANGED
|
@@ -2,6 +2,7 @@ import globby from 'globby';
|
|
|
2
2
|
import { specifiedDirectives } from 'graphql';
|
|
3
3
|
import { SchemaComposer, } from 'graphql-compose';
|
|
4
4
|
import { GraphQLBigInt, GraphQLByte, GraphQLJSON, GraphQLUnsignedInt, GraphQLVoid, } from 'graphql-scalars';
|
|
5
|
+
import micromatch from 'micromatch';
|
|
5
6
|
import protobufjs from 'protobufjs';
|
|
6
7
|
import descriptor from 'protobufjs/ext/descriptor/index.js';
|
|
7
8
|
import { Client } from '@ardatan/grpc-reflection-js';
|
|
@@ -381,9 +382,30 @@ export class GrpcLoaderHelper extends DisposableStack {
|
|
|
381
382
|
fieldConfig.args = fieldConfigArgs;
|
|
382
383
|
const methodNameLowerCased = methodName.toLowerCase();
|
|
383
384
|
const prefixQueryMethod = this.config.prefixQueryMethod || QUERY_METHOD_PREFIXES;
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
385
|
+
let rootTypeComposer;
|
|
386
|
+
if (this.config.selectQueryOrMutationField) {
|
|
387
|
+
const selection = this.config.selectQueryOrMutationField.find(selection => micromatch([rootFieldName], selection.fieldName).length > 0);
|
|
388
|
+
const rootTypeName = selection?.type?.toLowerCase();
|
|
389
|
+
if (rootTypeName) {
|
|
390
|
+
if (rootTypeName === 'query') {
|
|
391
|
+
rootTypeComposer = this.schemaComposer.Query;
|
|
392
|
+
}
|
|
393
|
+
else if (rootTypeName === 'mutation') {
|
|
394
|
+
rootTypeComposer = this.schemaComposer.Mutation;
|
|
395
|
+
}
|
|
396
|
+
else if (rootTypeName === 'subscription') {
|
|
397
|
+
rootTypeComposer = this.schemaComposer.Subscription;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
throw new Error(`Unknown type provided ${selection.type} for ${rootFieldName}; available options are Query, Mutation and Subscription`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (rootTypeComposer == null) {
|
|
405
|
+
rootTypeComposer = prefixQueryMethod.some(prefix => methodNameLowerCased.startsWith(prefix))
|
|
406
|
+
? this.schemaComposer.Query
|
|
407
|
+
: this.schemaComposer.Mutation;
|
|
408
|
+
}
|
|
387
409
|
this.schemaComposer.addDirective(grpcMethodDirective);
|
|
388
410
|
rootTypeComposer.addFields({
|
|
389
411
|
[rootFieldName]: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnigraph/grpc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2-alpha-20250117111022-41cb57e51d721fa0c43fb3af2cbc7d7124178c93",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "*"
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"graphql-compose": "^9.1.0",
|
|
18
18
|
"graphql-scalars": "^1.23.0",
|
|
19
19
|
"lodash.has": "^4.5.2",
|
|
20
|
+
"micromatch": "^4.0.8",
|
|
20
21
|
"protobufjs": "^7.2.5"
|
|
21
22
|
},
|
|
22
23
|
"repository": {
|