@graphql-mesh/graphql 0.94.7-alpha-20230728075942-6d4cf202c → 0.94.7
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 +4 -47
- package/esm/index.js +6 -49
- package/package.json +5 -5
- package/typings/index.d.cts +1 -2
- package/typings/index.d.ts +1 -2
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");
|
|
11
10
|
const url_loader_1 = require("@graphql-tools/url-loader");
|
|
12
11
|
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,9 +75,6 @@ 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
|
-
}
|
|
81
78
|
return (0, graphql_1.buildSchema)(sdlOrIntrospection, {
|
|
82
79
|
assumeValid: true,
|
|
83
80
|
assumeValidSDL: true,
|
|
@@ -125,14 +122,14 @@ class GraphQLHandler {
|
|
|
125
122
|
});
|
|
126
123
|
return this.getSchemaFromContent(sdlOrIntrospection);
|
|
127
124
|
}
|
|
128
|
-
return this.nonExecutableSchema.getWithSet(
|
|
125
|
+
return this.nonExecutableSchema.getWithSet(() => {
|
|
129
126
|
const endpointFactory = (0, string_interpolation_1.getInterpolatedStringFactory)(httpSourceConfig.endpoint);
|
|
130
127
|
const executor = this.urlLoader.getExecutorAsync(httpSourceConfig.endpoint, {
|
|
131
128
|
...httpSourceConfig,
|
|
132
129
|
customFetch: this.fetchFn,
|
|
133
130
|
subscriptionsProtocol: httpSourceConfig.subscriptionsProtocol,
|
|
134
131
|
});
|
|
135
|
-
function meshIntrospectionExecutor(params) {
|
|
132
|
+
return (0, wrap_1.schemaFromExecutor)(function meshIntrospectionExecutor(params) {
|
|
136
133
|
const resolverData = getResolverData(params);
|
|
137
134
|
return executor({
|
|
138
135
|
...params,
|
|
@@ -142,22 +139,6 @@ class GraphQLHandler {
|
|
|
142
139
|
endpoint: endpointFactory(resolverData),
|
|
143
140
|
},
|
|
144
141
|
});
|
|
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,
|
|
161
142
|
});
|
|
162
143
|
});
|
|
163
144
|
}
|
|
@@ -240,31 +221,7 @@ class GraphQLHandler {
|
|
|
240
221
|
throw error;
|
|
241
222
|
};
|
|
242
223
|
}
|
|
243
|
-
async getMeshSource(
|
|
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 }) {
|
|
224
|
+
async getMeshSource({ fetchFn }) {
|
|
268
225
|
this.fetchFn = fetchFn;
|
|
269
226
|
if ('sources' in this.config) {
|
|
270
227
|
if (this.config.strategy === 'race') {
|
package/esm/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { buildASTSchema, buildClientSchema, buildSchema,
|
|
1
|
+
import { buildASTSchema, buildClientSchema, buildSchema, GraphQLSchema, Kind, print, } 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';
|
|
8
7
|
import { UrlLoader } from '@graphql-tools/url-loader';
|
|
9
|
-
import {
|
|
8
|
+
import { getOperationASTFromRequest, isAsyncIterable, isDocumentNode, memoize1, parseSelectionSet, } from '@graphql-tools/utils';
|
|
9
|
+
import { schemaFromExecutor } from '@graphql-tools/wrap';
|
|
10
10
|
const getResolverData = memoize1(function getResolverData(params) {
|
|
11
11
|
return {
|
|
12
12
|
root: params.rootValue,
|
|
@@ -72,9 +72,6 @@ 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
|
-
}
|
|
78
75
|
return buildSchema(sdlOrIntrospection, {
|
|
79
76
|
assumeValid: true,
|
|
80
77
|
assumeValidSDL: true,
|
|
@@ -122,14 +119,14 @@ export default class GraphQLHandler {
|
|
|
122
119
|
});
|
|
123
120
|
return this.getSchemaFromContent(sdlOrIntrospection);
|
|
124
121
|
}
|
|
125
|
-
return this.nonExecutableSchema.getWithSet(
|
|
122
|
+
return this.nonExecutableSchema.getWithSet(() => {
|
|
126
123
|
const endpointFactory = getInterpolatedStringFactory(httpSourceConfig.endpoint);
|
|
127
124
|
const executor = this.urlLoader.getExecutorAsync(httpSourceConfig.endpoint, {
|
|
128
125
|
...httpSourceConfig,
|
|
129
126
|
customFetch: this.fetchFn,
|
|
130
127
|
subscriptionsProtocol: httpSourceConfig.subscriptionsProtocol,
|
|
131
128
|
});
|
|
132
|
-
function meshIntrospectionExecutor(params) {
|
|
129
|
+
return schemaFromExecutor(function meshIntrospectionExecutor(params) {
|
|
133
130
|
const resolverData = getResolverData(params);
|
|
134
131
|
return executor({
|
|
135
132
|
...params,
|
|
@@ -139,22 +136,6 @@ export default class GraphQLHandler {
|
|
|
139
136
|
endpoint: endpointFactory(resolverData),
|
|
140
137
|
},
|
|
141
138
|
});
|
|
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,
|
|
158
139
|
});
|
|
159
140
|
});
|
|
160
141
|
}
|
|
@@ -237,31 +218,7 @@ export default class GraphQLHandler {
|
|
|
237
218
|
throw error;
|
|
238
219
|
};
|
|
239
220
|
}
|
|
240
|
-
async getMeshSource(
|
|
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 }) {
|
|
221
|
+
async getMeshSource({ fetchFn }) {
|
|
265
222
|
this.fetchFn = fetchFn;
|
|
266
223
|
if ('sources' in this.config) {
|
|
267
224
|
if (this.config.strategy === 'race') {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/graphql",
|
|
3
|
-
"version": "0.94.7
|
|
3
|
+
"version": "0.94.7",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@graphql-mesh/cross-helpers": "^0.4.0",
|
|
7
|
-
"@graphql-mesh/store": "0.94.6
|
|
8
|
-
"@graphql-mesh/types": "0.94.6
|
|
9
|
-
"@graphql-mesh/utils": "0.94.6
|
|
7
|
+
"@graphql-mesh/store": "^0.94.6",
|
|
8
|
+
"@graphql-mesh/types": "^0.94.6",
|
|
9
|
+
"@graphql-mesh/utils": "^0.94.6",
|
|
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",
|
|
18
17
|
"@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,6 +19,5 @@ 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(
|
|
23
|
-
getMeshSourceWithoutFederation({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
|
|
22
|
+
getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
|
|
24
23
|
}
|
package/typings/index.d.ts
CHANGED
|
@@ -19,6 +19,5 @@ 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(
|
|
23
|
-
getMeshSourceWithoutFederation({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
|
|
22
|
+
getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource>;
|
|
24
23
|
}
|