@graphql-mesh/transport-grpc 0.1.11-alpha-20241227151343-f87147c32524c6f789912da45f79a36bcedc5836 → 0.2.0-alpha-20241229114753-3ab870e106a4b2cacdd1a7487ce3eb12026bbf11

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 CHANGED
@@ -15,8 +15,9 @@ const disposablestack_1 = require("@whatwg-node/disposablestack");
15
15
  const utils_js_1 = require("./utils.js");
16
16
  require("./patchLongJs.js");
17
17
  class GrpcTransportHelper extends disposablestack_1.DisposableStack {
18
- constructor(baseDir, logger, endpoint, config) {
18
+ constructor(subgraphName, baseDir, logger, endpoint, config) {
19
19
  super();
20
+ this.subgraphName = subgraphName;
20
21
  this.baseDir = baseDir;
21
22
  this.logger = logger;
22
23
  this.endpoint = endpoint;
@@ -103,13 +104,22 @@ class GrpcTransportHelper extends disposablestack_1.DisposableStack {
103
104
  if ('ObjMap' in schemaTypeMap) {
104
105
  (0, utils_js_1.addExecutionLogicToScalar)(schemaTypeMap.ObjMap, transport_common_1.ObjMapScalar);
105
106
  }
106
- const queryType = schema.getQueryType();
107
- const rootJsonAnnotations = (0, utils_1.getDirective)(schema, queryType, 'grpcRootJson');
108
- const rootJsonMap = new Map();
107
+ let roots;
108
+ const transportDirective = (0, utils_1.getDirective)(schema, schema, 'transport');
109
+ if (transportDirective) {
110
+ for (const directive of transportDirective) {
111
+ if (directive?.options?.roots) {
112
+ roots = directive.options.roots;
113
+ break;
114
+ }
115
+ }
116
+ }
117
+ if (!roots?.length) {
118
+ throw new Error(`No roots found for subgraph '${this.subgraphName}'`);
119
+ }
109
120
  const grpcObjectByRootJsonName = new Map();
110
- for (let { name, rootJson, loadOptions } of rootJsonAnnotations) {
121
+ for (let { name, rootJson, loadOptions } of roots) {
111
122
  rootJson = typeof rootJson === 'string' ? JSON.parse(rootJson) : rootJson;
112
- rootJsonMap.set(name, rootJson);
113
123
  const rootLogger = this.logger.child(name);
114
124
  grpcObjectByRootJsonName.set(name, this.getGrpcObject({ rootJson, loadOptions, rootLogger }));
115
125
  }
@@ -125,6 +135,9 @@ class GrpcTransportHelper extends disposablestack_1.DisposableStack {
125
135
  case 'grpcMethod': {
126
136
  const { rootJsonName, objPath, methodName, responseStream } = directiveObj.args;
127
137
  const grpcObject = grpcObjectByRootJsonName.get(rootJsonName);
138
+ if (!grpcObject) {
139
+ throw new Error(`Root JSON '${rootJsonName}' not found for subgraph '${this.subgraphName}'`);
140
+ }
128
141
  const client = this.getServiceClient({
129
142
  grpcObject,
130
143
  objPath,
@@ -152,6 +165,9 @@ class GrpcTransportHelper extends disposablestack_1.DisposableStack {
152
165
  case 'grpcConnectivityState': {
153
166
  const { rootJsonName, objPath } = directiveObj.args;
154
167
  const grpcObject = grpcObjectByRootJsonName.get(rootJsonName);
168
+ if (!grpcObject) {
169
+ throw new Error(`Root JSON '${rootJsonName}' not found for subgraph '${this.subgraphName}'`);
170
+ }
155
171
  const client = this.getServiceClient({
156
172
  grpcObject,
157
173
  objPath,
@@ -195,7 +211,7 @@ class GrpcTransportHelper extends disposablestack_1.DisposableStack {
195
211
  exports.GrpcTransportHelper = GrpcTransportHelper;
196
212
  exports.default = {
197
213
  getSubgraphExecutor({ transportEntry, subgraph, cwd, logger }) {
198
- const transport = new GrpcTransportHelper(cwd, logger, transportEntry.location, transportEntry.options);
214
+ const transport = new GrpcTransportHelper(transportEntry.subgraph, cwd, logger, transportEntry.location, transportEntry.options);
199
215
  return (0, utils_1.mapMaybePromise)(transport.getCredentials(), creds => {
200
216
  transport.processDirectives({ schema: subgraph, creds });
201
217
  return (0, transport_common_1.createDefaultExecutor)(subgraph);
package/esm/index.js CHANGED
@@ -11,8 +11,9 @@ import { DisposableStack } from '@whatwg-node/disposablestack';
11
11
  import { addExecutionLogicToScalar, addMetaDataToCall } from './utils.js';
12
12
  import './patchLongJs.js';
13
13
  export class GrpcTransportHelper extends DisposableStack {
14
- constructor(baseDir, logger, endpoint, config) {
14
+ constructor(subgraphName, baseDir, logger, endpoint, config) {
15
15
  super();
16
+ this.subgraphName = subgraphName;
16
17
  this.baseDir = baseDir;
17
18
  this.logger = logger;
18
19
  this.endpoint = endpoint;
@@ -99,13 +100,22 @@ export class GrpcTransportHelper extends DisposableStack {
99
100
  if ('ObjMap' in schemaTypeMap) {
100
101
  addExecutionLogicToScalar(schemaTypeMap.ObjMap, ObjMapScalar);
101
102
  }
102
- const queryType = schema.getQueryType();
103
- const rootJsonAnnotations = getDirective(schema, queryType, 'grpcRootJson');
104
- const rootJsonMap = new Map();
103
+ let roots;
104
+ const transportDirective = getDirective(schema, schema, 'transport');
105
+ if (transportDirective) {
106
+ for (const directive of transportDirective) {
107
+ if (directive?.options?.roots) {
108
+ roots = directive.options.roots;
109
+ break;
110
+ }
111
+ }
112
+ }
113
+ if (!roots?.length) {
114
+ throw new Error(`No roots found for subgraph '${this.subgraphName}'`);
115
+ }
105
116
  const grpcObjectByRootJsonName = new Map();
106
- for (let { name, rootJson, loadOptions } of rootJsonAnnotations) {
117
+ for (let { name, rootJson, loadOptions } of roots) {
107
118
  rootJson = typeof rootJson === 'string' ? JSON.parse(rootJson) : rootJson;
108
- rootJsonMap.set(name, rootJson);
109
119
  const rootLogger = this.logger.child(name);
110
120
  grpcObjectByRootJsonName.set(name, this.getGrpcObject({ rootJson, loadOptions, rootLogger }));
111
121
  }
@@ -121,6 +131,9 @@ export class GrpcTransportHelper extends DisposableStack {
121
131
  case 'grpcMethod': {
122
132
  const { rootJsonName, objPath, methodName, responseStream } = directiveObj.args;
123
133
  const grpcObject = grpcObjectByRootJsonName.get(rootJsonName);
134
+ if (!grpcObject) {
135
+ throw new Error(`Root JSON '${rootJsonName}' not found for subgraph '${this.subgraphName}'`);
136
+ }
124
137
  const client = this.getServiceClient({
125
138
  grpcObject,
126
139
  objPath,
@@ -148,6 +161,9 @@ export class GrpcTransportHelper extends DisposableStack {
148
161
  case 'grpcConnectivityState': {
149
162
  const { rootJsonName, objPath } = directiveObj.args;
150
163
  const grpcObject = grpcObjectByRootJsonName.get(rootJsonName);
164
+ if (!grpcObject) {
165
+ throw new Error(`Root JSON '${rootJsonName}' not found for subgraph '${this.subgraphName}'`);
166
+ }
151
167
  const client = this.getServiceClient({
152
168
  grpcObject,
153
169
  objPath,
@@ -190,7 +206,7 @@ export class GrpcTransportHelper extends DisposableStack {
190
206
  }
191
207
  export default {
192
208
  getSubgraphExecutor({ transportEntry, subgraph, cwd, logger }) {
193
- const transport = new GrpcTransportHelper(cwd, logger, transportEntry.location, transportEntry.options);
209
+ const transport = new GrpcTransportHelper(transportEntry.subgraph, cwd, logger, transportEntry.location, transportEntry.options);
194
210
  return mapMaybePromise(transport.getCredentials(), creds => {
195
211
  transport.processDirectives({ schema: subgraph, creds });
196
212
  return createDefaultExecutor(subgraph);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-mesh/transport-grpc",
3
- "version": "0.1.11-alpha-20241227151343-f87147c32524c6f789912da45f79a36bcedc5836",
3
+ "version": "0.2.0-alpha-20241229114753-3ab870e106a4b2cacdd1a7487ce3eb12026bbf11",
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-alpha-20241227151343-f87147c32524c6f789912da45f79a36bcedc5836",
13
- "@graphql-mesh/utils": "0.103.11-alpha-20241227151343-f87147c32524c6f789912da45f79a36bcedc5836",
12
+ "@graphql-mesh/types": "^0.103.10",
13
+ "@graphql-mesh/utils": "^0.103.10",
14
14
  "@graphql-tools/utils": "^10.6.0",
15
15
  "@grpc/grpc-js": "^1.1.7",
16
16
  "@grpc/proto-loader": "^0.7.8",
@@ -37,11 +37,12 @@ interface LoadOptions {
37
37
  includeDirs?: string[];
38
38
  }
39
39
  export declare class GrpcTransportHelper extends DisposableStack {
40
+ private subgraphName;
40
41
  private baseDir;
41
42
  private logger;
42
43
  private endpoint;
43
44
  private config;
44
- constructor(baseDir: string, logger: Logger, endpoint: string, config: gRPCTransportOptions);
45
+ constructor(subgraphName: string, baseDir: string, logger: Logger, endpoint: string, config: gRPCTransportOptions);
45
46
  getCredentials(): MaybePromise<ChannelCredentials>;
46
47
  getGrpcObject({ rootJson, loadOptions, rootLogger, }: {
47
48
  rootJson: protobufjs.INamespace;
@@ -37,11 +37,12 @@ interface LoadOptions {
37
37
  includeDirs?: string[];
38
38
  }
39
39
  export declare class GrpcTransportHelper extends DisposableStack {
40
+ private subgraphName;
40
41
  private baseDir;
41
42
  private logger;
42
43
  private endpoint;
43
44
  private config;
44
- constructor(baseDir: string, logger: Logger, endpoint: string, config: gRPCTransportOptions);
45
+ constructor(subgraphName: string, baseDir: string, logger: Logger, endpoint: string, config: gRPCTransportOptions);
45
46
  getCredentials(): MaybePromise<ChannelCredentials>;
46
47
  getGrpcObject({ rootJson, loadOptions, rootLogger, }: {
47
48
  rootJson: protobufjs.INamespace;