@omnigraph/grpc 0.0.1-alpha-20241030124810-c0e8113edb4c8fd5b24bd53fd28ec5b664e9922e → 0.0.1-alpha-20241030131730-1359d5277c2d37355cd8bcfebf07b0160688def4

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.
@@ -1,32 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gRPCLoader = void 0;
3
+ exports.GrpcLoaderHelper = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const globby_1 = tslib_1.__importDefault(require("globby"));
5
6
  const graphql_1 = require("graphql");
6
7
  const graphql_compose_1 = require("graphql-compose");
7
8
  const graphql_scalars_1 = require("graphql-scalars");
8
- const directives_js_1 = require("./directives.js");
9
- const grpc_js_1 = require("@grpc/grpc-js");
10
9
  const protobufjs_1 = tslib_1.__importDefault(require("protobufjs"));
11
- const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
12
- const node_path_1 = require("node:path");
13
- const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
14
- const globby_1 = tslib_1.__importDefault(require("globby"));
15
- const utils_js_1 = require("./utils.js");
16
- const utils_1 = require("@graphql-tools/utils");
17
10
  const index_js_1 = tslib_1.__importDefault(require("protobufjs/ext/descriptor/index.js"));
18
11
  const grpc_reflection_js_1 = require("@ardatan/grpc-reflection-js");
12
+ const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
13
+ const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
14
+ const utils_1 = require("@graphql-tools/utils");
15
+ const grpc_js_1 = require("@grpc/grpc-js");
19
16
  const disposablestack_1 = require("@whatwg-node/disposablestack");
17
+ const directives_js_1 = require("./directives.js");
18
+ const utils_js_1 = require("./utils.js");
20
19
  const { Root } = protobufjs_1.default;
21
20
  const QUERY_METHOD_PREFIXES = ['get', 'list', 'search'];
