@omnigraph/grpc 0.2.0 → 0.2.1-alpha-20250115110131-0a17f005ed7fae40ae55fe4276c949bb61c17531
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
CHANGED
|
@@ -18,17 +18,14 @@ const directives_js_1 = require("./directives.js");
|
|
|
18
18
|
const utils_js_1 = require("./utils.js");
|
|
19
19
|
const { Root } = protobufjs_1.default;
|
|
20
20
|
const QUERY_METHOD_PREFIXES = ['get', 'list', 'search'];
|
|
21
|
-
class GrpcLoaderHelper {
|
|
21
|
+
class GrpcLoaderHelper extends disposablestack_1.DisposableStack {
|
|
22
22
|
constructor(subgraphName, baseDir, logger, config) {
|
|
23
|
+
super();
|
|
23
24
|
this.subgraphName = subgraphName;
|
|
24
25
|
this.baseDir = baseDir;
|
|
25
26
|
this.logger = logger;
|
|
26
27
|
this.config = config;
|
|
27
28
|
this.schemaComposer = new graphql_compose_1.SchemaComposer();
|
|
28
|
-
this.asyncDisposableStack = new disposablestack_1.AsyncDisposableStack();
|
|
29
|
-
}
|
|
30
|
-
[Symbol.asyncDispose]() {
|
|
31
|
-
return this.asyncDisposableStack.disposeAsync();
|
|
32
29
|
}
|
|
33
30
|
async buildSchema() {
|
|
34
31
|
this.schemaComposer.add(graphql_scalars_1.GraphQLBigInt);
|
|
@@ -53,6 +50,7 @@ class GrpcLoaderHelper {
|
|
|
53
50
|
this.config.requestTimeout = this.config.requestTimeout || 200000;
|
|
54
51
|
this.logger.debug(`Getting channel credentials`);
|
|
55
52
|
const creds = await this.getCredentials();
|
|
53
|
+
this.defer(() => creds._unref());
|
|
56
54
|
this.logger.debug(`Getting stored root and decoded descriptor set objects`);
|
|
57
55
|
const descriptorSets = await this.getDescriptorSets(creds);
|
|
58
56
|
const directives = [];
|
|
@@ -100,7 +98,7 @@ class GrpcLoaderHelper {
|
|
|
100
98
|
const reflectionEndpoint = string_interpolation_1.stringInterpolator.parse(this.config.endpoint, { env: process.env });
|
|
101
99
|
this.logger.debug(`Creating gRPC Reflection Client`);
|
|
102
100
|
const reflectionClient = new grpc_reflection_js_1.Client(reflectionEndpoint, creds);
|
|
103
|
-
this.
|
|
101
|
+
this.defer(() => reflectionClient.grpcClient.close());
|
|
104
102
|
return reflectionClient.listServices().then(services => services.filter(service => service && !service?.startsWith('grpc.')).map(service => {
|
|
105
103
|
this.logger.debug(`Resolving root of Service: ${service} from the reflection response`);
|
|
106
104
|
return reflectionClient.fileContainingSymbol(service);
|
package/cjs/index.js
CHANGED
|
@@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.loadGrpcSubgraph = loadGrpcSubgraph;
|
|
4
4
|
const grpcLoaderHelper_js_1 = require("./grpcLoaderHelper.js");
|
|
5
5
|
function loadGrpcSubgraph(name, options) {
|
|
6
|
-
return (ctx) =>
|
|
7
|
-
name,
|
|
8
|
-
schema
|
|
9
|
-
|
|
6
|
+
return (ctx) => {
|
|
7
|
+
const helper = new grpcLoaderHelper_js_1.GrpcLoaderHelper(name, ctx.cwd, ctx.logger, options);
|
|
8
|
+
const schema$ = helper.buildSchema().finally(() => helper.dispose());
|
|
9
|
+
return {
|
|
10
|
+
name,
|
|
11
|
+
schema$,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
10
14
|
}
|
package/esm/grpcLoaderHelper.js
CHANGED
|
@@ -9,22 +9,19 @@ import { fs, path } from '@graphql-mesh/cross-helpers';
|
|
|
9
9
|
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
10
10
|
import { GraphQLStreamDirective } from '@graphql-tools/utils';
|
|
11
11
|
import { credentials } from '@grpc/grpc-js';
|
|
12
|
-
import {
|
|
12
|
+
import { DisposableStack } from '@whatwg-node/disposablestack';
|
|
13
13
|
import { EnumDirective, grpcConnectivityStateDirective, grpcMethodDirective, transportDirective, } from './directives.js';
|
|
14
14
|
import { addIncludePathResolver, getTypeName, walkToFindTypePath } from './utils.js';
|
|
15
15
|
const { Root } = protobufjs;
|
|
16
16
|
const QUERY_METHOD_PREFIXES = ['get', 'list', 'search'];
|
|
17
|
-
export class GrpcLoaderHelper {
|
|
17
|
+
export class GrpcLoaderHelper extends DisposableStack {
|
|
18
18
|
constructor(subgraphName, baseDir, logger, config) {
|
|
19
|
+
super();
|
|
19
20
|
this.subgraphName = subgraphName;
|
|
20
21
|
this.baseDir = baseDir;
|
|
21
22
|
this.logger = logger;
|
|
22
23
|
this.config = config;
|
|
23
24
|
this.schemaComposer = new SchemaComposer();
|
|
24
|
-
this.asyncDisposableStack = new AsyncDisposableStack();
|
|
25
|
-
}
|
|
26
|
-
[Symbol.asyncDispose]() {
|
|
27
|
-
return this.asyncDisposableStack.disposeAsync();
|
|
28
25
|
}
|
|
29
26
|
async buildSchema() {
|
|
30
27
|
this.schemaComposer.add(GraphQLBigInt);
|
|
@@ -49,6 +46,7 @@ export class GrpcLoaderHelper {
|
|
|
49
46
|
this.config.requestTimeout = this.config.requestTimeout || 200000;
|
|
50
47
|
this.logger.debug(`Getting channel credentials`);
|
|
51
48
|
const creds = await this.getCredentials();
|
|
49
|
+
this.defer(() => creds._unref());
|
|
52
50
|
this.logger.debug(`Getting stored root and decoded descriptor set objects`);
|
|
53
51
|
const descriptorSets = await this.getDescriptorSets(creds);
|
|
54
52
|
const directives = [];
|
|
@@ -96,7 +94,7 @@ export class GrpcLoaderHelper {
|
|
|
96
94
|
const reflectionEndpoint = stringInterpolator.parse(this.config.endpoint, { env: process.env });
|
|
97
95
|
this.logger.debug(`Creating gRPC Reflection Client`);
|
|
98
96
|
const reflectionClient = new Client(reflectionEndpoint, creds);
|
|
99
|
-
this.
|
|
97
|
+
this.defer(() => reflectionClient.grpcClient.close());
|
|
100
98
|
return reflectionClient.listServices().then(services => services.filter(service => service && !service?.startsWith('grpc.')).map(service => {
|
|
101
99
|
this.logger.debug(`Resolving root of Service: ${service} from the reflection response`);
|
|
102
100
|
return reflectionClient.fileContainingSymbol(service);
|
package/esm/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { GrpcLoaderHelper } from './grpcLoaderHelper.js';
|
|
2
2
|
export function loadGrpcSubgraph(name, options) {
|
|
3
|
-
return (ctx) =>
|
|
4
|
-
name,
|
|
5
|
-
schema
|
|
6
|
-
|
|
3
|
+
return (ctx) => {
|
|
4
|
+
const helper = new GrpcLoaderHelper(name, ctx.cwd, ctx.logger, options);
|
|
5
|
+
const schema$ = helper.buildSchema().finally(() => helper.dispose());
|
|
6
|
+
return {
|
|
7
|
+
name,
|
|
8
|
+
schema$,
|
|
9
|
+
};
|
|
10
|
+
};
|
|
7
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnigraph/grpc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1-alpha-20250115110131-0a17f005ed7fae40ae55fe4276c949bb61c17531",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "*"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@grpc/grpc-js": "^1.1.7",
|
|
15
15
|
"@whatwg-node/disposablestack": "^0.0.5",
|
|
16
16
|
"globby": "^11.1.0",
|
|
17
|
-
"graphql-compose": "^9.0
|
|
17
|
+
"graphql-compose": "^9.1.0",
|
|
18
18
|
"graphql-scalars": "^1.23.0",
|
|
19
19
|
"lodash.has": "^4.5.2",
|
|
20
20
|
"protobufjs": "^7.2.5"
|
|
@@ -2,15 +2,14 @@ import protobufjs, { type AnyNestedObject } from 'protobufjs';
|
|
|
2
2
|
import type { Logger, YamlConfig } from '@graphql-mesh/types';
|
|
3
3
|
import { type MaybePromise } from '@graphql-tools/utils';
|
|
4
4
|
import { type ChannelCredentials } from '@grpc/grpc-js';
|
|
5
|
-
|
|
5
|
+
import { DisposableStack } from '@whatwg-node/disposablestack';
|
|
6
|
+
export declare class GrpcLoaderHelper extends DisposableStack {
|
|
6
7
|
private subgraphName;
|
|
7
8
|
private baseDir;
|
|
8
9
|
private logger;
|
|
9
10
|
private config;
|
|
10
11
|
private schemaComposer;
|
|
11
|
-
private asyncDisposableStack;
|
|
12
12
|
constructor(subgraphName: string, baseDir: string, logger: Logger, config: YamlConfig.GrpcHandler);
|
|
13
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
14
13
|
buildSchema(): Promise<import("graphql").GraphQLSchema>;
|
|
15
14
|
private processReflection;
|
|
16
15
|
private processDescriptorFile;
|
|
@@ -2,15 +2,14 @@ import protobufjs, { type AnyNestedObject } from 'protobufjs';
|
|
|
2
2
|
import type { Logger, YamlConfig } from '@graphql-mesh/types';
|
|
3
3
|
import { type MaybePromise } from '@graphql-tools/utils';
|
|
4
4
|
import { type ChannelCredentials } from '@grpc/grpc-js';
|
|
5
|
-
|
|
5
|
+
import { DisposableStack } from '@whatwg-node/disposablestack';
|
|
6
|
+
export declare class GrpcLoaderHelper extends DisposableStack {
|
|
6
7
|
private subgraphName;
|
|
7
8
|
private baseDir;
|
|
8
9
|
private logger;
|
|
9
10
|
private config;
|
|
10
11
|
private schemaComposer;
|
|
11
|
-
private asyncDisposableStack;
|
|
12
12
|
constructor(subgraphName: string, baseDir: string, logger: Logger, config: YamlConfig.GrpcHandler);
|
|
13
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
14
13
|
buildSchema(): Promise<import("graphql").GraphQLSchema>;
|
|
15
14
|
private processReflection;
|
|
16
15
|
private processDescriptorFile;
|