@graphql-mesh/compose-cli 1.2.11 → 1.2.12

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.
@@ -37,6 +37,106 @@ exports.loadGraphQLHTTPSubgraph = loadGraphQLHTTPSubgraph;
37
37
  const graphql_1 = require("graphql");
38
38
  const utils_1 = require("@graphql-mesh/utils");
39
39
  const utils_2 = require("@graphql-tools/utils");
40
+ function fixExtends(node) {
41
+ return (0, graphql_1.visit)(node, {
42
+ [graphql_1.Kind.OBJECT_TYPE_EXTENSION](node) {
43
+ return {
44
+ ...node,
45
+ directives: [
46
+ ...(node.directives || []),
47
+ {
48
+ kind: graphql_1.Kind.DIRECTIVE,
49
+ name: {
50
+ kind: graphql_1.Kind.NAME,
51
+ value: 'extends',
52
+ },
53
+ },
54
+ ],
55
+ kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
56
+ };
57
+ },
58
+ [graphql_1.Kind.INTERFACE_TYPE_EXTENSION](node) {
59
+ return {
60
+ ...node,
61
+ directives: [
62
+ ...(node.directives || []),
63
+ {
64
+ kind: graphql_1.Kind.DIRECTIVE,
65
+ name: {
66
+ kind: graphql_1.Kind.NAME,
67
+ value: 'extends',
68
+ },
69
+ },
70
+ ],
71
+ kind: graphql_1.Kind.INTERFACE_TYPE_DEFINITION,
72
+ };
73
+ },
74
+ [graphql_1.Kind.UNION_TYPE_EXTENSION](node) {
75
+ return {
76
+ ...node,
77
+ directives: [
78
+ ...(node.directives || []),
79
+ {
80
+ kind: graphql_1.Kind.DIRECTIVE,
81
+ name: {
82
+ kind: graphql_1.Kind.NAME,
83
+ value: 'extends',
84
+ },
85
+ },
86
+ ],
87
+ kind: graphql_1.Kind.UNION_TYPE_DEFINITION,
88
+ };
89
+ },
90
+ [graphql_1.Kind.INPUT_OBJECT_TYPE_EXTENSION](node) {
91
+ return {
92
+ ...node,
93
+ directives: [
94
+ ...(node.directives || []),
95
+ {
96
+ kind: graphql_1.Kind.DIRECTIVE,
97
+ name: {
98
+ kind: graphql_1.Kind.NAME,
99
+ value: 'extends',
100
+ },
101
+ },
102
+ ],
103
+ kind: graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
104
+ };
105
+ },
106
+ [graphql_1.Kind.ENUM_TYPE_EXTENSION](node) {
107
+ return {
108
+ ...node,
109
+ directives: [
110
+ ...(node.directives || []),
111
+ {
112
+ kind: graphql_1.Kind.DIRECTIVE,
113
+ name: {
114
+ kind: graphql_1.Kind.NAME,
115
+ value: 'extends',
116
+ },
117
+ },
118
+ ],
119
+ kind: graphql_1.Kind.ENUM_TYPE_DEFINITION,
120
+ };
121
+ },
122
+ [graphql_1.Kind.SCALAR_TYPE_EXTENSION](node) {
123
+ return {
124
+ ...node,
125
+ directives: [
126
+ ...(node.directives || []),
127
+ {
128
+ kind: graphql_1.Kind.DIRECTIVE,
129
+ name: {
130
+ kind: graphql_1.Kind.NAME,
131
+ value: 'extends',
132
+ },
133
+ },
134
+ ],
135
+ kind: graphql_1.Kind.SCALAR_TYPE_DEFINITION,
136
+ };
137
+ },
138
+ });
139
+ }
40
140
  function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGETForQueries, operationHeaders, credentials, retry, timeout, source, schemaHeaders, federation = false, transportKind = 'http', }) {
41
141
  return (ctx) => {
42
142
  let schema$;
@@ -71,10 +171,9 @@ function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGETForQuer
71
171
  logger: ctx.logger,
72
172
  });
73
173
  }
