@omnigraph/protobuf 0.0.0-stage → 0.3.2

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.
@@ -0,0 +1,456 @@
1
+ import { specifiedDirectives } from 'graphql';
2
+ import { SchemaComposer, } from 'graphql-compose';
3
+ import { GraphQLBigInt, GraphQLByte, GraphQLJSON, GraphQLUnsignedInt, GraphQLVoid, } from 'graphql-scalars';
4
+ import micromatch from 'micromatch';
5
+ import protobufjs from 'protobufjs';
6
+ import descriptor from 'protobufjs/ext/descriptor.js';
7
+ import { Client } from '@ardatan/grpc-reflection-js';
8
+ import { fs, path } from '@graphql-mesh/cross-helpers';
9
+ import { stringInterpolator } from '@graphql-mesh/string-interpolation';
10
+ import { matchFiles } from '@graphql-tools/load-files';
11
+ import { GraphQLStreamDirective } from '@graphql-tools/utils';
12
+ import { credentials, Client as GrpcClient, Metadata, } from '@grpc/grpc-js';
13
+ import { DisposableStack } from '@whatwg-node/disposablestack';
14
+ import { protobufRpcDirective, transportDirective } from './directives.js';
15
+ import { emitRequestBody, emitResponseSelection, } from './emitMapping.js';
16
+ import { addIncludePathResolver, getTypeName, walkToFindTypePath } from './utils.js';
17
+ const { Root } = protobufjs;
18
+ const QUERY_METHOD_PREFIXES = ['get', 'list', 'search'];
19
+ export class GrpcLoaderHelper extends DisposableStack {
20
+ constructor(subgraphName, baseDir, log, config) {
21
+ super();
22
+ this.subgraphName = subgraphName;
23
+ this.baseDir = baseDir;
24
+ this.log = log;
25
+ this.config = config;
26
+ this.schemaComposer = new SchemaComposer();
27
+ }
28
+ async buildSchema() {
29
+ this.schemaComposer.add(GraphQLBigInt);
30
+ this.schemaComposer.add(GraphQLByte);
31
+ this.schemaComposer.add(GraphQLUnsignedInt);
32
+ this.schemaComposer.add(GraphQLVoid);
33
+ this.schemaComposer.add(GraphQLJSON);
34
+ this.schemaComposer.createScalarTC({
35
+ name: 'File',
36
+ });
37
+ this.config.requestTimeout = this.config.requestTimeout || 200000;
38
+ this.log.debug(`Getting channel credentials`);
39
+ const creds = await this.getCredentials();
40
+ if ('_unref' in creds && typeof creds._unref === 'function') {
41
+ this.defer(() => creds._unref());
42
+ }
43
+ this.log.debug(`Getting stored root and decoded descriptor set objects`);
44
+ const descriptorSets = await this.getDescriptorSets(creds);
45
+ for (const { name: rootJsonName, rootJson } of descriptorSets) {
46
+ const rootLogger = this.log.child({ root: rootJsonName });
47
+ this.log.debug(`Building the schema structure based on the root object`);
48
+ this.visit({
49
+ nested: rootJson,
50
+ name: '',
51
+ currentPath: [],
52
+ rootJsonName,
53
+ rootJson,
54
+ rootLogger,
55
+ });
56
+ }
57
+ // graphql-compose doesn't add @defer and @stream to the schema
58
+ specifiedDirectives.forEach(directive => this.schemaComposer.addDirective(directive));
59
+ if (!this.schemaComposer.hasDirective('stream')) {
60
+ this.schemaComposer.addDirective(GraphQLStreamDirective);
61
+ }
62
+ this.log.debug(`Building the final GraphQL Schema`);
63
+ this.schemaComposer.addDirective(transportDirective);
64
+ const schema = this.schemaComposer.buildSchema();
65
+ const schemaExtensions = (schema.extensions = schema.extensions || {});
66
+ const directiveExtensions = (schemaExtensions.directives = schemaExtensions.directives || {});
67
+ directiveExtensions.transport = {
68
+ subgraph: this.subgraphName,
69
+ kind: 'protobuf',
70
+ location: this.config.endpoint,
71
+ options: {
72
+ requestTimeout: this.config.requestTimeout,
73
+ credentialsSsl: this.config.credentialsSsl,
74
+ useHTTPS: this.config.useHTTPS,
75
+ metaData: this.config.metaData ? Object.entries(this.config.metaData) : undefined,
76
+ // Serialize as entries so keys like `grpc.max_receive_message_length` are GraphQL-safe
77
+ channelOptions: this.config.channelOptions
78
+ ? Object.entries(this.config.channelOptions)
79
+ : undefined,
80
+ },
81
+ };
82
+ return schema;
83
+ }
84
+ processReflection(creds) {
85
+ this.log.debug(`Using the reflection`);
86
+ const reflectionEndpoint = stringInterpolator.parse(this.config.endpoint, {
87
+ env: globalThis.process?.env,
88
+ });
89
+ this.log.debug(`Creating gRPC Reflection Client`);
90
+ const reflectionClient = new Client(reflectionEndpoint, creds, this.config.channelOptions);
91
+ // Attach reflectionMetadata to server-reflection calls (routing / auth metadata)
92
+ if (this.config.reflectionMetadata) {
93
+ const meta = new Metadata();
94
+ const resolverData = { env: globalThis.process?.env };
95
+ for (const [key, value] of Object.entries(this.config.reflectionMetadata)) {
96
+ const interpolated = typeof value === 'string' ? stringInterpolator.parse(value, resolverData) : value;
97
+ meta.set(key, String(interpolated));
98
+ }
99
+ const grpcClient = reflectionClient.grpcClient;
100
+ const originalServerReflectionInfo = grpcClient.serverReflectionInfo.bind(grpcClient);
101
+ grpcClient.serverReflectionInfo = (...args) => {
102
+ args[0] = meta;
103
+ return originalServerReflectionInfo(...args);
104
+ };
105
+ }
106
+ // Avoid Close RPC name collisions if present on generated clients
107
+ this.defer(() => GrpcClient.prototype.close.call(reflectionClient.grpcClient));
108
+ return reflectionClient.listServices().then(services => services.filter(service => service && !service?.startsWith('grpc.')).map(service => {
109
+ this.log.debug(`Resolving root of Service: ${service} from the reflection response`);
110
+ return reflectionClient.fileContainingSymbol(service);
111
+ }));
112
+ }
113
+ async processDescriptorFile() {
114
+ let fileName;
115
+ let options;
116
+ if (typeof this.config.source === 'object') {
117
+ fileName = this.config.source.file;
118
+ options = {
119
+ ...this.config.source.load,
120
+ includeDirs: this.config.source.load.includeDirs?.map(includeDir => path.isAbsolute(includeDir) ? includeDir : path.join(this.baseDir, includeDir)),
121
+ };
122
+ }
123
+ else {
124
+ fileName = this.config.source;
125
+ }
126
+ fileName = stringInterpolator.parse(fileName, { env: globalThis.process?.env });
127
+ const absoluteFilePath = path.isAbsolute(fileName)
128
+ ? fileName
129
+ : path.join(this.baseDir, fileName);
130
+ this.log.debug(`Using the descriptor set from ${absoluteFilePath} `);
131
+ const descriptorSetBuffer = await fs.promises.readFile(absoluteFilePath);
132
+ this.log.debug(`Reading ${absoluteFilePath} `);
133
+ let decodedDescriptorSet;
134
+ if (absoluteFilePath.endsWith('json')) {
135
+ this.log.debug(`Parsing ${absoluteFilePath} as json`);
136
+ const descriptorSetJSON = JSON.parse(descriptorSetBuffer.toString());
137
+ decodedDescriptorSet = descriptor.FileDescriptorSet.fromObject(descriptorSetJSON);
138
+ }
139
+ else {
140
+ decodedDescriptorSet = descriptor.FileDescriptorSet.decode(descriptorSetBuffer);
141
+ }
142
+ this.log.debug(`Creating root from descriptor set`);
143
+ const rootFromDescriptor = Root.fromDescriptor(decodedDescriptorSet);
144
+ if (options.includeDirs) {
145
+ if (!Array.isArray(options.includeDirs)) {
146
+ throw new Error('The includeDirs option must be an array');
147
+ }
148
+ addIncludePathResolver(rootFromDescriptor, options.includeDirs);
149
+ }
150
+ return rootFromDescriptor;
151
+ }
152
+ async processProtoFile() {
153
+ this.log.debug(`Using proto file(s)`);
154
+ let protoRoot = new Root();
155
+ let fileGlob;
156
+ let options = {
157
+ keepCase: true,
158
+ alternateCommentMode: true,
159
+ };
160
+ if (typeof this.config.source === 'object') {
161
+ fileGlob = this.config.source.file;
162
+ options = {
163
+ ...options,
164
+ ...this.config.source.load,
165
+ includeDirs: this.config.source.load?.includeDirs?.map(includeDir => path.isAbsolute(includeDir) ? includeDir : path.join(this.baseDir, includeDir)),
166
+ };
167
+ if (options.includeDirs) {
168
+ if (!Array.isArray(options.includeDirs)) {
169
+ throw new Error('The includeDirs option must be an array');
170
+ }
171
+ addIncludePathResolver(protoRoot, options.includeDirs);
172
+ }
173
+ }
174
+ else {
175
+ fileGlob = this.config.source;
176
+ }
177
+ fileGlob = stringInterpolator.parse(fileGlob, { env: globalThis.process?.env });
178
+ const fileNames = await matchFiles(fileGlob, {
179
+ cwd: this.baseDir,
180
+ absolute: false,
181
+ });
182
+ this.log.debug(`Loading proto files(${fileGlob}); \n ${fileNames.join('\n')} `);
183
+ protoRoot = await protoRoot.load(fileNames.map(filePath => path.isAbsolute(filePath) ? filePath : path.join(this.baseDir, filePath)), options);
184
+ this.log.debug(`Adding proto content to the root`);
185
+ return protoRoot;
186
+ }
187
+ async getDescriptorSets(creds) {
188
+ const rootPromises = [];
189
+ this.log.debug(`Building Roots`);
190
+ const filePath = this.config.source
191
+ ? typeof this.config.source === 'string'
192
+ ? this.config.source
193
+ : this.config.source.file
194
+ : undefined;
195
+ // Missing or empty source means gRPC reflection (also accepts source: { file: '' } workaround)
196
+ if (filePath?.endsWith('json')) {
197
+ rootPromises.push(this.processDescriptorFile());
198
+ }
199
+ else if (filePath?.endsWith('proto')) {
200
+ rootPromises.push(this.processProtoFile());
201
+ }
202
+ else {
203
+ const reflectionPromises = await this.processReflection(creds);
204
+ rootPromises.push(...reflectionPromises);
205
+ }
206
+ return Promise.all(rootPromises.map(async (root$, i) => {
207
+ const root = await root$;
208
+ const rootName = root.name || `Root${i}`;
209
+ const rootLogger = this.log.child({ root: rootName });
210
+ rootLogger.debug(`Resolving entire the root tree`);
211
+ root.resolveAll();
212
+ rootLogger.debug(`Creating artifacts from descriptor set and root`);
213
+ return {
214
+ name: rootName,
215
+ rootJson: root.toJSON({
216
+ keepComments: true,
217
+ }),
218
+ };
219
+ }));
220
+ }
221
+ getCredentials() {
222
+ this.log.debug(`Getting channel credentials`);
223
+ if (this.config.credentialsSsl) {
224
+ this.log.debug(() => `Using SSL Connection with credentials at ${this.config.credentialsSsl.privateKey} & ${this.config.credentialsSsl.certChain}`);
225
+ const absolutePrivateKeyPath = path.isAbsolute(this.config.credentialsSsl.privateKey)
226
+ ? this.config.credentialsSsl.privateKey
227
+ : path.join(this.baseDir, this.config.credentialsSsl.privateKey);
228
+ const absoluteCertChainPath = path.isAbsolute(this.config.credentialsSsl.certChain)
229
+ ? this.config.credentialsSsl.certChain
230
+ : path.join(this.baseDir, this.config.credentialsSsl.certChain);
231
+ const sslFiles = [
232
+ fs.promises.readFile(absolutePrivateKeyPath),
233
+ fs.promises.readFile(absoluteCertChainPath),
234
+ ];
235
+ if (this.config.credentialsSsl.rootCA !== 'rootCA') {
236
+ const absoluteRootCAPath = path.isAbsolute(this.config.credentialsSsl.rootCA)
237
+ ? this.config.credentialsSsl.rootCA
238
+ : path.join(this.baseDir, this.config.credentialsSsl.rootCA);
239
+ sslFiles.unshift(fs.promises.readFile(absoluteRootCAPath));
240
+ }
241
+ return Promise.all(sslFiles).then(([rootCA, privateKey, certChain]) => credentials.createSsl(rootCA, privateKey, certChain));
242
+ }
243
+ else if (this.config.useHTTPS) {
244
+ this.log.debug(`Using SSL Connection`);
245
+ return credentials.createSsl();
246
+ }
247
+ this.log.debug(`Using insecure connection`);
248
+ return credentials.createInsecure();
249
+ }
250
+ visit({ nested, name, currentPath, rootJsonName, rootJson, rootLogger: log, }) {
251
+ const pathWithName = [...currentPath, ...name.split('.')].filter(Boolean);
252
+ if ('nested' in nested) {
253
+ for (const key in nested.nested) {
254
+ log.debug(`Visiting ${currentPath}.nested[${key}]`);
255
+ const currentNested = nested.nested[key];
256
+ this.visit({
257
+ nested: currentNested,
258
+ name: key,
259
+ currentPath: pathWithName,
260
+ rootJsonName,
261
+ rootJson,
262
+ rootLogger: log,
263
+ });
264
+ }
265
+ }
266
+ const typeName = pathWithName.join('__');
267
+ if ('values' in nested) {
268
+ const enumValues = {};
269
+ const commentMap = nested.comments;
270
+ for (const [key] of Object.entries(nested.values)) {
271
+ log.debug(`Visiting ${currentPath}.nested.values[${key}]`);
272
+ enumValues[key] = {
273
+ description: commentMap?.[key],
274
+ };
275
+ }
276
+ this.schemaComposer.createEnumTC({
277
+ name: typeName,
278
+ values: enumValues,
279
+ description: nested.comment,
280
+ });
281
+ }
282
+ else if ('fields' in nested) {
283
+ const inputTypeName = typeName + '_Input';
284
+ const outputTypeName = typeName;
285
+ const description = nested.comment;
286
+ const fieldEntries = Object.entries(nested.fields);
287
+ if (fieldEntries.length) {
288
+ const inputTC = this.schemaComposer.createInputTC({
289
+ name: inputTypeName,
290
+ description,
291
+ fields: {},
292
+ });
293
+ const outputTC = this.schemaComposer.createObjectTC({
294
+ name: outputTypeName,
295
+ description,
296
+ fields: {},
297
+ });
298
+ for (const [fieldName, { type, rule, comment, keyType }] of fieldEntries) {
299
+ log.debug(`Visiting ${currentPath}.nested.fields[${fieldName}]`);
300
+ const baseFieldTypePath = type.split('.');
301
+ inputTC.addFields({
302
+ [fieldName]: {
303
+ type: () => {
304
+ let fieldInputTypeName;
305
+ if (keyType) {
306
+ fieldInputTypeName = 'JSON';
307
+ }
308
+ else {
309
+ const fieldTypePath = walkToFindTypePath(rootJson, pathWithName, baseFieldTypePath);
310
+ fieldInputTypeName = getTypeName(this.schemaComposer, fieldTypePath, true);
311
+ }
312
+ return rule === 'repeated' ? `[${fieldInputTypeName}]` : fieldInputTypeName;
313
+ },
314
+ description: comment,
315
+ },
316
+ });
317
+ outputTC.addFields({
318
+ [fieldName]: {
319
+ type: () => {
320
+ let fieldTypeName;
321
+ if (keyType) {
322
+ fieldTypeName = 'JSON';
323
+ }
324
+ else {
325
+ const fieldTypePath = walkToFindTypePath(rootJson, pathWithName, baseFieldTypePath);
326
+ fieldTypeName = getTypeName(this.schemaComposer, fieldTypePath, false);
327
+ }
328
+ return rule === 'repeated' ? `[${fieldTypeName}]` : fieldTypeName;
329
+ },
330
+ description: comment,
331
+ },
332
+ });
333
+ }
334
+ }
335
+ else {
336
+ this.schemaComposer.createScalarTC({
337
+ ...GraphQLJSON.toConfig(),
338
+ name: inputTypeName,
339
+ description,
340
+ });
341
+ this.schemaComposer.createScalarTC({
342
+ ...GraphQLJSON.toConfig(),
343
+ name: outputTypeName,
344
+ description,
345
+ });
346
+ }
347
+ }
348
+ else if ('methods' in nested) {
349
+ const objPath = pathWithName.join('.');
350
+ for (const methodName in nested.methods) {
351
+ const method = nested.methods[methodName];
352
+ const rootFieldName = [...pathWithName, methodName].join('_');
353
+ const fieldConfigTypeFactory = () => {
354
+ const baseResponseTypePath = method.responseType?.split('.');
355
+ if (baseResponseTypePath) {
356
+ const responseTypePath = walkToFindTypePath(rootJson, pathWithName, baseResponseTypePath);
357
+ return getTypeName(this.schemaComposer, responseTypePath, false);
358
+ }
359
+ return 'Void';
360
+ };
361
+ const fieldConfig = {
362
+ type: () => {
363
+ const typeName = fieldConfigTypeFactory();
364
+ if (method.responseStream) {
365
+ return `[${typeName}]`;
366
+ }
367
+ return typeName;
368
+ },
369
+ description: method.comment,
370
+ };
371
+ const fieldConfigArgs = {
372
+ input: () => {
373
+ if (method.requestStream) {
374
+ return 'File';
375
+ }
376
+ const baseRequestTypePath = method.requestType?.split('.');
377
+ if (baseRequestTypePath) {
378
+ const requestTypePath = walkToFindTypePath(rootJson, pathWithName, baseRequestTypePath);
379
+ const requestTypeName = getTypeName(this.schemaComposer, requestTypePath, true);
380
+ return requestTypeName;
381
+ }
382
+ return undefined;
383
+ },
384
+ };
385
+ fieldConfig.args = fieldConfigArgs;
386
+ const methodNameLowerCased = methodName.toLowerCase();
387
+ const prefixQueryMethod = this.config.prefixQueryMethod || QUERY_METHOD_PREFIXES;
388
+ let rootTypeComposer;
389
+ if (this.config.selectQueryOrMutationField) {
390
+ const selection = this.config.selectQueryOrMutationField.find(selection => micromatch([rootFieldName], selection.fieldName).length > 0);
391
+ const rootTypeName = selection?.type?.toLowerCase();
392
+ if (rootTypeName) {
393
+ if (rootTypeName === 'query') {
394
+ rootTypeComposer = this.schemaComposer.Query;
395
+ }
396
+ else if (rootTypeName === 'mutation') {
397
+ rootTypeComposer = this.schemaComposer.Mutation;
398
+ }
399
+ else if (rootTypeName === 'subscription') {
400
+ rootTypeComposer = this.schemaComposer.Subscription;
401
+ }
402
+ else {
403
+ throw new Error(`Unknown type provided ${selection.type} for ${rootFieldName}; available options are Query, Mutation and Subscription`);
404
+ }
405
+ }
406
+ }
407
+ if (rootTypeComposer == null) {
408
+ rootTypeComposer = prefixQueryMethod.some(prefix => methodNameLowerCased.startsWith(prefix))
409
+ ? this.schemaComposer.Query
410
+ : this.schemaComposer.Mutation;
411
+ }
412
+ const serviceName = pathWithName.join('.') || objPath;
413
+ const argsMapping = method.requestType
414
+ ? emitRequestBody(rootJson, pathWithName, method.requestType)
415
+ : '';
416
+ const selection = method.responseType
417
+ ? emitResponseSelection(rootJson, pathWithName, method.responseType)
418
+ : '';
419
+ const rpcDirective = {
420
+ name: 'protobuf__rpc',
421
+ args: {
422
+ subgraph: this.subgraphName,
423
+ service: serviceName,
424
+ method: methodName,
425
+ args: argsMapping,
426
+ selection,
427
+ stream: !!method.responseStream,
428
+ },
429
+ };
430
+ this.schemaComposer.addDirective(protobufRpcDirective);
431
+ rootTypeComposer.addFields({
432
+ [rootFieldName]: {
433
+ ...fieldConfig,
434
+ directives: [rpcDirective],
435
+ },
436
+ });
437
+ if (method.responseStream) {
438
+ this.schemaComposer.Subscription.addFields({
439
+ [rootFieldName]: {
440
+ args: fieldConfigArgs,
441
+ description: method.comment,
442
+ type: fieldConfigTypeFactory,
443
+ directives: [
444
+ {
445
+ ...rpcDirective,
446
+ args: { ...rpcDirective.args, stream: true },
447
+ },
448
+ ],
449
+ },
450
+ });
451
+ }
452
+ }
453
+ // connectivity state removed from protobuf author surface
454
+ }
455
+ }
456
+ }
@@ -0,0 +1,17 @@
1
+ import { GrpcLoaderHelper } from './grpcLoaderHelper.js';
2
+ /**
3
+ * Load a protobuf-RPC subgraph from `.proto` / reflection.
4
+ */
5
+ export function loadProtobufSubgraph(name, options) {
6
+ return (ctx) => {
7
+ const helper = new GrpcLoaderHelper(name, ctx.cwd, ctx.log, {
8
+ ...options,
9
+ // type reserved for future connect/twirp emit path conventions
10
+ });
11
+ const schema$ = helper.buildSchema().finally(() => helper.dispose());
12
+ return {
13
+ name,
14
+ schema$,
15
+ };
16
+ };
17
+ }
@@ -0,0 +1,27 @@
1
+ const SCALARS = new Map([
2
+ ['bool', 'Boolean'],
3
+ ['bytes', 'Byte'],
4
+ ['double', 'Float'],
5
+ ['fixed32', 'Int'],
6
+ ['fixed64', 'BigInt'],
7
+ ['float', 'Float'],
8
+ ['int32', 'Int'],
9
+ ['int64', 'BigInt'],
10
+ ['sfixed32', 'Int'],
11
+ ['sfixed64', 'BigInt'],
12
+ ['sint32', 'Int'],
13
+ ['sint64', 'BigInt'],
14
+ ['string', 'String'],
15
+ ['uint32', 'UnsignedInt'],
16
+ ['uint64', 'BigInt'], // A new scalar might be needed
17
+ ]);
18
+ export function isGrpcScalar(type) {
19
+ return SCALARS.has(type);
20
+ }
21
+ export function getGraphQLScalarForGrpc(scalarType) {
22
+ const gqlScalar = SCALARS.get(scalarType);
23
+ if (!gqlScalar) {
24
+ throw new Error(`Could not find GraphQL Scalar for type ${scalarType}`);
25
+ }
26
+ return SCALARS.get(scalarType);
27
+ }
@@ -0,0 +1,48 @@
1
+ import lodashHas from 'lodash.has';
2
+ import { fs, path as pathModule } from '@graphql-mesh/cross-helpers';
3
+ import { getGraphQLScalarForGrpc, isGrpcScalar } from './scalars.js';
4
+ export function addIncludePathResolver(root, includePaths) {
5
+ const originalResolvePath = root.resolvePath;
6
+ root.resolvePath = (origin, target) => {
7
+ if (pathModule.isAbsolute(target)) {
8
+ return target;
9
+ }
10
+ for (const directory of includePaths) {
11
+ const fullPath = pathModule.join(directory, target);
12
+ if (fs.existsSync(fullPath)) {
13
+ return fullPath;
14
+ }
15
+ }
16
+ const path = originalResolvePath(origin, target);
17
+ if (path === null) {
18
+ console.warn(`${target} not found in any of the include paths ${includePaths}`);
19
+ }
20
+ return path;
21
+ };
22
+ }
23
+ export function getTypeName(schemaComposer, pathWithName, isInput) {
24
+ if (pathWithName?.length) {
25
+ const baseTypeName = pathWithName.filter(Boolean).join('__');
26
+ if (isGrpcScalar(baseTypeName)) {
27
+ return getGraphQLScalarForGrpc(baseTypeName);
28
+ }
29
+ if (schemaComposer.isEnumType(baseTypeName)) {
30
+ return baseTypeName;
31
+ }
32
+ return isInput ? baseTypeName + '_Input' : baseTypeName;
33
+ }
34
+ return 'Void';
35
+ }
36
+ export function walkToFindTypePath(rootJson, pathWithName, baseTypePath) {
37
+ // Reflection / Fully-qualified names often look like `.echo.GreetingRequest`
38
+ // (`split('.')` → `['', 'echo', …]`). Empty segments break `nested['']` walks.
39
+ const normalizedBase = baseTypePath.filter(Boolean);
40
+ const currentWalkingPath = pathWithName.filter(Boolean);
41
+ while (!lodashHas(rootJson.nested, currentWalkingPath.concat(normalizedBase).join('.nested.'))) {
42
+ if (!currentWalkingPath.length) {
43
+ break;
44
+ }
45
+ currentWalkingPath.pop();
46
+ }
47
+ return currentWalkingPath.concat(normalizedBase);
48
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@omnigraph/protobuf",
3
+ "version": "0.3.2",
4
+ "sideEffects": false,
5
+ "peerDependencies": {
6
+ "graphql": "^16.0.0 || ^17.0.0"
7
+ },
8
+ "dependencies": {
9
+ "@ardatan/grpc-reflection-js": "^0.0.2",
10
+ "@graphql-hive/logger": "^1.1.1",
11
+ "@graphql-mesh/cross-helpers": "^0.4.18",
12
+ "@graphql-mesh/string-interpolation": "^0.5.18",
13
+ "@graphql-mesh/transport-common": "^1.1.2",
14
+ "@graphql-mesh/utils": "^0.107.3",
15
+ "@graphql-tools/load-files": "^8.0.9",
16
+ "@graphql-tools/utils": "^13.2.2",
17
+ "@grpc/grpc-js": "^1.14.5",
18
+ "@whatwg-node/disposablestack": "^0.1.0",
19
+ "graphql-compose": "^9.3.0",
20
+ "graphql-scalars": "^2.0.1",
21
+ "lodash.has": "^4.5.2",
22
+ "micromatch": "^4.0.8",
23
+ "protobufjs": "^8.8.1"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "ardatan/graphql-mesh",
28
+ "directory": "packages/loaders/protobuf"
29
+ },
30
+ "license": "MIT",
31
+ "engines": {
32
+ "node": ">=22.18.0"
33
+ },
34
+ "main": "cjs/index.js",
35
+ "module": "esm/index.js",
36
+ "typings": "typings/index.d.ts",
37
+ "typescript": {
38
+ "definition": "typings/index.d.ts"
39
+ },
40
+ "type": "module",
41
+ "exports": {
42
+ ".": {
43
+ "require": {
44
+ "types": "./typings/index.d.cts",
45
+ "default": "./cjs/index.js"
46
+ },
47
+ "import": {
48
+ "types": "./typings/index.d.ts",
49
+ "default": "./esm/index.js"
50
+ },
51
+ "default": {
52
+ "types": "./typings/index.d.ts",
53
+ "default": "./esm/index.js"
54
+ }
55
+ },
56
+ "./package.json": "./package.json"
57
+ }
58
+ }
@@ -0,0 +1,3 @@
1
+ import { GraphQLDirective } from 'graphql';
2
+ export declare const protobufRpcDirective: GraphQLDirective;
3
+ export { TransportDirective as transportDirective } from '@graphql-mesh/utils';
@@ -0,0 +1,3 @@
1
+ import { GraphQLDirective } from 'graphql';
2
+ export declare const protobufRpcDirective: GraphQLDirective;
3
+ export { TransportDirective as transportDirective } from '@graphql-mesh/utils';
@@ -0,0 +1,15 @@
1
+ import type { INamespace } from 'protobufjs';
2
+ /**
3
+ * Emit typed protobuf mapping strings from protobufjs JSON namespace (loader-time only).
4
+ * Output is indented and may include `#` comments for humans/AI; the transport parser skips them.
5
+ */
6
+ export declare function emitEnumValues(rootJson: INamespace, pathWithName: string[], typeName: string): string;
7
+ export declare function protoTypeToken(rootJson: INamespace, pathWithName: string[], field: {
8
+ type?: string;
9
+ rule?: string;
10
+ keyType?: string;
11
+ }): string;
12
+ export declare function emitFieldsMapping(rootJson: INamespace, pathWithName: string[], typeName: string, bindMode: 'relative' | 'prefix', bindPrefix?: string, indent?: string): string;
13
+ /** Request: GraphQL args use `input` wrapping the request message fields. */
14
+ export declare function emitRequestBody(rootJson: INamespace, pathWithName: string[], requestType: string): string;
15
+ export declare function emitResponseSelection(rootJson: INamespace, pathWithName: string[], responseType: string): string;
@@ -0,0 +1,15 @@
1
+ import type { INamespace } from 'protobufjs';
2
+ /**
3
+ * Emit typed protobuf mapping strings from protobufjs JSON namespace (loader-time only).
4
+ * Output is indented and may include `#` comments for humans/AI; the transport parser skips them.
5
+ */
6
+ export declare function emitEnumValues(rootJson: INamespace, pathWithName: string[], typeName: string): string;
7
+ export declare function protoTypeToken(rootJson: INamespace, pathWithName: string[], field: {
8
+ type?: string;
9
+ rule?: string;
10
+ keyType?: string;
11
+ }): string;
12
+ export declare function emitFieldsMapping(rootJson: INamespace, pathWithName: string[], typeName: string, bindMode: 'relative' | 'prefix', bindPrefix?: string, indent?: string): string;
13
+ /** Request: GraphQL args use `input` wrapping the request message fields. */
14
+ export declare function emitRequestBody(rootJson: INamespace, pathWithName: string[], requestType: string): string;
15
+ export declare function emitResponseSelection(rootJson: INamespace, pathWithName: string[], responseType: string): string;