@graphql-mesh/merger-stitching 0.95.0 → 0.95.1-alpha-20230731151755-1fb00a173
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 +1 -80
- package/esm/index.js +1 -80
- package/package.json +5 -6
- package/typings/index.d.cts +1 -5
- package/typings/index.d.ts +1 -5
package/cjs/index.js
CHANGED
|
@@ -1,95 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
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
3
|
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");
|
|
10
|
-
const APOLLO_GET_SERVICE_DEFINITION_QUERY = /* GraphQL */ `
|
|
11
|
-
query __ApolloGetServiceDefinition__ {
|
|
12
|
-
_service {
|
|
13
|
-
sdl
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
`;
|
|
17
4
|
class StitchingMerger {
|
|
18
5
|
constructor(options) {
|
|
19
6
|
this.name = 'stitching';
|
|
20
7
|
this.logger = options.logger;
|
|
21
|
-
this.store = options.store;
|
|
22
|
-
}
|
|
23
|
-
isFederatedSchema(schema) {
|
|
24
|
-
const queryType = schema.getQueryType();
|
|
25
|
-
if (queryType) {
|
|
26
|
-
const queryFields = queryType.getFields();
|
|
27
|
-
return '_service' in queryFields;
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
async replaceFederationSDLWithStitchingSDL(name, oldSchema, executor, stitchingDirectives) {
|
|
32
|
-
const rawSourceLogger = this.logger.child(name);
|
|
33
|
-
rawSourceLogger.debug(`Extracting existing resolvers if available`);
|
|
34
|
-
const resolvers = (0, utils_1.extractResolvers)(oldSchema);
|
|
35
|
-
let newSchema = await this.store
|
|
36
|
-
.proxy(`${name}_stitching`, store_1.PredefinedProxyOptions.GraphQLSchemaWithDiffing)
|
|
37
|
-
.getWithSet(async () => {
|
|
38
|
-
this.logger.debug(`Fetching Apollo Federated Service SDL for ${name}`);
|
|
39
|
-
let federationSdl;
|
|
40
|
-
if (oldSchema.extensions?.directives?.link) {
|
|
41
|
-
federationSdl = (0, utils_2.printSchemaWithDirectives)(oldSchema);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
const sdlQueryResult = (await executor({
|
|
45
|
-
document: (0, graphql_1.parse)(APOLLO_GET_SERVICE_DEFINITION_QUERY),
|
|
46
|
-
}));
|
|
47
|
-
if (sdlQueryResult.errors?.length) {
|
|
48
|
-
throw new AggregateError(sdlQueryResult.errors, `Failed on fetching Federated SDL for ${name}`);
|
|
49
|
-
}
|
|
50
|
-
federationSdl = sdlQueryResult.data._service.sdl;
|
|
51
|
-
}
|
|
52
|
-
this.logger.debug(`Generating Stitching SDL for ${name}`);
|
|
53
|
-
const stitchingSdl = (0, stitching_directives_1.federationToStitchingSDL)(federationSdl, stitchingDirectives);
|
|
54
|
-
return (0, graphql_1.buildSchema)(stitchingSdl, {
|
|
55
|
-
assumeValid: true,
|
|
56
|
-
assumeValidSDL: true,
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
rawSourceLogger.debug(`Adding existing resolvers back to the schema`);
|
|
60
|
-
newSchema = (0, schema_1.addResolversToSchema)({
|
|
61
|
-
schema: newSchema,
|
|
62
|
-
resolvers,
|
|
63
|
-
updateResolversInPlace: true,
|
|
64
|
-
resolverValidationOptions: {
|
|
65
|
-
requireResolversToMatchSchema: 'ignore',
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
newSchema.extensions = oldSchema.extensions;
|
|
69
|
-
return newSchema;
|
|
70
8
|
}
|
|
71
9
|
async getUnifiedSchema(context) {
|
|
72
10
|
const { rawSources, typeDefs, resolvers } = context;
|
|
73
|
-
this.logger.debug(`Stitching directives are being generated`);
|
|
74
|
-
const defaultStitchingDirectives = (0, stitching_directives_1.stitchingDirectives)({
|
|
75
|
-
pathToDirectivesInExtensions: ['directives'],
|
|
76
|
-
});
|
|
77
|
-
this.logger.debug(`Checking if any of sources has federation metadata`);
|
|
78
|
-
const subschemas = await Promise.all(rawSources.map(async (rawSource) => {
|
|
79
|
-
if (rawSource.batch == null) {
|
|
80
|
-
rawSource.batch = true;
|
|
81
|
-
}
|
|
82
|
-
if (this.isFederatedSchema(rawSource.schema)) {
|
|
83
|
-
this.logger.debug(`${rawSource.name} has federated schema.`);
|
|
84
|
-
rawSource.schema = await this.replaceFederationSDLWithStitchingSDL(rawSource.name, rawSource.schema, rawSource.executor, defaultStitchingDirectives);
|
|
85
|
-
}
|
|
86
|
-
rawSource.merge =
|
|
87
|
-
defaultStitchingDirectives.stitchingDirectivesTransformer(rawSource).merge;
|
|
88
|
-
return rawSource;
|
|
89
|
-
}));
|
|
90
11
|
this.logger.debug(`Stitching the source schemas`);
|
|
91
12
|
const unifiedSchema = (0, stitch_1.stitchSchemas)({
|
|
92
|
-
subschemas,
|
|
13
|
+
subschemas: rawSources,
|
|
93
14
|
typeDefs,
|
|
94
15
|
resolvers,
|
|
95
16
|
typeMergingOptions: {
|
package/esm/index.js
CHANGED
|
@@ -1,93 +1,14 @@
|
|
|
1
|
-
import { buildSchema, parse } from 'graphql';
|
|
2
|
-
import { PredefinedProxyOptions } from '@graphql-mesh/store';
|
|
3
|
-
import { extractResolvers } from '@graphql-mesh/utils';
|
|
4
|
-
import { addResolversToSchema } from '@graphql-tools/schema';
|
|
5
1
|
import { stitchSchemas, ValidationLevel } from '@graphql-tools/stitch';
|
|
6
|
-
import { federationToStitchingSDL, stitchingDirectives, } from '@graphql-tools/stitching-directives';
|
|
7
|
-
import { printSchemaWithDirectives } from '@graphql-tools/utils';
|
|
8
|
-
const APOLLO_GET_SERVICE_DEFINITION_QUERY = /* GraphQL */ `
|
|
9
|
-
query __ApolloGetServiceDefinition__ {
|
|
10
|
-
_service {
|
|
11
|
-
sdl
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
`;
|
|
15
2
|
export default class StitchingMerger {
|
|
16
3
|
constructor(options) {
|
|
17
4
|
this.name = 'stitching';
|
|
18
5
|
this.logger = options.logger;
|
|
19
|
-
this.store = options.store;
|
|
20
|
-
}
|
|
21
|
-
isFederatedSchema(schema) {
|
|
22
|
-
const queryType = schema.getQueryType();
|
|
23
|
-
if (queryType) {
|
|
24
|
-
const queryFields = queryType.getFields();
|
|
25
|
-
return '_service' in queryFields;
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
async replaceFederationSDLWithStitchingSDL(name, oldSchema, executor, stitchingDirectives) {
|
|
30
|
-
const rawSourceLogger = this.logger.child(name);
|
|
31
|
-
rawSourceLogger.debug(`Extracting existing resolvers if available`);
|
|
32
|
-
const resolvers = extractResolvers(oldSchema);
|
|
33
|
-
let newSchema = await this.store
|
|
34
|
-
.proxy(`${name}_stitching`, PredefinedProxyOptions.GraphQLSchemaWithDiffing)
|
|
35
|
-
.getWithSet(async () => {
|
|
36
|
-
this.logger.debug(`Fetching Apollo Federated Service SDL for ${name}`);
|
|
37
|
-
let federationSdl;
|
|
38
|
-
if (oldSchema.extensions?.directives?.link) {
|
|
39
|
-
federationSdl = printSchemaWithDirectives(oldSchema);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const sdlQueryResult = (await executor({
|
|
43
|
-
document: parse(APOLLO_GET_SERVICE_DEFINITION_QUERY),
|
|
44
|
-
}));
|
|
45
|
-
if (sdlQueryResult.errors?.length) {
|
|
46
|
-
throw new AggregateError(sdlQueryResult.errors, `Failed on fetching Federated SDL for ${name}`);
|
|
47
|
-
}
|
|
48
|
-
federationSdl = sdlQueryResult.data._service.sdl;
|
|
49
|
-
}
|
|
50
|
-
this.logger.debug(`Generating Stitching SDL for ${name}`);
|
|
51
|
-
const stitchingSdl = federationToStitchingSDL(federationSdl, stitchingDirectives);
|
|
52
|
-
return buildSchema(stitchingSdl, {
|
|
53
|
-
assumeValid: true,
|
|
54
|
-
assumeValidSDL: true,
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
rawSourceLogger.debug(`Adding existing resolvers back to the schema`);
|
|
58
|
-
newSchema = addResolversToSchema({
|
|
59
|
-
schema: newSchema,
|
|
60
|
-
resolvers,
|
|
61
|
-
updateResolversInPlace: true,
|
|
62
|
-
resolverValidationOptions: {
|
|
63
|
-
requireResolversToMatchSchema: 'ignore',
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
newSchema.extensions = oldSchema.extensions;
|
|
67
|
-
return newSchema;
|
|
68
6
|
}
|
|
69
7
|
async getUnifiedSchema(context) {
|
|
70
8
|
const { rawSources, typeDefs, resolvers } = context;
|
|
71
|
-
this.logger.debug(`Stitching directives are being generated`);
|
|
72
|
-
const defaultStitchingDirectives = stitchingDirectives({
|
|
73
|
-
pathToDirectivesInExtensions: ['directives'],
|
|
74
|
-
});
|
|
75
|
-
this.logger.debug(`Checking if any of sources has federation metadata`);
|
|
76
|
-
const subschemas = await Promise.all(rawSources.map(async (rawSource) => {
|
|
77
|
-
if (rawSource.batch == null) {
|
|
78
|
-
rawSource.batch = true;
|
|
79
|
-
}
|
|
80
|
-
if (this.isFederatedSchema(rawSource.schema)) {
|
|
81
|
-
this.logger.debug(`${rawSource.name} has federated schema.`);
|
|
82
|
-
rawSource.schema = await this.replaceFederationSDLWithStitchingSDL(rawSource.name, rawSource.schema, rawSource.executor, defaultStitchingDirectives);
|
|
83
|
-
}
|
|
84
|
-
rawSource.merge =
|
|
85
|
-
defaultStitchingDirectives.stitchingDirectivesTransformer(rawSource).merge;
|
|
86
|
-
return rawSource;
|
|
87
|
-
}));
|
|
88
9
|
this.logger.debug(`Stitching the source schemas`);
|
|
89
10
|
const unifiedSchema = stitchSchemas({
|
|
90
|
-
subschemas,
|
|
11
|
+
subschemas: rawSources,
|
|
91
12
|
typeDefs,
|
|
92
13
|
resolvers,
|
|
93
14
|
typeMergingOptions: {
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/merger-stitching",
|
|
3
|
-
"version": "0.95.
|
|
3
|
+
"version": "0.95.1-alpha-20230731151755-1fb00a173",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/store": "
|
|
7
|
-
"@graphql-mesh/types": "
|
|
8
|
-
"@graphql-mesh/utils": "
|
|
6
|
+
"@graphql-mesh/store": "0.95.1-alpha-20230731151755-1fb00a173",
|
|
7
|
+
"@graphql-mesh/types": "0.95.1-alpha-20230731151755-1fb00a173",
|
|
8
|
+
"@graphql-mesh/utils": "0.95.1-alpha-20230731151755-1fb00a173",
|
|
9
9
|
"@graphql-tools/utils": "^9.2.1 || ^10.0.0",
|
|
10
10
|
"graphql": "*",
|
|
11
11
|
"tslib": "^2.4.0"
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@graphql-tools/delegate": "^10.0.0",
|
|
15
15
|
"@graphql-tools/schema": "^10.0.0",
|
|
16
|
-
"@graphql-tools/stitch": "^9.0.0"
|
|
17
|
-
"@graphql-tools/stitching-directives": "^3.0.0"
|
|
16
|
+
"@graphql-tools/stitch": "^9.0.0"
|
|
18
17
|
},
|
|
19
18
|
"repository": {
|
|
20
19
|
"type": "git",
|
package/typings/index.d.cts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { GraphQLSchema } from 'graphql';
|
|
2
1
|
import { MeshMerger, MeshMergerContext, MeshMergerOptions } from '@graphql-mesh/types';
|
|
3
2
|
export default class StitchingMerger implements MeshMerger {
|
|
4
3
|
name: string;
|
|
5
4
|
private logger;
|
|
6
|
-
private store;
|
|
7
5
|
constructor(options: MeshMergerOptions);
|
|
8
|
-
private isFederatedSchema;
|
|
9
|
-
private replaceFederationSDLWithStitchingSDL;
|
|
10
6
|
getUnifiedSchema(context: MeshMergerContext): Promise<{
|
|
11
|
-
schema: GraphQLSchema;
|
|
7
|
+
schema: import("graphql").GraphQLSchema;
|
|
12
8
|
}>;
|
|
13
9
|
}
|
package/typings/index.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { GraphQLSchema } from 'graphql';
|
|
2
1
|
import { MeshMerger, MeshMergerContext, MeshMergerOptions } from '@graphql-mesh/types';
|
|
3
2
|
export default class StitchingMerger implements MeshMerger {
|
|
4
3
|
name: string;
|
|
5
4
|
private logger;
|
|
6
|
-
private store;
|
|
7
5
|
constructor(options: MeshMergerOptions);
|
|
8
|
-
private isFederatedSchema;
|
|
9
|
-
private replaceFederationSDLWithStitchingSDL;
|
|
10
6
|
getUnifiedSchema(context: MeshMergerContext): Promise<{
|
|
11
|
-
schema: GraphQLSchema;
|
|
7
|
+
schema: import("graphql").GraphQLSchema;
|
|
12
8
|
}>;
|
|
13
9
|
}
|