74
- schema$ = (0, utils_2.mapMaybePromise)(source$, sdl => (0, graphql_1.buildSchema)(sdl, {
174
+ schema$ = (0, utils_2.mapMaybePromise)(source$, sdl => (0, graphql_1.buildASTSchema)(fixExtends((0, graphql_1.parse)(sdl, { noLocation: true })), {
75
175
  assumeValidSDL: true,
76
176
  assumeValid: true,
77
- noLocation: true,
78
177
  }));
79
178
  }
80
179
  else {
@@ -125,10 +224,13 @@ function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGETForQuer
125
224
  if (result.errors) {
126
225
  throw new AggregateError(result.errors.map(err => (0, utils_2.createGraphQLError)(err.message, err)), 'Introspection Query Failed');
127
226
  }
128
- return (0, graphql_1.buildSchema)(result?.data?._service?.sdl, {
227
+ if (!result.data?._service?.sdl) {
228
+ throw new Error('Federation subgraph does not provide SDL');
229
+ }
230
+ // Replace "extend" keyword with "@extends"
231
+ return (0, graphql_1.buildASTSchema)(fixExtends((0, graphql_1.parse)(result.data._service.sdl, { noLocation: true })), {
129
232
  assumeValidSDL: true,
130
233
  assumeValid: true,
131
- noLocation: true,
132
234
  });
133
235
  });
134
236
  });
@@ -1,6 +1,106 @@
1
- import { buildClientSchema, buildSchema, DirectiveLocation, getIntrospectionQuery, getNamedType, GraphQLDirective, GraphQLList, GraphQLNonNull, GraphQLScalarType, GraphQLSchema, GraphQLString, isObjectType, } from 'graphql';
1
+ import { buildASTSchema, buildClientSchema, DirectiveLocation, getIntrospectionQuery, getNamedType, GraphQLDirective, GraphQLList, GraphQLNonNull, GraphQLScalarType, GraphQLSchema, GraphQLString, isObjectType, Kind, parse, visit, } from 'graphql';
2
2
  import { isUrl, readFile } from '@graphql-mesh/utils';
3
3
  import { createGraphQLError, isValidPath, mapMaybePromise, } from '@graphql-tools/utils';
4
+ function fixExtends(node) {
5
+ return visit(node, {
6
+ [Kind.OBJECT_TYPE_EXTENSION](node) {
7
+ return {
8
+ ...node,
9
+ directives: [
10
+ ...(node.directives || []),
11
+ {
12
+ kind: Kind.DIRECTIVE,
13
+ name: {
14
+ kind: Kind.NAME,
15
+ value: 'extends',
16
+ },
17
+ },
18
+ ],
19
+ kind: Kind.OBJECT_TYPE_DEFINITION,
20
+ };
21
+ },
22
+ [Kind.INTERFACE_TYPE_EXTENSION](node) {
23
+ return {
24
+ ...node,
25
+ directives: [
26
+ ...(node.directives || []),
27
+ {
28
+ kind: Kind.DIRECTIVE,
29
+ name: {
30
+ kind: Kind.NAME,
31
+ value: 'extends',
32
+ },
33
+ },
34
+ ],
35
+ kind: Kind.INTERFACE_TYPE_DEFINITION,
36
+ };
37
+ },
38
+ [Kind.UNION_TYPE_EXTENSION](node) {
39
+ return {
40
+ ...node,
41
+ directives: [
42
+ ...(node.directives || []),
43
+ {
44
+ kind: Kind.DIRECTIVE,
45
+ name: {
46
+ kind: Kind.NAME,
47
+ value: 'extends',
48
+ },
49
+ },
50
+ ],
51
+ kind: Kind.UNION_TYPE_DEFINITION,
52
+ };
53
+ },
54
+ [Kind.INPUT_OBJECT_TYPE_EXTENSION](node) {
55
+ return {
56
+ ...node,
57
+ directives: [
58
+ ...(node.directives || []),
59
+ {
60
+ kind: Kind.DIRECTIVE,
61
+ name: {
62
+ kind: Kind.NAME,
63
+ value: 'extends',
64
+ },
65
+ },
66
+ ],
67
+ kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
68
+ };
69
+ },
70
+ [Kind.ENUM_TYPE_EXTENSION](node) {
71
+ return {
72
+ ...node,
73
+ directives: [
74
+ ...(node.directives || []),
75
+ {
76
+ kind: Kind.DIRECTIVE,
77
+ name: {
78
+ kind: Kind.NAME,
79
+ value: 'extends',
80
+ },
81
+ },
82
+ ],
83
+ kind: Kind.ENUM_TYPE_DEFINITION,
84
+ };
85
+ },
86
+ [Kind.SCALAR_TYPE_EXTENSION](node) {
87
+ return {
88
+ ...node,
89
+ directives: [
90
+ ...(node.directives || []),
91
+ {
92
+ kind: Kind.DIRECTIVE,
93
+ name: {
94
+ kind: Kind.NAME,
95
+ value: 'extends',
96
+ },
97
+ },
98
+ ],
99
+ kind: Kind.SCALAR_TYPE_DEFINITION,
100
+ };
101
+ },
102
+ });
103
+ }
4
104
  export function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGETForQueries, operationHeaders, credentials, retry, timeout, source, schemaHeaders, federation = false, transportKind = 'http', }) {
5
105
  return (ctx) => {
6
106
  let schema$;
@@ -35,10 +135,9 @@ export function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGET
35
135
  logger: ctx.logger,
36
136
  });
37
137
  }
38
- schema$ = mapMaybePromise(source$, sdl => buildSchema(sdl, {
138
+ schema$ = mapMaybePromise(source$, sdl => buildASTSchema(fixExtends(parse(sdl, { noLocation: true })), {
39
139
  assumeValidSDL: true,
40
140
  assumeValid: true,
41
- noLocation: true,
42
141
  }));
43
142
  }
44
143
  else {
@@ -89,10 +188,13 @@ export function loadGraphQLHTTPSubgraph(subgraphName, { endpoint, method, useGET
89
188
  if (result.errors) {
90
189
  throw new AggregateError(result.errors.map(err => createGraphQLError(err.message, err)), 'Introspection Query Failed');
91
190
  }
92
- return buildSchema(result?.data?._service?.sdl, {
191
+ if (!result.data?._service?.sdl) {
192
+ throw new Error('Federation subgraph does not provide SDL');
193
+ }
194
+ // Replace "extend" keyword with "@extends"
195
+ return buildASTSchema(fixExtends(parse(result.data._service.sdl, { noLocation: true })), {
93
196
  assumeValidSDL: true,
94
197
  assumeValid: true,
95
- noLocation: true,
96
198
  });
97
199
  });
98
200
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-mesh/compose-cli",
3
- "version": "1.2.11",
3
+ "version": "1.2.12",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@graphql-mesh/types": "^0.103.5",