@graphql-mesh/graphql 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 +47 -4
- package/esm/index.js +49 -6
- package/package.json +5 -5
- package/typings/index.d.cts +2 -1
- package/typings/index.d.ts +2 -1
package/cjs/index.js
CHANGED
|
@@ -7,9 +7,9 @@ const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
|
7
7
|
const store_1 = require("@graphql-mesh/store");
|
|
8
8
|
const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
|
|
9
9
|
const utils_1 = require("@graphql-mesh/utils");
|
|
10
|
+
const federation_1 = require("@graphql-tools/federation");
|
|
10
11
|
const url_loader_1 = require("@graphql-tools/url-loader");
|
|
11
12
|
const utils_2 = require("@graphql-tools/utils");
|
|
12
|
-
const wrap_1 = require("@graphql-tools/wrap");
|
|
13
13
|
const getResolverData = (0, utils_2.memoize1)(function getResolverData(params) {
|
|
14
14
|
return {
|
|
15
15
|
root: params.rootValue,
|
|
@@ -75,6 +75,9 @@ class GraphQLHandler {
|
|
|
75
75
|
}
|
|
76
76
|
getSchemaFromContent(sdlOrIntrospection) {
|
|
77
77
|
if (typeof sdlOrIntrospection === 'string') {
|
|
78
|
+
if (sdlOrIntrospection.includes('@key')) {
|
|
79
|
+
sdlOrIntrospection = sdlOrIntrospection.replace(/extend type (\w+)/g, 'type $1 @extends');
|
|
80
|
+
}
|
|
78
81
|
return (0, graphql_1.buildSchema)(sdlOrIntrospection, {
|
|
79
82
|
assumeValid: true,
|
|
80
83
|
assumeValidSDL: true,
|
|
@@ -122,14 +125,14 @@ class GraphQLHandler {
|
|
|
122
125
|
});
|
|
123
126
|
return this.getSchemaFromContent(sdlOrIntrospection);
|
|
124
127
|
}
|
|
125
|
-
return this.nonExecutableSchema.getWithSet(() => {
|
|
128
|
+
return this.nonExecutableSchema.getWithSet(async () => {
|
|
126
129
|
const endpointFactory = (0, string_interpolation_1.getInterpolatedStringFactory)(httpSourceConfig.endpoint);
|
|
127
130
|
const executor = this.urlLoader.getExecutorAsync(httpSourceConfig.endpoint, {
|
|
128
131
|
...httpSourceConfig,
|
|
129
132
|
customFetch: this.fetchFn,
|
|
130
133
|
subscriptionsProtocol: httpSourceConfig.subscriptionsProtocol,
|
|
131
134
|
});
|
|
132
|
-
|
|
135
|
+
function meshIntrospectionExecutor(params) {
|
|
133
136
|
const resolverData = getResolverData(params);
|
|
134
137
|
return executor({
|
|
135
138
|
...params,
|
|
@@ -139,6 +142,22 @@ class GraphQLHandler {
|
|
|
139
142
|
endpoint: endpointFactory(resolverData),
|
|
140
143
|
},
|
|
141
144
|
});
|
|
145
|
+
}
|
|
146
|
+
const introspection = (await meshIntrospectionExecutor({
|
|
147
|
+
document: (0, graphql_1.parse)((0, graphql_1.getIntrospectionQuery)()),
|
|
148
|
+
}));
|
|
149
|
+
if (introspection.data.__schema.types.find(t => t.name === '_Service')) {
|
|
150
|
+
const sdl = (await meshIntrospectionExecutor({
|
|
151
|
+
document: (0, graphql_1.parse)(federation_1.SubgraphSDLQuery),
|
|
152
|
+
}));
|
|
153
|
+
const schema = (0, graphql_1.buildSchema)(sdl.data._service.sdl.replace(/extend type (\w+)/g, 'type $1 @extends'), {
|
|
154
|
+
assumeValid: true,
|
|
155
|
+
assumeValidSDL: true,
|
|
156
|
+
});
|
|
157
|
+
return schema;
|
|
158
|
+
}
|
|
159
|
+
return (0, graphql_1.buildClientSchema)(introspection.data, {
|
|
160
|
+
assumeValid: true,
|
|
142
161
|
});
|
|
143
162
|
});
|
|
144
163
|
}
|
|
@@ -221,7 +240,31 @@ class GraphQLHandler {
|
|
|
221
240
|
throw error;
|
|
222
241
|
};
|
|
223
242
|
}
|
|
224
|
-
async getMeshSource(
|
|
243
|
+
async getMeshSource(payload) {
|
|
244
|
+
const meshSource = await this.getMeshSourceWithoutFederation(payload);
|
|
245
|
+
if (meshSource.schema.getDirective('key') != null) {
|
|
246
|
+
const typeDefs = (0, graphql_1.visit)((0, utils_2.getDocumentNodeFromSchema)(meshSource.schema), {
|
|
247
|
+
ObjectTypeDefinition(node) {
|
|
248
|
+
if (node.directives?.find(d => d.name.value === 'extends')) {
|
|
249
|
+
return {
|
|
250
|
+
...node,
|
|
251
|
+
directives: node.directives.filter(d => d.name.value !== 'extends'),
|
|
252
|
+
kind: graphql_1.Kind.OBJECT_TYPE_EXTENSION,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return node;
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
const extraConfig = (0, federation_1.getSubschemaForFederationWithTypeDefs)(typeDefs);
|
|
259
|
+
return {
|
|
260
|
+
...meshSource,
|
|
261
|
+
...extraConfig,
|
|
262
|
+
batch: true,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return meshSource;
|
|
266
|
+
}
|
|
267
|
+
async getMeshSourceWithoutFederation({ fetchFn }) {
|
|
225
268
|
this.fetchFn = fetchFn;
|
|
226
269
|
if ('sources' in this.config) {
|
|
227
270
|
if (this.config.strategy === 'race') {
|
package/esm/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { buildASTSchema, buildClientSchema, buildSchema, GraphQLSchema, Kind, print, } from 'graphql';
|
|
1
|
+
import { buildASTSchema, buildClientSchema, buildSchema, getIntrospectionQuery, GraphQLSchema, Kind, parse, print, visit, } from 'graphql';
|
|
2
2
|
import lodashGet from 'lodash.get';
|
|
3
3
|
import { process, util } from '@graphql-mesh/cross-helpers';
|
|
4
4
|
import { PredefinedProxyOptions, ValidationError } from '@graphql-mesh/store';
|
|
5
5
|
import { getInterpolatedHeadersFactory, getInterpolatedStringFactory, parseInterpolationStrings, stringInterpolator, } from '@graphql-mesh/string-interpolation';
|
|
6
6
|
import { isUrl, loadFromModuleExportExpression, readFile, readFileOrUrl, readUrl, } from '@graphql-mesh/utils';
|
|
7
|
+
import { getSubschemaForFederationWithTypeDefs, SubgraphSDLQuery } from '@graphql-tools/federation';
|
|
7
8
|
import { UrlLoader } from '@graphql-tools/url-loader';
|
|
8
|
-
import { getOperationASTFromRequest, isAsyncIterable, isDocumentNode, memoize1, parseSelectionSet, } from '@graphql-tools/utils';
|
|
9
|
-
import { schemaFromExecutor } from '@graphql-tools/wrap';
|
|
9
|
+
import { getDocumentNodeFromSchema, getOperationASTFromRequest, isAsyncIterable, isDocumentNode, memoize1, parseSelectionSet, } from '@graphql-tools/utils';
|
|
10
10
|
const getResolverData = memoize1(function getResolverData(params) {
|
|
11
11
|
return {
|
|
12
12
|
root: params.rootValue,
|
|
@@ -72,6 +72,9 @@ export default class GraphQLHandler {
|
|
|
72
72
|
}
|
|
73
73
|
getSchemaFromContent(sdlOrIntrospection) {
|
|
74
74
|
if (typeof sdlOrIntrospection === 'string') {
|
|
75
|
+
if (sdlOrIntrospection.includes('@key')) {
|
|
76
|
+
sdlOrIntrospection = sdlOrIntrospection.replace(/extend type (\w+)/g, 'type $1 @extends');
|
|
77
|
+
}
|
|
75
78
|
return buildSchema(sdlOrIntrospection, {
|
|
76
79
|
assumeValid: true,
|
|
77
80
|
assumeValidSDL: true,
|
|
@@ -119,14 +122,14 @@ export default class GraphQLHandler {
|
|
|
119
122
|
});
|
|
120
123
|
return this.getSchemaFromContent(sdlOrIntrospection);
|
|
121
124
|
}
|
|
122
|
-
return this.nonExecutableSchema.getWithSet(() => {
|
|
125
|
+
return this.nonExecutableSchema.getWithSet(async () => {
|
|
123
126
|
const endpointFactory = getInterpolatedStringFactory(httpSourceConfig.endpoint);
|
|
124
127
|
const executor = this.urlLoader.getExecutorAsync(httpSourceConfig.endpoint, {
|
|
125
128
|
...httpSourceConfig,
|
|
126
129
|
customFetch: this.fetchFn,
|
|
127
130
|
subscriptionsProtocol: httpSourceConfig.subscriptionsProtocol,
|
|
128
131
|
});
|
|
129
|
-
|
|
132
|
+
function meshIntrospectionExecutor(params) {
|
|
130
133
|
const resolverData = getResolverData(params);
|
|
131
134
|
return executor({
|
|
132
135
|
...params,
|
|
@@ -136,6 +139,22 @@ export default class GraphQLHandler {
|
|
|
136
139
|
endpoint: endpointFactory(resolverData),
|
|
137
140
|
},
|
|
138
141
|
});
|
|
142
|
+
}
|
|
143
|
+
const introspection = (await meshIntrospectionExecutor({
|
|
144
|
+
document: parse(getIntrospectionQuery()),
|
|
145
|
+
}));
|
|
146
|
+
if (introspection.data.__schema.types.find(t => t.name === '_Service')) {
|
|
147
|
+
const sdl = (await meshIntrospectionExecutor({
|
|
148
|
+
document: parse(SubgraphSDLQuery),
|
|
149
|
+
}));
|
|
150
|
+
const schema = buildSchema(sdl.data._service.sdl.replace(/extend type (\w+)/g, 'type $1 @extends'), {
|
|
151
|
+
assumeValid: true,
|
|
152
|
+
assumeValidSDL: true,
|
|
153
|
+
});
|
|
154
|
+
return schema;
|
|
155
|
+
}
|
|
156
|
+
return buildClientSchema(introspection.data, {
|
|
157
|
+
assumeValid: true,
|
|
139
158
|
});
|
|
140
159
|
});
|
|
141
160
|
}
|
|
@@ -218,7 +237,31 @@ export default class GraphQLHandler {
|
|
|
218
237
|
throw error;
|
|
219
238
|
};
|
|
220
239
|
}
|
|
221
|
-
async getMeshSource(
|
|
240
|
+
async getMeshSource(payload) {
|
|
241
|
+
const meshSource = await this.getMeshSourceWithoutFederation(payload);
|
|
242
|
+
if (meshSource.schema.getDirective('key') != null) {
|
|
243
|
+
const typeDefs = visit(getDocumentNodeFromSchema(meshSource.schema), {
|
|
244
|
+
ObjectTypeDefinition(node) {
|
|
245
|
+
if (node.directives?.find(d => d.name.value === 'extends')) {
|
|
246
|
+
return {
|
|
247
|
+
...node,
|
|
248
|
+
directives: node.directives.filter(d => d.name.value !== 'extends'),
|
|
249
|
+
kind: Kind.OBJECT_TYPE_EXTENSION,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return node;
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
const extraConfig = getSubschemaForFederationWithTypeDefs(typeDefs);
|
|
256
|
+
return {
|
|
257
|
+
...meshSource,
|
|
258
|
+
...extraConfig,
|
|
259
|
+
batch: true,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return meshSource;
|
|
263
|
+
}
|
|
264
|
+
async getMeshSourceWithoutFederation({ fetchFn }) {
|
|
222
265
|
this.fetchFn = fetchFn;
|
|
223
266
|
if ('sources' in this.config) {
|
|
224
267
|
if (this.config.strategy === 'race') {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/graphql",
|
|
3
|
-
"version": "0.95.
|
|
3
|
+
"version": "0.95.1-alpha-20230731151755-1fb00a173",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@graphql-mesh/cross-helpers": "^0.4.0",
|
|
7
|
-
"@graphql-mesh/store": "
|
|
8
|
-
"@graphql-mesh/types": "
|
|
9
|
-
"@graphql-mesh/utils": "
|
|
7
|
+
"@graphql-mesh/store": "0.95.1-alpha-20230731151755-1fb00a173",
|
|
8
|
+
"@graphql-mesh/types": "0.95.1-alpha-20230731151755-1fb00a173",
|
|
9
|
+
"@graphql-mesh/utils": "0.95.1-alpha-20230731151755-1fb00a173",
|
|
10
10
|
"@graphql-tools/utils": "^9.2.1 || ^10.0.0",
|
|
11
11
|
"graphql": "*",
|
|
12
12
|
"tslib": "^2.4.0"
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@graphql-mesh/string-interpolation": "^0.5.1",
|
|
16
16
|
"@graphql-tools/delegate": "^10.0.0",
|
|
17
|
+
"@graphql-tools/federation": "^1.1.0",
|
|
17
18
|
"@graphql-tools/url-loader": "^8.0.0",
|
|
18
|
-
"@graphql-tools/wrap": "^10.0.0",
|
|
19
19
|
"lodash.get": "^4.4.2"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
package/typings/index.d.cts
CHANGED
|
@@ -19,5 +19,6 @@ export default class GraphQLHandler implements MeshHandler {
|
|
|
19
19
|
getCodeFirstSource({ source: schemaConfig, }: YamlConfig.GraphQLHandlerCodeFirstConfiguration): Promise<MeshSource>;
|
|
20
20
|
getRaceExecutor(executors: MeshSource['executor'][]): MeshSource['executor'];
|
|
21
21
|
getFallbackExecutor(executors: MeshSource['executor'][]): MeshSource['executor'];
|
|
22
|
-
getMeshSource(
|
|
22
|
+
getMeshSource(payload: GetMeshSourcePayload): Promise<MeshSource>;
|
|
23
|
+
getMeshSourceWithoutFederation({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
|
|
23
24
|
}
|
package/typings/index.d.ts
CHANGED
|
@@ -19,5 +19,6 @@ export default class GraphQLHandler implements MeshHandler {
|
|
|
19
19
|
getCodeFirstSource({ source: schemaConfig, }: YamlConfig.GraphQLHandlerCodeFirstConfiguration): Promise<MeshSource>;
|
|
20
20
|
getRaceExecutor(executors: MeshSource['executor'][]): MeshSource['executor'];
|
|
21
21
|
getFallbackExecutor(executors: MeshSource['executor'][]): MeshSource['executor'];
|
|
22
|
-
getMeshSource(
|
|
22
|
+
getMeshSource(payload: GetMeshSourcePayload): Promise<MeshSource>;
|
|
23
|
+
getMeshSourceWithoutFederation({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
|
|
23
24
|
}
|