22
- class gRPCLoader {
21
+ class GrpcLoaderHelper {
23
22
  constructor(subgraphName, baseDir, logger, config) {
24
23
  this.subgraphName = subgraphName;
25
24
  this.baseDir = baseDir;
26
25
  this.logger = logger;
27
26
  this.config = config;
28
27
  this.schemaComposer = new graphql_compose_1.SchemaComposer();
29
- this.asyncDisposableStack = new disposablestack_1.AsyncDisposableStack;
28
+ this.asyncDisposableStack = new disposablestack_1.AsyncDisposableStack();
30
29
  }
31
30
  [Symbol.asyncDispose]() {
32
31
  return this.asyncDisposableStack.disposeAsync();
@@ -87,8 +86,8 @@ class gRPCLoader {
87
86
  this.logger.debug(`Building the final GraphQL Schema`);
88
87
  this.schemaComposer.addDirective(directives_js_1.transportDirective);
89
88
  const schema = this.schemaComposer.buildSchema();
90
- const schemaExtensions = schema.extensions = schema.extensions || {};
91
- const directiveExtensions = schemaExtensions.directives = schemaExtensions.directives || {};
89
+ const schemaExtensions = (schema.extensions = schema.extensions || {});
90
+ const directiveExtensions = (schemaExtensions.directives = schemaExtensions.directives || {});
92
91
  directiveExtensions.transport = {
93
92
  subgraph: this.subgraphName,
94
93
  kind: 'grpc',
@@ -108,11 +107,10 @@ class gRPCLoader {
108
107
  this.logger.debug(`Creating gRPC Reflection Client`);
109
108
  const reflectionClient = new grpc_reflection_js_1.Client(reflectionEndpoint, creds);
110
109
  this.asyncDisposableStack.defer(() => reflectionClient.grpcClient.close());
111
- return reflectionClient.listServices().then(services => (services.filter(service => service && !service?.startsWith('grpc.'))
112
- .map(service => {
110
+ return reflectionClient.listServices().then(services => services.filter(service => service && !service?.startsWith('grpc.')).map(service => {
113
111
  this.logger.debug(`Resolving root of Service: ${service} from the reflection response`);
114
112
  return reflectionClient.fileContainingSymbol(service);
115
- })));
113
+ }));
116
114
  }
117
115
  async processDescriptorFile() {
118
116
  let fileName;
@@ -121,16 +119,16 @@ class gRPCLoader {
121
119
  fileName = this.config.source.file;
122
120
  options = {
123
121
  ...this.config.source.load,
124
- includeDirs: this.config.source.load.includeDirs?.map(includeDir => (0, node_path_1.isAbsolute)(includeDir) ? includeDir : (0, node_path_1.join)(this.baseDir, includeDir)),
122
+ includeDirs: this.config.source.load.includeDirs?.map(includeDir => cross_helpers_1.path.isAbsolute(includeDir) ? includeDir : cross_helpers_1.path.join(this.baseDir, includeDir)),
125
123
  };
126
124
  }
127
125
  else {
128
126
  fileName = this.config.source;
129
127
  }
130
128
  fileName = string_interpolation_1.stringInterpolator.parse(fileName, { env: process.env });
131
- const absoluteFilePath = (0, node_path_1.isAbsolute)(fileName)
129
+ const absoluteFilePath = cross_helpers_1.path.isAbsolute(fileName)
132
130
  ? fileName
133
- : (0, node_path_1.join)(this.baseDir, fileName);
131
+ : cross_helpers_1.path.join(this.baseDir, fileName);
134
132
  this.logger.debug(`Using the descriptor set from ${absoluteFilePath} `);
135
133
  const descriptorSetBuffer = await cross_helpers_1.fs.promises.readFile(absoluteFilePath);
136
134
  this.logger.debug(`Reading ${absoluteFilePath} `);
@@ -166,7 +164,7 @@ class gRPCLoader {
166
164
  options = {
167
165
  ...options,
168
166
  ...this.config.source.load,
169
- includeDirs: this.config.source.load?.includeDirs?.map(includeDir => (0, node_path_1.isAbsolute)(includeDir) ? includeDir : (0, node_path_1.join)(this.baseDir, includeDir)),
167
+ includeDirs: this.config.source.load?.includeDirs?.map(includeDir => cross_helpers_1.path.isAbsolute(includeDir) ? includeDir : cross_helpers_1.path.join(this.baseDir, includeDir)),
170
168
  };
171
169
  if (options.includeDirs) {
172
170
  if (!Array.isArray(options.includeDirs)) {
@@ -183,7 +181,7 @@ class gRPCLoader {
183
181
  cwd: this.baseDir,
184
182
  });
185
183
  this.logger.debug(`Loading proto files(${fileGlob}); \n ${fileNames.join('\n')} `);
186
- protoRoot = await protoRoot.load(fileNames.map(filePath => (0, node_path_1.isAbsolute)(filePath) ? filePath : (0, node_path_1.join)(this.baseDir, filePath)), options);
184
+ protoRoot = await protoRoot.load(fileNames.map(filePath => cross_helpers_1.path.isAbsolute(filePath) ? filePath : cross_helpers_1.path.join(this.baseDir, filePath)), options);
187
185
  this.logger.debug(`Adding proto content to the root`);
188
186
  return protoRoot;
189
187
  }
@@ -222,20 +220,20 @@ class gRPCLoader {
222
220
  this.logger.debug(`Getting channel credentials`);
223
221
  if (this.config.credentialsSsl) {
224
222
  this.logger.debug(() => `Using SSL Connection with credentials at ${this.config.credentialsSsl.privateKey} & ${this.config.credentialsSsl.certChain}`);
225
- const absolutePrivateKeyPath = (0, node_path_1.isAbsolute)(this.config.credentialsSsl.privateKey)
223
+ const absolutePrivateKeyPath = cross_helpers_1.path.isAbsolute(this.config.credentialsSsl.privateKey)
226
224
  ? this.config.credentialsSsl.privateKey
227
- : (0, node_path_1.join)(this.baseDir, this.config.credentialsSsl.privateKey);
228
- const absoluteCertChainPath = (0, node_path_1.isAbsolute)(this.config.credentialsSsl.certChain)
225
+ : cross_helpers_1.path.join(this.baseDir, this.config.credentialsSsl.privateKey);
226
+ const absoluteCertChainPath = cross_helpers_1.path.isAbsolute(this.config.credentialsSsl.certChain)
229
227
  ? this.config.credentialsSsl.certChain
230
- : (0, node_path_1.join)(this.baseDir, this.config.credentialsSsl.certChain);
228
+ : cross_helpers_1.path.join(this.baseDir, this.config.credentialsSsl.certChain);
231
229
  const sslFiles = [
232
230
  cross_helpers_1.fs.promises.readFile(absolutePrivateKeyPath),
233
231
  cross_helpers_1.fs.promises.readFile(absoluteCertChainPath),
234
232
  ];
235
233
  if (this.config.credentialsSsl.rootCA !== 'rootCA') {
236
- const absoluteRootCAPath = (0, node_path_1.isAbsolute)(this.config.credentialsSsl.rootCA)
234
+ const absoluteRootCAPath = cross_helpers_1.path.isAbsolute(this.config.credentialsSsl.rootCA)
237
235
  ? this.config.credentialsSsl.rootCA
238
- : (0, node_path_1.join)(this.baseDir, this.config.credentialsSsl.rootCA);
236
+ : cross_helpers_1.path.join(this.baseDir, this.config.credentialsSsl.rootCA);
239
237
  sslFiles.unshift(cross_helpers_1.fs.promises.readFile(absoluteRootCAPath));
240
238
  }
241
239
  return Promise.all(sslFiles).then(([rootCA, privateKey, certChain]) => grpc_js_1.credentials.createSsl(rootCA, privateKey, certChain));
@@ -463,4 +461,4 @@ class gRPCLoader {
463
461
  }
464
462
  }
465
463
  }
466
- exports.gRPCLoader = gRPCLoader;
464
+ exports.GrpcLoaderHelper = GrpcLoaderHelper;
package/cjs/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadGrpcSubgraph = loadGrpcSubgraph;
4
- const gRPCLoader_1 = require("./gRPCLoader");
4
+ const grpcLoaderHelper_js_1 = require("./grpcLoaderHelper.js");
5
5
  function loadGrpcSubgraph(name, options) {
6
6
  return (ctx) => ({
7
7
  name,
8
- schema$: new gRPCLoader_1.gRPCLoader(name, ctx.cwd, ctx.logger, options).buildSchema(),
8
+ schema$: new grpcLoaderHelper_js_1.GrpcLoaderHelper(name, ctx.cwd, ctx.logger, options).buildSchema(),
9
9
  });
10
10
  }
@@ -1,28 +1,27 @@
1
- import { specifiedDirectives } from "graphql";
2
- import { SchemaComposer } from "graphql-compose";
3
- import { GraphQLBigInt, GraphQLByte, GraphQLUnsignedInt, GraphQLVoid, GraphQLJSON } from "graphql-scalars";
4
- import { EnumDirective, grpcConnectivityStateDirective, grpcMethodDirective, grpcRootJsonDirective, transportDirective } from "./directives.js";
5
- import { credentials } from '@grpc/grpc-js';
1
+ import globby from 'globby';
2
+ import { specifiedDirectives } from 'graphql';
3
+ import { SchemaComposer, } from 'graphql-compose';
4
+ import { GraphQLBigInt, GraphQLByte, GraphQLJSON, GraphQLUnsignedInt, GraphQLVoid, } from 'graphql-scalars';
6
5
  import protobufjs from 'protobufjs';
7
- import { stringInterpolator } from '@graphql-mesh/string-interpolation';
8
- import { isAbsolute, join } from "node:path";
9
- import { fs } from "@graphql-mesh/cross-helpers";
10
- import globby from "globby";
11
- import { addIncludePathResolver, getTypeName, walkToFindTypePath } from "./utils.js";
12
- import { GraphQLStreamDirective } from "@graphql-tools/utils";
13
6
  import descriptor from 'protobufjs/ext/descriptor/index.js';
14
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 { GraphQLStreamDirective } from '@graphql-tools/utils';
11
+ import { credentials } from '@grpc/grpc-js';
15
12
  import { AsyncDisposableStack } from '@whatwg-node/disposablestack';
13
+ import { EnumDirective, grpcConnectivityStateDirective, grpcMethodDirective, grpcRootJsonDirective, transportDirective, } from './directives.js';
14
+ import { addIncludePathResolver, getTypeName, walkToFindTypePath } from './utils.js';
16
15
  const { Root } = protobufjs;
17
16
  const QUERY_METHOD_PREFIXES = ['get', 'list', 'search'];
18
- export class gRPCLoader {
17
+ export class GrpcLoaderHelper {
19
18
  constructor(subgraphName, baseDir, logger, config) {
20
19
  this.subgraphName = subgraphName;
21
20
  this.baseDir = baseDir;
22
21
  this.logger = logger;
23
22
  this.config = config;
24
23
  this.schemaComposer = new SchemaComposer();
25
- this.asyncDisposableStack = new AsyncDisposableStack;
24
+ this.asyncDisposableStack = new AsyncDisposableStack();
26
25
  }
27
26
  [Symbol.asyncDispose]() {
28
27
  return this.asyncDisposableStack.disposeAsync();
@@ -83,8 +82,8 @@ export class gRPCLoader {
83
82
  this.logger.debug(`Building the final GraphQL Schema`);
84
83
  this.schemaComposer.addDirective(transportDirective);
85
84
  const schema = this.schemaComposer.buildSchema();
86
- const schemaExtensions = schema.extensions = schema.extensions || {};
87
- const directiveExtensions = schemaExtensions.directives = schemaExtensions.directives || {};
85
+ const schemaExtensions = (schema.extensions = schema.extensions || {});
86
+ const directiveExtensions = (schemaExtensions.directives = schemaExtensions.directives || {});
88
87
  directiveExtensions.transport = {
89
88
  subgraph: this.subgraphName,
90
89
  kind: 'grpc',
@@ -104,11 +103,10 @@ export class gRPCLoader {
104
103
  this.logger.debug(`Creating gRPC Reflection Client`);
105
104
  const reflectionClient = new Client(reflectionEndpoint, creds);
106
105
  this.asyncDisposableStack.defer(() => reflectionClient.grpcClient.close());
107
- return reflectionClient.listServices().then(services => (services.filter(service => service && !service?.startsWith('grpc.'))
108
- .map(service => {
106
+ return reflectionClient.listServices().then(services => services.filter(service => service && !service?.startsWith('grpc.')).map(service => {
109
107
  this.logger.debug(`Resolving root of Service: ${service} from the reflection response`);
110
108
  return reflectionClient.fileContainingSymbol(service);
111
- })));
109
+ }));
112
110
  }
113
111
  async processDescriptorFile() {
114
112
  let fileName;
@@ -117,16 +115,16 @@ export class gRPCLoader {
117
115
  fileName = this.config.source.file;
118
116
  options = {
119
117
  ...this.config.source.load,
120
- includeDirs: this.config.source.load.includeDirs?.map(includeDir => isAbsolute(includeDir) ? includeDir : join(this.baseDir, includeDir)),
118
+ includeDirs: this.config.source.load.includeDirs?.map(includeDir => path.isAbsolute(includeDir) ? includeDir : path.join(this.baseDir, includeDir)),
121
119
  };
122
120
  }
123
121
  else {
124
122
  fileName = this.config.source;
125
123
  }
126
124
  fileName = stringInterpolator.parse(fileName, { env: process.env });
127
- const absoluteFilePath = isAbsolute(fileName)
125
+ const absoluteFilePath = path.isAbsolute(fileName)
128
126
  ? fileName
129
- : join(this.baseDir, fileName);
127
+ : path.join(this.baseDir, fileName);
130
128
  this.logger.debug(`Using the descriptor set from ${absoluteFilePath} `);
131
129
  const descriptorSetBuffer = await fs.promises.readFile(absoluteFilePath);
132
130
  this.logger.debug(`Reading ${absoluteFilePath} `);
@@ -162,7 +160,7 @@ export class gRPCLoader {
162
160
  options = {
163
161
  ...options,
164
162
  ...this.config.source.load,
165
- includeDirs: this.config.source.load?.includeDirs?.map(includeDir => isAbsolute(includeDir) ? includeDir : join(this.baseDir, includeDir)),
163
+ includeDirs: this.config.source.load?.includeDirs?.map(includeDir => path.isAbsolute(includeDir) ? includeDir : path.join(this.baseDir, includeDir)),
166
164
  };
167
165
  if (options.includeDirs) {
168
166
  if (!Array.isArray(options.includeDirs)) {
@@ -179,7 +177,7 @@ export class gRPCLoader {
179
177
  cwd: this.baseDir,
180
178
  });
181
179
  this.logger.debug(`Loading proto files(${fileGlob}); \n ${fileNames.join('\n')} `);
182
- protoRoot = await protoRoot.load(fileNames.map(filePath => isAbsolute(filePath) ? filePath : join(this.baseDir, filePath)), options);
180
+ protoRoot = await protoRoot.load(fileNames.map(filePath => path.isAbsolute(filePath) ? filePath : path.join(this.baseDir, filePath)), options);
183
181
  this.logger.debug(`Adding proto content to the root`);
184
182
  return protoRoot;
185
183
  }
@@ -218,20 +216,20 @@ export class gRPCLoader {
218
216
  this.logger.debug(`Getting channel credentials`);
219
217
  if (this.config.credentialsSsl) {
220
218
  this.logger.debug(() => `Using SSL Connection with credentials at ${this.config.credentialsSsl.privateKey} & ${this.config.credentialsSsl.certChain}`);
221
- const absolutePrivateKeyPath = isAbsolute(this.config.credentialsSsl.privateKey)
219
+ const absolutePrivateKeyPath = path.isAbsolute(this.config.credentialsSsl.privateKey)
222
220
  ? this.config.credentialsSsl.privateKey
223
- : join(this.baseDir, this.config.credentialsSsl.privateKey);
224
- const absoluteCertChainPath = isAbsolute(this.config.credentialsSsl.certChain)
221
+ : path.join(this.baseDir, this.config.credentialsSsl.privateKey);
222
+ const absoluteCertChainPath = path.isAbsolute(this.config.credentialsSsl.certChain)
225
223
  ? this.config.credentialsSsl.certChain
226
- : join(this.baseDir, this.config.credentialsSsl.certChain);
224
+ : path.join(this.baseDir, this.config.credentialsSsl.certChain);
227
225
  const sslFiles = [
228
226
  fs.promises.readFile(absolutePrivateKeyPath),
229
227
  fs.promises.readFile(absoluteCertChainPath),
230
228
  ];
231
229
  if (this.config.credentialsSsl.rootCA !== 'rootCA') {
232
- const absoluteRootCAPath = isAbsolute(this.config.credentialsSsl.rootCA)
230
+ const absoluteRootCAPath = path.isAbsolute(this.config.credentialsSsl.rootCA)
233
231
  ? this.config.credentialsSsl.rootCA
234
- : join(this.baseDir, this.config.credentialsSsl.rootCA);
232
+ : path.join(this.baseDir, this.config.credentialsSsl.rootCA);
235
233
  sslFiles.unshift(fs.promises.readFile(absoluteRootCAPath));
236
234
  }
237
235
  return Promise.all(sslFiles).then(([rootCA, privateKey, certChain]) => credentials.createSsl(rootCA, privateKey, certChain));
package/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { gRPCLoader } from "./gRPCLoader";
1
+ import { GrpcLoaderHelper } from './grpcLoaderHelper.js';
2
2
  export function loadGrpcSubgraph(name, options) {
3
3
  return (ctx) => ({
4
4
  name,
5
- schema$: new gRPCLoader(name, ctx.cwd, ctx.logger, options).buildSchema(),
5
+ schema$: new GrpcLoaderHelper(name, ctx.cwd, ctx.logger, options).buildSchema(),
6
6
  });
7
7
  }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@omnigraph/grpc",
3
- "version": "0.0.1-alpha-20241030124810-c0e8113edb4c8fd5b24bd53fd28ec5b664e9922e",
3
+ "version": "0.0.1-alpha-20241030131730-1359d5277c2d37355cd8bcfebf07b0160688def4",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "*"
7
7
  },
8
8
  "dependencies": {
9
9
  "@ardatan/grpc-reflection-js": "^0.0.2",
10
+ "@graphql-mesh/cross-helpers": "^0.4.7",
10
11
  "@graphql-mesh/string-interpolation": "^0.5.6",
11
- "@graphql-mesh/transport-common": "0.7.12-alpha-20241030124810-c0e8113edb4c8fd5b24bd53fd28ec5b664e9922e",
12
+ "@graphql-mesh/transport-common": "0.7.12-alpha-20241030131730-1359d5277c2d37355cd8bcfebf07b0160688def4",
12
13
  "@graphql-tools/utils": "^10.5.5",
13
14
  "@grpc/grpc-js": "^1.1.7",
14
15
  "@whatwg-node/disposablestack": "^0.0.5",
@@ -1,8 +1,8 @@
1
- import type { Logger, YamlConfig } from "@graphql-mesh/types";
2
- import { type ChannelCredentials } from '@grpc/grpc-js';
3
1
  import protobufjs, { type AnyNestedObject } from 'protobufjs';
4
- import { type MaybePromise } from "@graphql-tools/utils";
5
- export declare class gRPCLoader implements AsyncDisposable {
2
+ import type { Logger, YamlConfig } from '@graphql-mesh/types';
3
+ import { type MaybePromise } from '@graphql-tools/utils';
4
+ import { type ChannelCredentials } from '@grpc/grpc-js';
5
+ export declare class GrpcLoaderHelper implements AsyncDisposable {
6
6
  private subgraphName;
7
7
  private baseDir;
8
8
  private logger;
@@ -1,8 +1,8 @@
1
- import type { Logger, YamlConfig } from "@graphql-mesh/types";
2
- import { type ChannelCredentials } from '@grpc/grpc-js';
3
1
  import protobufjs, { type AnyNestedObject } from 'protobufjs';
4
- import { type MaybePromise } from "@graphql-tools/utils";
5
- export declare class gRPCLoader implements AsyncDisposable {
2
+ import type { Logger, YamlConfig } from '@graphql-mesh/types';
3
+ import { type MaybePromise } from '@graphql-tools/utils';
4
+ import { type ChannelCredentials } from '@grpc/grpc-js';
5
+ export declare class GrpcLoaderHelper implements AsyncDisposable {
6
6
  private subgraphName;
7
7
  private baseDir;
8
8
  private logger;
@@ -1,4 +1,4 @@
1
- import type { Logger, YamlConfig } from "@graphql-mesh/types";
1
+ import type { Logger, YamlConfig } from '@graphql-mesh/types';
2
2
  interface LoaderContext {
3
3
  cwd: string;
4
4
  logger: Logger;
@@ -1,4 +1,4 @@
1
- import type { Logger, YamlConfig } from "@graphql-mesh/types";
1
+ import type { Logger, YamlConfig } from '@graphql-mesh/types';
2
2
  interface LoaderContext {
3
3
  cwd: string;
4
4
  logger: Logger;