@graphql-mesh/merger-stitching 1.0.0-alpha-20220804093904-8e2e41f7f → 1.0.0-alpha-20230420181317-a95037648
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/{index.js → cjs/index.js} +36 -29
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +23 -17
- package/package.json +29 -22
- package/typings/index.d.cts +13 -0
- package/{index.d.ts → typings/index.d.ts} +1 -1
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const graphql_1 = require("graphql");
|
|
4
|
+
const store_1 = require("@graphql-mesh/store");
|
|
5
|
+
const utils_1 = require("@graphql-mesh/utils");
|
|
6
|
+
const schema_1 = require("@graphql-tools/schema");
|
|
7
|
+
const stitch_1 = require("@graphql-tools/stitch");
|
|
8
|
+
const stitching_directives_1 = require("@graphql-tools/stitching-directives");
|
|
9
|
+
const utils_2 = require("@graphql-tools/utils");
|
|
11
10
|
const APOLLO_GET_SERVICE_DEFINITION_QUERY = /* GraphQL */ `
|
|
12
11
|
query __ApolloGetServiceDefinition__ {
|
|
13
12
|
_service {
|
|
@@ -29,31 +28,37 @@ class StitchingMerger {
|
|
|
29
28
|
}
|
|
30
29
|
return false;
|
|
31
30
|
}
|
|
32
|
-
async replaceFederationSDLWithStitchingSDL(name, oldSchema, executor, stitchingDirectives
|
|
31
|
+
async replaceFederationSDLWithStitchingSDL(name, oldSchema, executor, stitchingDirectives) {
|
|
33
32
|
const rawSourceLogger = this.logger.child(name);
|
|
34
33
|
rawSourceLogger.debug(`Extracting existing resolvers if available`);
|
|
35
|
-
const resolvers =
|
|
34
|
+
const resolvers = (0, utils_1.extractResolvers)(oldSchema);
|
|
36
35
|
let newSchema = await this.store
|
|
37
|
-
.proxy(`${name}_stitching`,
|
|
36
|
+
.proxy(`${name}_stitching`, store_1.PredefinedProxyOptions.GraphQLSchemaWithDiffing)
|
|
38
37
|
.getWithSet(async () => {
|
|
39
|
-
var _a;
|
|
38
|
+
var _a, _b, _c;
|
|
40
39
|
this.logger.debug(`Fetching Apollo Federated Service SDL for ${name}`);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
let federationSdl;
|
|
41
|
+
if ((_b = (_a = oldSchema.extensions) === null || _a === void 0 ? void 0 : _a.directives) === null || _b === void 0 ? void 0 : _b.link) {
|
|
42
|
+
federationSdl = (0, utils_2.printSchemaWithDirectives)(oldSchema);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const sdlQueryResult = (await executor({
|
|
46
|
+
document: (0, graphql_1.parse)(APOLLO_GET_SERVICE_DEFINITION_QUERY),
|
|
47
|
+
}));
|
|
48
|
+
if ((_c = sdlQueryResult.errors) === null || _c === void 0 ? void 0 : _c.length) {
|
|
49
|
+
throw new utils_2.AggregateError(sdlQueryResult.errors, `Failed on fetching Federated SDL for ${name}`);
|
|
50
|
+
}
|
|
51
|
+
federationSdl = sdlQueryResult.data._service.sdl;
|
|
46
52
|
}
|
|
47
|
-
const federationSdl = sdlQueryResult.data._service.sdl;
|
|
48
53
|
this.logger.debug(`Generating Stitching SDL for ${name}`);
|
|
49
|
-
const stitchingSdl =
|
|
50
|
-
return
|
|
54
|
+
const stitchingSdl = (0, stitching_directives_1.federationToStitchingSDL)(federationSdl, stitchingDirectives);
|
|
55
|
+
return (0, graphql_1.buildSchema)(stitchingSdl, {
|
|
51
56
|
assumeValid: true,
|
|
52
57
|
assumeValidSDL: true,
|
|
53
58
|
});
|
|
54
59
|
});
|
|
55
60
|
rawSourceLogger.debug(`Adding existing resolvers back to the schema`);
|
|
56
|
-
newSchema =
|
|
61
|
+
newSchema = (0, schema_1.addResolversToSchema)({
|
|
57
62
|
schema: newSchema,
|
|
58
63
|
resolvers,
|
|
59
64
|
updateResolversInPlace: true,
|
|
@@ -61,12 +66,13 @@ class StitchingMerger {
|
|
|
61
66
|
requireResolversToMatchSchema: 'ignore',
|
|
62
67
|
},
|
|
63
68
|
});
|
|
69
|
+
newSchema.extensions = oldSchema.extensions;
|
|
64
70
|
return newSchema;
|
|
65
71
|
}
|
|
66
72
|
async getUnifiedSchema(context) {
|
|
67
73
|
const { rawSources, typeDefs, resolvers } = context;
|
|
68
74
|
this.logger.debug(`Stitching directives are being generated`);
|
|
69
|
-
const defaultStitchingDirectives =
|
|
75
|
+
const defaultStitchingDirectives = (0, stitching_directives_1.stitchingDirectives)({
|
|
70
76
|
pathToDirectivesInExtensions: ['directives'],
|
|
71
77
|
});
|
|
72
78
|
this.logger.debug(`Checking if any of sources has federation metadata`);
|
|
@@ -78,19 +84,21 @@ class StitchingMerger {
|
|
|
78
84
|
this.logger.debug(`${rawSource.name} has federated schema.`);
|
|
79
85
|
rawSource.schema = await this.replaceFederationSDLWithStitchingSDL(rawSource.name, rawSource.schema, rawSource.executor, defaultStitchingDirectives);
|
|
80
86
|
}
|
|
81
|
-
rawSource.merge =
|
|
87
|
+
rawSource.merge =
|
|
88
|
+
defaultStitchingDirectives.stitchingDirectivesTransformer(rawSource).merge;
|
|
82
89
|
return rawSource;
|
|
83
90
|
}));
|
|
84
91
|
this.logger.debug(`Stitching the source schemas`);
|
|
85
|
-
const unifiedSchema =
|
|
92
|
+
const unifiedSchema = (0, stitch_1.stitchSchemas)({
|
|
86
93
|
subschemas,
|
|
87
94
|
typeDefs,
|
|
88
95
|
resolvers,
|
|
89
96
|
typeMergingOptions: {
|
|
90
97
|
validationSettings: {
|
|
91
|
-
validationLevel:
|
|
98
|
+
validationLevel: stitch_1.ValidationLevel.Off,
|
|
92
99
|
},
|
|
93
100
|
},
|
|
101
|
+
mergeDirectives: true,
|
|
94
102
|
});
|
|
95
103
|
this.logger.debug(`sourceMap is being generated and attached to the unified schema`);
|
|
96
104
|
unifiedSchema.extensions = unifiedSchema.extensions || {};
|
|
@@ -119,5 +127,4 @@ class StitchingMerger {
|
|
|
119
127
|
};
|
|
120
128
|
}
|
|
121
129
|
}
|
|
122
|
-
|
|
123
|
-
module.exports = StitchingMerger;
|
|
130
|
+
exports.default = StitchingMerger;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildSchema, parse } from 'graphql';
|
|
2
|
+
import { PredefinedProxyOptions } from '@graphql-mesh/store';
|
|
2
3
|
import { extractResolvers } from '@graphql-mesh/utils';
|
|
3
|
-
import { federationToStitchingSDL, stitchingDirectives } from '@graphql-tools/stitching-directives';
|
|
4
4
|
import { addResolversToSchema } from '@graphql-tools/schema';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { AggregateError } from '@graphql-tools/utils';
|
|
8
|
-
|
|
5
|
+
import { stitchSchemas, ValidationLevel } from '@graphql-tools/stitch';
|
|
6
|
+
import { federationToStitchingSDL, stitchingDirectives, } from '@graphql-tools/stitching-directives';
|
|
7
|
+
import { AggregateError, printSchemaWithDirectives } from '@graphql-tools/utils';
|
|
9
8
|
const APOLLO_GET_SERVICE_DEFINITION_QUERY = /* GraphQL */ `
|
|
10
9
|
query __ApolloGetServiceDefinition__ {
|
|
11
10
|
_service {
|
|
@@ -13,7 +12,7 @@ const APOLLO_GET_SERVICE_DEFINITION_QUERY = /* GraphQL */ `
|
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
`;
|
|
16
|
-
class StitchingMerger {
|
|
15
|
+
export default class StitchingMerger {
|
|
17
16
|
constructor(options) {
|
|
18
17
|
this.name = 'stitching';
|
|
19
18
|
this.logger = options.logger;
|
|
@@ -34,15 +33,21 @@ class StitchingMerger {
|
|
|
34
33
|
let newSchema = await this.store
|
|
35
34
|
.proxy(`${name}_stitching`, PredefinedProxyOptions.GraphQLSchemaWithDiffing)
|
|
36
35
|
.getWithSet(async () => {
|
|
37
|
-
var _a;
|
|
36
|
+
var _a, _b, _c;
|
|
38
37
|
this.logger.debug(`Fetching Apollo Federated Service SDL for ${name}`);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
let federationSdl;
|
|
39
|
+
if ((_b = (_a = oldSchema.extensions) === null || _a === void 0 ? void 0 : _a.directives) === null || _b === void 0 ? void 0 : _b.link) {
|
|
40
|
+
federationSdl = printSchemaWithDirectives(oldSchema);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const sdlQueryResult = (await executor({
|
|
44
|
+
document: parse(APOLLO_GET_SERVICE_DEFINITION_QUERY),
|
|
45
|
+
}));
|
|
46
|
+
if ((_c = sdlQueryResult.errors) === null || _c === void 0 ? void 0 : _c.length) {
|
|
47
|
+
throw new AggregateError(sdlQueryResult.errors, `Failed on fetching Federated SDL for ${name}`);
|
|
48
|
+
}
|
|
49
|
+
federationSdl = sdlQueryResult.data._service.sdl;
|
|
44
50
|
}
|
|
45
|
-
const federationSdl = sdlQueryResult.data._service.sdl;
|
|
46
51
|
this.logger.debug(`Generating Stitching SDL for ${name}`);
|
|
47
52
|
const stitchingSdl = federationToStitchingSDL(federationSdl, stitchingDirectives);
|
|
48
53
|
return buildSchema(stitchingSdl, {
|
|
@@ -59,6 +64,7 @@ class StitchingMerger {
|
|
|
59
64
|
requireResolversToMatchSchema: 'ignore',
|
|
60
65
|
},
|
|
61
66
|
});
|
|
67
|
+
newSchema.extensions = oldSchema.extensions;
|
|
62
68
|
return newSchema;
|
|
63
69
|
}
|
|
64
70
|
async getUnifiedSchema(context) {
|
|
@@ -76,7 +82,8 @@ class StitchingMerger {
|
|
|
76
82
|
this.logger.debug(`${rawSource.name} has federated schema.`);
|
|
77
83
|
rawSource.schema = await this.replaceFederationSDLWithStitchingSDL(rawSource.name, rawSource.schema, rawSource.executor, defaultStitchingDirectives);
|
|
78
84
|
}
|
|
79
|
-
rawSource.merge =
|
|
85
|
+
rawSource.merge =
|
|
86
|
+
defaultStitchingDirectives.stitchingDirectivesTransformer(rawSource).merge;
|
|
80
87
|
return rawSource;
|
|
81
88
|
}));
|
|
82
89
|
this.logger.debug(`Stitching the source schemas`);
|
|
@@ -89,6 +96,7 @@ class StitchingMerger {
|
|
|
89
96
|
validationLevel: ValidationLevel.Off,
|
|
90
97
|
},
|
|
91
98
|
},
|
|
99
|
+
mergeDirectives: true,
|
|
92
100
|
});
|
|
93
101
|
this.logger.debug(`sourceMap is being generated and attached to the unified schema`);
|
|
94
102
|
unifiedSchema.extensions = unifiedSchema.extensions || {};
|
|
@@ -117,5 +125,3 @@ class StitchingMerger {
|
|
|
117
125
|
};
|
|
118
126
|
}
|
|
119
127
|
}
|
|
120
|
-
|
|
121
|
-
export default StitchingMerger;
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/merger-stitching",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230420181317-a95037648",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/
|
|
7
|
-
"@graphql-mesh/
|
|
8
|
-
"graphql": "
|
|
6
|
+
"@graphql-mesh/store": "1.0.0-alpha-20230420181317-a95037648",
|
|
7
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230420181317-a95037648",
|
|
8
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230420181317-a95037648",
|
|
9
|
+
"@graphql-tools/utils": "^9.2.1",
|
|
10
|
+
"graphql": "*",
|
|
11
|
+
"tslib": "^2.4.0"
|
|
9
12
|
},
|
|
10
13
|
"dependencies": {
|
|
11
|
-
"@graphql-
|
|
12
|
-
"@graphql-tools/
|
|
13
|
-
"@graphql-tools/
|
|
14
|
-
"@graphql-tools/
|
|
15
|
-
"@graphql-tools/stitching-directives": "2.3.1",
|
|
16
|
-
"@graphql-tools/utils": "8.9.0",
|
|
17
|
-
"tslib": "^2.4.0"
|
|
14
|
+
"@graphql-tools/delegate": "9.0.32",
|
|
15
|
+
"@graphql-tools/schema": "9.0.18",
|
|
16
|
+
"@graphql-tools/stitch": "8.7.48",
|
|
17
|
+
"@graphql-tools/stitching-directives": "2.3.34"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -22,21 +22,28 @@
|
|
|
22
22
|
"directory": "packages/mergers/stitching"
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
|
-
"main": "index.js",
|
|
26
|
-
"module": "index.
|
|
27
|
-
"typings": "index.d.ts",
|
|
25
|
+
"main": "cjs/index.js",
|
|
26
|
+
"module": "esm/index.js",
|
|
27
|
+
"typings": "typings/index.d.ts",
|
|
28
28
|
"typescript": {
|
|
29
|
-
"definition": "index.d.ts"
|
|
29
|
+
"definition": "typings/index.d.ts"
|
|
30
30
|
},
|
|
31
|
+
"type": "module",
|
|
31
32
|
"exports": {
|
|
32
33
|
".": {
|
|
33
|
-
"require":
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./typings/index.d.cts",
|
|
36
|
+
"default": "./cjs/index.js"
|
|
37
|
+
},
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./typings/index.d.ts",
|
|
40
|
+
"default": "./esm/index.js"
|
|
41
|
+
},
|
|
42
|
+
"default": {
|
|
43
|
+
"types": "./typings/index.d.ts",
|
|
44
|
+
"default": "./esm/index.js"
|
|
45
|
+
}
|
|
39
46
|
},
|
|
40
47
|
"./package.json": "./package.json"
|
|
41
48
|
}
|
|
42
|
-
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { MeshMerger, MeshMergerContext, MeshMergerOptions } from '@graphql-mesh/types';
|
|
3
|
+
export default class StitchingMerger implements MeshMerger {
|
|
4
|
+
name: string;
|
|
5
|
+
private logger;
|
|
6
|
+
private store;
|
|
7
|
+
constructor(options: MeshMergerOptions);
|
|
8
|
+
private isFederatedSchema;
|
|
9
|
+
private replaceFederationSDLWithStitchingSDL;
|
|
10
|
+
getUnifiedSchema(context: MeshMergerContext): Promise<{
|
|
11
|
+
schema: GraphQLSchema;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MeshMerger, MeshMergerContext, MeshMergerOptions } from '@graphql-mesh/types';
|
|
2
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { MeshMerger, MeshMergerContext, MeshMergerOptions } from '@graphql-mesh/types';
|
|
3
3
|
export default class StitchingMerger implements MeshMerger {
|
|
4
4
|
name: string;
|
|
5
5
|
private logger;
|