@graphql-mesh/compose-cli 1.3.0-alpha-20241203100420-58d2c6c6c83aa69944086b8bcd3e723766e24fbd → 1.3.0-alpha-20241211122135-773bfd64ca37688dd8c875b68ba597dcbbdec428
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/loadGraphQLHTTPSubgraph.js +119 -11
- package/esm/loadGraphQLHTTPSubgraph.js +120 -12
- package/package.json +3 -2
|
@@ -35,11 +35,117 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.loadGraphQLHTTPSubgraph = loadGraphQLHTTPSubgraph;
|
|
37
37
|
const graphql_1 = require("graphql");
|
|
38
|
+
const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
|
|
38
39
|
const utils_1 = require("@graphql-mesh/utils");
|
|
39
40
|
const utils_2 = require("@graphql-tools/utils");
|
|
41
|
+
function fixExtends(node) {
|
|
42
|
+
return (0, graphql_1.visit)(node, {
|
|
43
|
+
[graphql_1.Kind.OBJECT_TYPE_EXTENSION](node) {
|
|
44
|
+
return {
|
|
45
|
+
...node,
|
|
46
|
+
directives: [
|
|
47
|
+
...(node.directives || []),
|
|
48
|
+
{
|
|
49
|
+
kind: graphql_1.Kind.DIRECTIVE,
|
|
50
|
+
name: {
|
|
51
|
+
kind: graphql_1.Kind.NAME,
|
|
52
|
+
value: 'extends',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
[graphql_1.Kind.INTERFACE_TYPE_EXTENSION](node) {
|
|
60
|
+
return {
|
|
61
|
+
...node,
|
|
62
|
+
directives: [
|
|
63
|
+
...(node.directives || []),
|
|
64
|
+
{
|
|
65
|
+
kind: graphql_1.Kind.DIRECTIVE,
|
|
66
|
+
name: {
|
|
67
|
+
kind: graphql_1.Kind.NAME,
|
|
68
|
+
value: 'extends',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
kind: graphql_1.Kind.INTERFACE_TYPE_DEFINITION,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
[graphql_1.Kind.UNION_TYPE_EXTENSION](node) {
|
|
76
|
+
return {
|
|
77
|
+
...node,
|
|
78
|
+
directives: [
|
|
79
|
+
...(node.directives || []),
|
|
80
|
+
{
|
|
81
|
+
kind: graphql_1.Kind.DIRECTIVE,
|
|
82
|
+
name: {
|
|
83
|
+
kind: graphql_1.Kind.NAME,
|
|
84
|
+
value: 'extends',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
kind: graphql_1.Kind.UNION_TYPE_DEFINITION,
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
[graphql_1.Kind.INPUT_OBJECT_TYPE_EXTENSION](node) {
|
|
92
|
+
return {
|
|
93
|
+
...node,
|
|
94
|
+
directives: [
|
|
95
|
+
...(node.directives || []),
|
|
96
|
+
{
|
|
97
|
+
kind: graphql_1.Kind.DIRECTIVE,
|
|
98
|
+
name: {
|
|
99
|
+
kind: graphql_1.Kind.NAME,
|
|
100
|
+
value: 'extends',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
kind: graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
[graphql_1.Kind.ENUM_TYPE_EXTENSION](node) {
|
|
108
|
+
return {
|
|
109
|
+
...node,
|
|
110
|
+
directives: [
|
|
111
|
+
...(node.directives || []),
|
|
112
|
+
{
|
|
113
|
+
kind: graphql_1.Kind.DIRECTIVE,
|
|
114
|
+
name: {
|
|
115
|
+
kind: graphql_1.Kind.NAME,
|
|
116
|
+
value: 'extends',
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
kind: graphql_1.Kind.ENUM_TYPE_DEFINITION,
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
[graphql_1.Kind.SCALAR_TYPE_EXTENSION](node) {
|
|
124
|
+
return {
|
|
125
|
+
...node,
|
|
126
|
+
directives: [
|
|
127
|
+
...(node.directives || []),
|
|
128
|
+
{
|
|
129
|
+
kind: graphql_1.Kind.DIRECTIVE,
|
|
130
|
+
name: {
|
|
131
|
+
kind: graphql_1.Kind.NAME,
|
|
132
|
+
value: 'extends',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
kind: graphql_1.Kind.SCALAR_TYPE_DEFINITION,
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
}
|
|
40
141
|
function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGETForQueries, operationHeaders, credentials, retry, timeout, source, schemaHeaders, federation = false, transportKind = 'http', }) {
|
|
41
142
|
return (ctx) => {
|
|
42
143
|
let schema$;
|
|
144
|
+
const interpolationData = {
|
|
145
|
+
env: process.env,
|
|
146
|
+
};
|
|
147
|
+
const interpolatedEndpoint = string_interpolation_1.stringInterpolator.parse(endpoint, interpolationData);
|
|
148
|
+
const interpolatedSource = string_interpolation_1.stringInterpolator.parse(source, interpolationData);
|
|
43
149
|
function handleFetchedSchema(schema) {
|
|
44
150
|
return addAnnotations({
|
|
45
151
|
kind: transportKind,
|
|
@@ -55,15 +161,15 @@ function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGETForQuer
|
|
|
55
161
|
},
|
|
56
162
|
}, schema);
|
|
57
163
|
}
|
|
58
|
-
if (
|
|
164
|
+
if (interpolatedSource) {
|
|
59
165
|
let source$;
|
|
60
|
-
if ((0, utils_1.isUrl)(
|
|
61
|
-
source$ = (0, utils_2.mapMaybePromise)(ctx.fetch(
|
|
166
|
+
if ((0, utils_1.isUrl)(interpolatedSource)) {
|
|
167
|
+
source$ = (0, utils_2.mapMaybePromise)(ctx.fetch(interpolatedSource, {
|
|
62
168
|
headers: schemaHeaders,
|
|
63
169
|
}), res => res.text());
|
|
64
170
|
}
|
|
65
|
-
else if ((0, utils_2.isValidPath)(
|
|
66
|
-
source$ = (0, utils_1.readFile)(
|
|
171
|
+
else if ((0, utils_2.isValidPath)(interpolatedSource)) {
|
|
172
|
+
source$ = (0, utils_1.readFile)(interpolatedSource, {
|
|
67
173
|
allowUnknownExtensions: true,
|
|
68
174
|
cwd: ctx.cwd,
|
|
69
175
|
fetch: ctx.fetch,
|
|
@@ -71,14 +177,13 @@ function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGETForQuer
|
|
|
71
177
|
logger: ctx.logger,
|
|
72
178
|
});
|
|
73
179
|
}
|
|
74
|
-
schema$ = (0, utils_2.mapMaybePromise)(source$, sdl => (0, graphql_1.
|
|
180
|
+
schema$ = (0, utils_2.mapMaybePromise)(source$, sdl => (0, graphql_1.buildASTSchema)(fixExtends((0, graphql_1.parse)(sdl, { noLocation: true })), {
|
|
75
181
|
assumeValidSDL: true,
|
|
76
182
|
assumeValid: true,
|
|
77
|
-
noLocation: true,
|
|
78
183
|
}));
|
|
79
184
|
}
|
|
80
185
|
else {
|
|
81
|
-
const fetchAsRegular = () => (0, utils_2.mapMaybePromise)(ctx.fetch(
|
|
186
|
+
const fetchAsRegular = () => (0, utils_2.mapMaybePromise)(ctx.fetch(interpolatedEndpoint, {
|
|
82
187
|
method: method || (useGETForQueries ? 'GET' : 'POST'),
|
|
83
188
|
headers: {
|
|
84
189
|
'Content-Type': 'application/json',
|
|
@@ -110,7 +215,7 @@ function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGETForQuer
|
|
|
110
215
|
return schema;
|
|
111
216
|
});
|
|
112
217
|
});
|
|
113
|
-
const fetchAsFederation = () => (0, utils_2.mapMaybePromise)(ctx.fetch(
|
|
218
|
+
const fetchAsFederation = () => (0, utils_2.mapMaybePromise)(ctx.fetch(interpolatedEndpoint, {
|
|
114
219
|
method: method || (useGETForQueries ? 'GET' : 'POST'),
|
|
115
220
|
headers: {
|
|
116
221
|
'Content-Type': 'application/json',
|
|
@@ -125,10 +230,13 @@ function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGETForQuer
|
|
|
125
230
|
if (result.errors) {
|
|
126
231
|
throw new AggregateError(result.errors.map(err => (0, utils_2.createGraphQLError)(err.message, err)), 'Introspection Query Failed');
|
|
127
232
|
}
|
|
128
|
-
|
|
233
|
+
if (!result.data?._service?.sdl) {
|
|
234
|
+
throw new Error('Federation subgraph does not provide SDL');
|
|
235
|
+
}
|
|
236
|
+
// Replace "extend" keyword with "@extends"
|
|
237
|
+
return (0, graphql_1.buildASTSchema)(fixExtends((0, graphql_1.parse)(result.data._service.sdl, { noLocation: true })), {
|
|
129
238
|
assumeValidSDL: true,
|
|
130
239
|
assumeValid: true,
|
|
131
|
-
noLocation: true,
|
|
132
240
|
});
|
|
133
241
|
});
|
|
134
242
|
});
|
|
@@ -1,9 +1,115 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildASTSchema, buildClientSchema, DirectiveLocation, getIntrospectionQuery, getNamedType, GraphQLDirective, GraphQLList, GraphQLNonNull, GraphQLScalarType, GraphQLSchema, GraphQLString, isObjectType, Kind, parse, visit, } from 'graphql';
|
|
2
|
+
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
2
3
|
import { isUrl, readFile } from '@graphql-mesh/utils';
|
|
3
4
|
import { createGraphQLError, isValidPath, mapMaybePromise, } from '@graphql-tools/utils';
|
|
5
|
+
function fixExtends(node) {
|
|
6
|
+
return visit(node, {
|
|
7
|
+
[Kind.OBJECT_TYPE_EXTENSION](node) {
|
|
8
|
+
return {
|
|
9
|
+
...node,
|
|
10
|
+
directives: [
|
|
11
|
+
...(node.directives || []),
|
|
12
|
+
{
|
|
13
|
+
kind: Kind.DIRECTIVE,
|
|
14
|
+
name: {
|
|
15
|
+
kind: Kind.NAME,
|
|
16
|
+
value: 'extends',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
kind: Kind.OBJECT_TYPE_DEFINITION,
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
[Kind.INTERFACE_TYPE_EXTENSION](node) {
|
|
24
|
+
return {
|
|
25
|
+
...node,
|
|
26
|
+
directives: [
|
|
27
|
+
...(node.directives || []),
|
|
28
|
+
{
|
|
29
|
+
kind: Kind.DIRECTIVE,
|
|
30
|
+
name: {
|
|
31
|
+
kind: Kind.NAME,
|
|
32
|
+
value: 'extends',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
kind: Kind.INTERFACE_TYPE_DEFINITION,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
[Kind.UNION_TYPE_EXTENSION](node) {
|
|
40
|
+
return {
|
|
41
|
+
...node,
|
|
42
|
+
directives: [
|
|
43
|
+
...(node.directives || []),
|
|
44
|
+
{
|
|
45
|
+
kind: Kind.DIRECTIVE,
|
|
46
|
+
name: {
|
|
47
|
+
kind: Kind.NAME,
|
|
48
|
+
value: 'extends',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
kind: Kind.UNION_TYPE_DEFINITION,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
[Kind.INPUT_OBJECT_TYPE_EXTENSION](node) {
|
|
56
|
+
return {
|
|
57
|
+
...node,
|
|
58
|
+
directives: [
|
|
59
|
+
...(node.directives || []),
|
|
60
|
+
{
|
|
61
|
+
kind: Kind.DIRECTIVE,
|
|
62
|
+
name: {
|
|
63
|
+
kind: Kind.NAME,
|
|
64
|
+
value: 'extends',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
[Kind.ENUM_TYPE_EXTENSION](node) {
|
|
72
|
+
return {
|
|
73
|
+
...node,
|
|
74
|
+
directives: [
|
|
75
|
+
...(node.directives || []),
|
|
76
|
+
{
|
|
77
|
+
kind: Kind.DIRECTIVE,
|
|
78
|
+
name: {
|
|
79
|
+
kind: Kind.NAME,
|
|
80
|
+
value: 'extends',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
kind: Kind.ENUM_TYPE_DEFINITION,
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
[Kind.SCALAR_TYPE_EXTENSION](node) {
|
|
88
|
+
return {
|
|
89
|
+
...node,
|
|
90
|
+
directives: [
|
|
91
|
+
...(node.directives || []),
|
|
92
|
+
{
|
|
93
|
+
kind: Kind.DIRECTIVE,
|
|
94
|
+
name: {
|
|
95
|
+
kind: Kind.NAME,
|
|
96
|
+
value: 'extends',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
kind: Kind.SCALAR_TYPE_DEFINITION,
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
4
105
|
export function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGETForQueries, operationHeaders, credentials, retry, timeout, source, schemaHeaders, federation = false, transportKind = 'http', }) {
|
|
5
106
|
return (ctx) => {
|
|
6
107
|
let schema$;
|
|
108
|
+
const interpolationData = {
|
|
109
|
+
env: process.env,
|
|
110
|
+
};
|
|
111
|
+
const interpolatedEndpoint = stringInterpolator.parse(endpoint, interpolationData);
|
|
112
|
+
const interpolatedSource = stringInterpolator.parse(source, interpolationData);
|
|
7
113
|
function handleFetchedSchema(schema) {
|
|
8
114
|
return addAnnotations({
|
|
9
115
|
kind: transportKind,
|
|
@@ -19,15 +125,15 @@ export function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGET
|
|
|
19
125
|
},
|
|
20
126
|
}, schema);
|
|
21
127
|
}
|
|
22
|
-
if (
|
|
128
|
+
if (interpolatedSource) {
|
|
23
129
|
let source$;
|
|
24
|
-
if (isUrl(
|
|
25
|
-
source$ = mapMaybePromise(ctx.fetch(
|
|
130
|
+
if (isUrl(interpolatedSource)) {
|
|
131
|
+
source$ = mapMaybePromise(ctx.fetch(interpolatedSource, {
|
|
26
132
|
headers: schemaHeaders,
|
|
27
133
|
}), res => res.text());
|
|
28
134
|
}
|
|
29
|
-
else if (isValidPath(
|
|
30
|
-
source$ = readFile(
|
|
135
|
+
else if (isValidPath(interpolatedSource)) {
|
|
136
|
+
source$ = readFile(interpolatedSource, {
|
|
31
137
|
allowUnknownExtensions: true,
|
|
32
138
|
cwd: ctx.cwd,
|
|
33
139
|
fetch: ctx.fetch,
|
|
@@ -35,14 +141,13 @@ export function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGET
|
|
|
35
141
|
logger: ctx.logger,
|
|
36
142
|
});
|
|
37
143
|
}
|
|
38
|
-
schema$ = mapMaybePromise(source$, sdl =>
|
|
144
|
+
schema$ = mapMaybePromise(source$, sdl => buildASTSchema(fixExtends(parse(sdl, { noLocation: true })), {
|
|
39
145
|
assumeValidSDL: true,
|
|
40
146
|
assumeValid: true,
|
|
41
|
-
noLocation: true,
|
|
42
147
|
}));
|
|
43
148
|
}
|
|
44
149
|
else {
|
|
45
|
-
const fetchAsRegular = () => mapMaybePromise(ctx.fetch(
|
|
150
|
+
const fetchAsRegular = () => mapMaybePromise(ctx.fetch(interpolatedEndpoint, {
|
|
46
151
|
method: method || (useGETForQueries ? 'GET' : 'POST'),
|
|
47
152
|
headers: {
|
|
48
153
|
'Content-Type': 'application/json',
|
|
@@ -74,7 +179,7 @@ export function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGET
|
|
|
74
179
|
return schema;
|
|
75
180
|
});
|
|
76
181
|
});
|
|
77
|
-
const fetchAsFederation = () => mapMaybePromise(ctx.fetch(
|
|
182
|
+
const fetchAsFederation = () => mapMaybePromise(ctx.fetch(interpolatedEndpoint, {
|
|
78
183
|
method: method || (useGETForQueries ? 'GET' : 'POST'),
|
|
79
184
|
headers: {
|
|
80
185
|
'Content-Type': 'application/json',
|
|
@@ -89,10 +194,13 @@ export function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGET
|
|
|
89
194
|
if (result.errors) {
|
|
90
195
|
throw new AggregateError(result.errors.map(err => createGraphQLError(err.message, err)), 'Introspection Query Failed');
|
|
91
196
|
}
|
|
92
|
-
|
|
197
|
+
if (!result.data?._service?.sdl) {
|
|
198
|
+
throw new Error('Federation subgraph does not provide SDL');
|
|
199
|
+
}
|
|
200
|
+
// Replace "extend" keyword with "@extends"
|
|
201
|
+
return buildASTSchema(fixExtends(parse(result.data._service.sdl, { noLocation: true })), {
|
|
93
202
|
assumeValidSDL: true,
|
|
94
203
|
assumeValid: true,
|
|
95
|
-
noLocation: true,
|
|
96
204
|
});
|
|
97
205
|
});
|
|
98
206
|
});
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/compose-cli",
|
|
3
|
-
"version": "1.3.0-alpha-
|
|
3
|
+
"version": "1.3.0-alpha-20241211122135-773bfd64ca37688dd8c875b68ba597dcbbdec428",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/types": "^0.103.5",
|
|
7
6
|
"graphql": "*"
|
|
8
7
|
},
|
|
9
8
|
"dependencies": {
|
|
10
9
|
"@commander-js/extra-typings": "^12.1.0",
|
|
11
10
|
"@graphql-mesh/fusion-composition": "workspace:^",
|
|
12
11
|
"@graphql-mesh/include": "workspace:^",
|
|
12
|
+
"@graphql-mesh/string-interpolation": "workspace:^",
|
|
13
|
+
"@graphql-mesh/types": "workspace:^",
|
|
13
14
|
"@graphql-mesh/utils": "workspace:^",
|
|
14
15
|
"@graphql-tools/code-file-loader": "^8.1.7",
|
|
15
16
|
"@graphql-tools/graphql-file-loader": "^8.0.5",
|