@graphql-mesh/transport-grpc 0.2.1-alpha-20250108093422-7f247cc2650f51e795db1aa17613a11aae6d14cb → 0.2.1
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 +16 -4
- package/cjs/utils.js +2 -2
- package/esm/index.js +16 -4
- package/esm/utils.js +2 -2
- package/package.json +3 -3
- package/typings/index.d.cts +1 -1
- package/typings/index.d.ts +1 -1
package/cjs/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const proto_loader_1 = require("@grpc/proto-loader");
|
|
|
14
14
|
const disposablestack_1 = require("@whatwg-node/disposablestack");
|
|
15
15
|
const utils_js_1 = require("./utils.js");
|
|
16
16
|
require("./patchLongJs.js");
|
|
17
|
+
const utils_2 = require("@graphql-mesh/utils");
|
|
17
18
|
class GrpcTransportHelper extends disposablestack_1.DisposableStack {
|
|
18
19
|
constructor(subgraphName, baseDir, logger, endpoint, config) {
|
|
19
20
|
super();
|
|
@@ -108,6 +109,11 @@ class GrpcTransportHelper extends disposablestack_1.DisposableStack {
|
|
|
108
109
|
const transportDirective = (0, utils_1.getDirective)(schema, schema, 'transport');
|
|
109
110
|
if (transportDirective) {
|
|
110
111
|
for (const directive of transportDirective) {
|
|
112
|
+
if (directive?.subgraph != null &&
|
|
113
|
+
this.subgraphName != null &&
|
|
114
|
+
directive.subgraph !== this.subgraphName) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
111
117
|
if (directive?.options?.roots) {
|
|
112
118
|
roots = directive.options.roots;
|
|
113
119
|
break;
|
|
@@ -131,6 +137,11 @@ class GrpcTransportHelper extends disposablestack_1.DisposableStack {
|
|
|
131
137
|
const directives = (0, utils_1.getDirectives)(schema, field);
|
|
132
138
|
if (directives?.length) {
|
|
133
139
|
for (const directiveObj of directives) {
|
|
140
|
+
if (this.subgraphName &&
|
|
141
|
+
directiveObj.args?.subgraph &&
|
|
142
|
+
directiveObj.args.subgraph !== this.subgraphName) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
134
145
|
switch (directiveObj.name) {
|
|
135
146
|
case 'grpcMethod': {
|
|
136
147
|
const { rootJsonName, objPath, methodName, responseStream } = directiveObj.args;
|
|
@@ -149,9 +160,7 @@ class GrpcTransportHelper extends disposablestack_1.DisposableStack {
|
|
|
149
160
|
methodName,
|
|
150
161
|
isResponseStream: responseStream,
|
|
151
162
|
});
|
|
152
|
-
field.resolve =
|
|
153
|
-
return root;
|
|
154
|
-
};
|
|
163
|
+
field.resolve = identityFn;
|
|
155
164
|
}
|
|
156
165
|
else {
|
|
157
166
|
field.resolve = this.getFieldResolver({
|
|
@@ -214,7 +223,10 @@ exports.default = {
|
|
|
214
223
|
const transport = new GrpcTransportHelper(transportEntry.subgraph, cwd, logger, transportEntry.location, transportEntry.options);
|
|
215
224
|
return (0, utils_1.mapMaybePromise)(transport.getCredentials(), creds => {
|
|
216
225
|
transport.processDirectives({ schema: subgraph, creds });
|
|
217
|
-
return (0, transport_common_1.createDefaultExecutor)(subgraph);
|
|
226
|
+
return (0, utils_2.makeDisposable)((0, transport_common_1.createDefaultExecutor)(subgraph), () => transport.dispose());
|
|
218
227
|
});
|
|
219
228
|
},
|
|
220
229
|
};
|
|
230
|
+
function identityFn(obj) {
|
|
231
|
+
return obj;
|
|
232
|
+
}
|
package/cjs/utils.js
CHANGED
|
@@ -43,9 +43,9 @@ function addMetaDataToCall(callFn, input, resolverData, metaData, isResponseStre
|
|
|
43
43
|
});
|
|
44
44
|
if (isResponseStream) {
|
|
45
45
|
let isCancelled = false;
|
|
46
|
-
const responseStreamWithCancel = (0, utils_1.withCancel)(call,
|
|
46
|
+
const responseStreamWithCancel = (0, utils_1.withCancel)(call, reason => {
|
|
47
47
|
if (!isCancelled) {
|
|
48
|
-
call.call?.cancelWithStatus(0,
|
|
48
|
+
call.call?.cancelWithStatus(0, reason?.toString() || 'aborted');
|
|
49
49
|
isCancelled = true;
|
|
50
50
|
}
|
|
51
51
|
});
|
package/esm/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { fromJSON } from '@grpc/proto-loader';
|
|
|
10
10
|
import { DisposableStack } from '@whatwg-node/disposablestack';
|
|
11
11
|
import { addExecutionLogicToScalar, addMetaDataToCall } from './utils.js';
|
|
12
12
|
import './patchLongJs.js';
|
|
13
|
+
import { makeDisposable } from '@graphql-mesh/utils';
|
|
13
14
|
export class GrpcTransportHelper extends DisposableStack {
|
|
14
15
|
constructor(subgraphName, baseDir, logger, endpoint, config) {
|
|
15
16
|
super();
|
|
@@ -104,6 +105,11 @@ export class GrpcTransportHelper extends DisposableStack {
|
|
|
104
105
|
const transportDirective = getDirective(schema, schema, 'transport');
|
|
105
106
|
if (transportDirective) {
|
|
106
107
|
for (const directive of transportDirective) {
|
|
108
|
+
if (directive?.subgraph != null &&
|
|
109
|
+
this.subgraphName != null &&
|
|
110
|
+
directive.subgraph !== this.subgraphName) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
107
113
|
if (directive?.options?.roots) {
|
|
108
114
|
roots = directive.options.roots;
|
|
109
115
|
break;
|
|
@@ -127,6 +133,11 @@ export class GrpcTransportHelper extends DisposableStack {
|
|
|
127
133
|
const directives = getDirectives(schema, field);
|
|
128
134
|
if (directives?.length) {
|
|
129
135
|
for (const directiveObj of directives) {
|
|
136
|
+
if (this.subgraphName &&
|
|
137
|
+
directiveObj.args?.subgraph &&
|
|
138
|
+
directiveObj.args.subgraph !== this.subgraphName) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
130
141
|
switch (directiveObj.name) {
|
|
131
142
|
case 'grpcMethod': {
|
|
132
143
|
const { rootJsonName, objPath, methodName, responseStream } = directiveObj.args;
|
|
@@ -145,9 +156,7 @@ export class GrpcTransportHelper extends DisposableStack {
|
|
|
145
156
|
methodName,
|
|
146
157
|
isResponseStream: responseStream,
|
|
147
158
|
});
|
|
148
|
-
field.resolve =
|
|
149
|
-
return root;
|
|
150
|
-
};
|
|
159
|
+
field.resolve = identityFn;
|
|
151
160
|
}
|
|
152
161
|
else {
|
|
153
162
|
field.resolve = this.getFieldResolver({
|
|
@@ -209,7 +218,10 @@ export default {
|
|
|
209
218
|
const transport = new GrpcTransportHelper(transportEntry.subgraph, cwd, logger, transportEntry.location, transportEntry.options);
|
|
210
219
|
return mapMaybePromise(transport.getCredentials(), creds => {
|
|
211
220
|
transport.processDirectives({ schema: subgraph, creds });
|
|
212
|
-
return createDefaultExecutor(subgraph);
|
|
221
|
+
return makeDisposable(createDefaultExecutor(subgraph), () => transport.dispose());
|
|
213
222
|
});
|
|
214
223
|
},
|
|
215
224
|
};
|
|
225
|
+
function identityFn(obj) {
|
|
226
|
+
return obj;
|
|
227
|
+
}
|
package/esm/utils.js
CHANGED
|
@@ -38,9 +38,9 @@ export function addMetaDataToCall(callFn, input, resolverData, metaData, isRespo
|
|
|
38
38
|
});
|
|
39
39
|
if (isResponseStream) {
|
|
40
40
|
let isCancelled = false;
|
|
41
|
-
const responseStreamWithCancel = withCancel(call,
|
|
41
|
+
const responseStreamWithCancel = withCancel(call, reason => {
|
|
42
42
|
if (!isCancelled) {
|
|
43
|
-
call.call?.cancelWithStatus(0,
|
|
43
|
+
call.call?.cancelWithStatus(0, reason?.toString() || 'aborted');
|
|
44
44
|
isCancelled = true;
|
|
45
45
|
}
|
|
46
46
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/transport-grpc",
|
|
3
|
-
"version": "0.2.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "*"
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"@graphql-mesh/cross-helpers": "^0.4.9",
|
|
10
10
|
"@graphql-mesh/string-interpolation": "^0.5.7",
|
|
11
11
|
"@graphql-mesh/transport-common": "^0.7.13",
|
|
12
|
-
"@graphql-mesh/types": "0.103.11
|
|
13
|
-
"@graphql-mesh/utils": "0.103.11
|
|
12
|
+
"@graphql-mesh/types": "^0.103.11",
|
|
13
|
+
"@graphql-mesh/utils": "^0.103.11",
|
|
14
14
|
"@graphql-tools/utils": "^10.6.0",
|
|
15
15
|
"@grpc/grpc-js": "^1.1.7",
|
|
16
16
|
"@grpc/proto-loader": "^0.7.8",
|
package/typings/index.d.cts
CHANGED
|
@@ -69,6 +69,6 @@ export declare class GrpcTransportHelper extends DisposableStack {
|
|
|
69
69
|
}): void;
|
|
70
70
|
}
|
|
71
71
|
declare const _default: {
|
|
72
|
-
getSubgraphExecutor({ transportEntry, subgraph, cwd, logger }: import("@graphql-mesh/transport-common").TransportGetSubgraphExecutorOptions<gRPCTransportOptions>): MaybePromise<import("@graphql-mesh/transport-common").Executor>;
|
|
72
|
+
getSubgraphExecutor({ transportEntry, subgraph, cwd, logger }: import("@graphql-mesh/transport-common").TransportGetSubgraphExecutorOptions<gRPCTransportOptions>): MaybePromise<import("@graphql-mesh/transport-common").Executor & Disposable>;
|
|
73
73
|
};
|
|
74
74
|
export default _default;
|
package/typings/index.d.ts
CHANGED
|
@@ -69,6 +69,6 @@ export declare class GrpcTransportHelper extends DisposableStack {
|
|
|
69
69
|
}): void;
|
|
70
70
|
}
|
|
71
71
|
declare const _default: {
|
|
72
|
-
getSubgraphExecutor({ transportEntry, subgraph, cwd, logger }: import("@graphql-mesh/transport-common").TransportGetSubgraphExecutorOptions<gRPCTransportOptions>): MaybePromise<import("@graphql-mesh/transport-common").Executor>;
|
|
72
|
+
getSubgraphExecutor({ transportEntry, subgraph, cwd, logger }: import("@graphql-mesh/transport-common").TransportGetSubgraphExecutorOptions<gRPCTransportOptions>): MaybePromise<import("@graphql-mesh/transport-common").Executor & Disposable>;
|
|
73
73
|
};
|
|
74
74
|
export default _default;
|