@graphql-mesh/supergraph 0.0.1-alpha-20230727180535-dd3ed974b

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 ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphql_1 = require("graphql");
4
+ const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
5
+ const store_1 = require("@graphql-mesh/store");
6
+ const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
7
+ const utils_1 = require("@graphql-mesh/utils");
8
+ const executor_http_1 = require("@graphql-tools/executor-http");
9
+ const federation_1 = require("@graphql-tools/federation");
10
+ class SupergraphHandler {
11
+ constructor({ config, baseDir, store, importFn, logger, }) {
12
+ this.config = config;
13
+ this.baseDir = baseDir;
14
+ this.supergraphSdl = store.proxy('nonExecutableSchema', store_1.PredefinedProxyOptions.JsonWithoutValidation);
15
+ this.importFn = importFn;
16
+ this.logger = logger;
17
+ }
18
+ async getSupergraphSdl() {
19
+ const schemaHeadersFactory = (0, string_interpolation_1.getInterpolatedHeadersFactory)(this.config.schemaHeaders);
20
+ if ((0, utils_1.isUrl)(this.config.source)) {
21
+ const interpolatedSource = string_interpolation_1.stringInterpolator.parse(this.config.source, {
22
+ env: cross_helpers_1.process.env,
23
+ });
24
+ const res = await (0, utils_1.readUrl)(interpolatedSource, {
25
+ headers: schemaHeadersFactory({
26
+ env: cross_helpers_1.process.env,
27
+ }),
28
+ cwd: this.baseDir,
29
+ allowUnknownExtensions: true,
30
+ importFn: this.importFn,
31
+ fetch: this.fetchFn,
32
+ logger: this.logger,
33
+ });
34
+ if (typeof res === 'string') {
35
+ return (0, graphql_1.parse)(res, { noLocation: true });
36
+ }
37
+ return res;
38
+ }
39
+ return this.supergraphSdl.getWithSet(async () => {
40
+ const interpolatedSource = string_interpolation_1.stringInterpolator.parse(this.config.source, {
41
+ env: cross_helpers_1.process.env,
42
+ });
43
+ const sdlOrIntrospection = await (0, utils_1.readFile)(interpolatedSource, {
44
+ cwd: this.baseDir,
45
+ allowUnknownExtensions: true,
46
+ importFn: this.importFn,
47
+ fetch: this.fetchFn,
48
+ logger: this.logger,
49
+ });
50
+ if (typeof sdlOrIntrospection === 'string') {
51
+ return (0, graphql_1.parse)(sdlOrIntrospection, { noLocation: true });
52
+ }
53
+ return sdlOrIntrospection;
54
+ });
55
+ }
56
+ async getMeshSource({ fetchFn }) {
57
+ this.fetchFn = fetchFn;
58
+ const supergraphSdl = await this.getSupergraphSdl();
59
+ const schema = (0, federation_1.getStitchedSchemaFromSupergraphSdl)({
60
+ supergraphSdl,
61
+ onExecutor({ endpoint }) {
62
+ return (0, executor_http_1.buildHTTPExecutor)({ endpoint, fetch: fetchFn });
63
+ },
64
+ });
65
+ return {
66
+ schema,
67
+ };
68
+ }
69
+ }
70
+ exports.default = SupergraphHandler;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
package/esm/index.js ADDED
@@ -0,0 +1,67 @@
1
+ import { parse } from 'graphql';
2
+ import { process } from '@graphql-mesh/cross-helpers';
3
+ import { PredefinedProxyOptions } from '@graphql-mesh/store';
4
+ import { getInterpolatedHeadersFactory, stringInterpolator, } from '@graphql-mesh/string-interpolation';
5
+ import { isUrl, readFile, readUrl } from '@graphql-mesh/utils';
6
+ import { buildHTTPExecutor } from '@graphql-tools/executor-http';
7
+ import { getStitchedSchemaFromSupergraphSdl } from '@graphql-tools/federation';
8
+ export default class SupergraphHandler {
9
+ constructor({ config, baseDir, store, importFn, logger, }) {
10
+ this.config = config;
11
+ this.baseDir = baseDir;
12
+ this.supergraphSdl = store.proxy('nonExecutableSchema', PredefinedProxyOptions.JsonWithoutValidation);
13
+ this.importFn = importFn;
14
+ this.logger = logger;
15
+ }
16
+ async getSupergraphSdl() {
17
+ const schemaHeadersFactory = getInterpolatedHeadersFactory(this.config.schemaHeaders);
18
+ if (isUrl(this.config.source)) {
19
+ const interpolatedSource = stringInterpolator.parse(this.config.source, {
20
+ env: process.env,
21
+ });
22
+ const res = await readUrl(interpolatedSource, {
23
+ headers: schemaHeadersFactory({
24
+ env: process.env,
25
+ }),
26
+ cwd: this.baseDir,
27
+ allowUnknownExtensions: true,
28
+ importFn: this.importFn,
29
+ fetch: this.fetchFn,
30
+ logger: this.logger,
31
+ });
32
+ if (typeof res === 'string') {
33
+ return parse(res, { noLocation: true });
34
+ }
35
+ return res;
36
+ }
37
+ return this.supergraphSdl.getWithSet(async () => {
38
+ const interpolatedSource = stringInterpolator.parse(this.config.source, {
39
+ env: process.env,
40
+ });
41
+ const sdlOrIntrospection = await readFile(interpolatedSource, {
42
+ cwd: this.baseDir,
43
+ allowUnknownExtensions: true,
44
+ importFn: this.importFn,
45
+ fetch: this.fetchFn,
46
+ logger: this.logger,
47
+ });
48
+ if (typeof sdlOrIntrospection === 'string') {
49
+ return parse(sdlOrIntrospection, { noLocation: true });
50
+ }
51
+ return sdlOrIntrospection;
52
+ });
53
+ }
54
+ async getMeshSource({ fetchFn }) {
55
+ this.fetchFn = fetchFn;
56
+ const supergraphSdl = await this.getSupergraphSdl();
57
+ const schema = getStitchedSchemaFromSupergraphSdl({
58
+ supergraphSdl,
59
+ onExecutor({ endpoint }) {
60
+ return buildHTTPExecutor({ endpoint, fetch: fetchFn });
61
+ },
62
+ });
63
+ return {
64
+ schema,
65
+ };
66
+ }
67
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@graphql-mesh/supergraph",
3
+ "version": "0.0.1-alpha-20230727180535-dd3ed974b",
4
+ "sideEffects": false,
5
+ "peerDependencies": {
6
+ "@graphql-mesh/cross-helpers": "^0.4.0",
7
+ "@graphql-mesh/store": "0.94.6-alpha-20230727180535-dd3ed974b",
8
+ "@graphql-mesh/types": "0.94.6-alpha-20230727180535-dd3ed974b",
9
+ "@graphql-mesh/utils": "0.94.6-alpha-20230727180535-dd3ed974b",
10
+ "graphql": "*",
11
+ "tslib": "^2.4.0"
12
+ },
13
+ "dependencies": {
14
+ "@graphql-mesh/string-interpolation": "^0.5.1",
15
+ "@graphql-tools/executor-http": "^1.0.2",
16
+ "@graphql-tools/federation": "^1.1.0",
17
+ "lodash.get": "^4.4.2"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "Urigo/graphql-mesh",
22
+ "directory": "packages/handlers/supergraph"
23
+ },
24
+ "license": "MIT",
25
+ "engines": {
26
+ "node": ">=16.0.0"
27
+ },
28
+ "main": "cjs/index.js",
29
+ "module": "esm/index.js",
30
+ "typings": "typings/index.d.ts",
31
+ "typescript": {
32
+ "definition": "typings/index.d.ts"
33
+ },
34
+ "type": "module",
35
+ "exports": {
36
+ ".": {
37
+ "require": {
38
+ "types": "./typings/index.d.cts",
39
+ "default": "./cjs/index.js"
40
+ },
41
+ "import": {
42
+ "types": "./typings/index.d.ts",
43
+ "default": "./esm/index.js"
44
+ },
45
+ "default": {
46
+ "types": "./typings/index.d.ts",
47
+ "default": "./esm/index.js"
48
+ }
49
+ },
50
+ "./package.json": "./package.json"
51
+ }
52
+ }
@@ -0,0 +1,12 @@
1
+ import { GetMeshSourcePayload, MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
2
+ export default class SupergraphHandler implements MeshHandler {
3
+ private config;
4
+ private baseDir;
5
+ private supergraphSdl;
6
+ private importFn;
7
+ private fetchFn;
8
+ private logger;
9
+ constructor({ config, baseDir, store, importFn, logger, }: MeshHandlerOptions<YamlConfig.Handler['supergraph']>);
10
+ private getSupergraphSdl;
11
+ getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
12
+ }
@@ -0,0 +1,12 @@
1
+ import { GetMeshSourcePayload, MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
2
+ export default class SupergraphHandler implements MeshHandler {
3
+ private config;
4
+ private baseDir;
5
+ private supergraphSdl;
6
+ private importFn;
7
+ private fetchFn;
8
+ private logger;
9
+ constructor({ config, baseDir, store, importFn, logger, }: MeshHandlerOptions<YamlConfig.Handler['supergraph']>);
10
+ private getSupergraphSdl;
11
+ getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
12
+ }