@graphql-mesh/transform-federation 0.10.8-alpha-20230207124039-e1ab926b9 → 0.10.8
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 +68 -15
- package/esm/index.js +69 -16
- package/package.json +3 -3
- package/typings/index.d.cts +1 -1
- package/typings/index.d.ts +1 -1
package/cjs/index.js
CHANGED
|
@@ -2,11 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
|
-
const utils_1 = require("@graphql-mesh/utils");
|
|
6
|
-
const types_js_1 = require("@apollo/subgraph/dist/types.js");
|
|
7
|
-
const utils_2 = require("@graphql-tools/utils");
|
|
8
5
|
const lodash_set_1 = tslib_1.__importDefault(require("lodash.set"));
|
|
6
|
+
const types_js_1 = require("@apollo/subgraph/dist/types.js");
|
|
9
7
|
const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
|
|
8
|
+
const utils_1 = require("@graphql-mesh/utils");
|
|
9
|
+
const utils_2 = require("@graphql-tools/utils");
|
|
10
|
+
const federationDirectives = [
|
|
11
|
+
'extends',
|
|
12
|
+
'external',
|
|
13
|
+
'inaccessible',
|
|
14
|
+
'key',
|
|
15
|
+
'override',
|
|
16
|
+
'provides',
|
|
17
|
+
'requires',
|
|
18
|
+
'shareable',
|
|
19
|
+
'tag',
|
|
20
|
+
];
|
|
10
21
|
class FederationTransform {
|
|
11
22
|
constructor({ apiName, baseDir, config, importFn, }) {
|
|
12
23
|
this.noWrap = true;
|
|
@@ -154,19 +165,61 @@ class FederationTransform {
|
|
|
154
165
|
schemaWithUnionType.extensions.directives || {});
|
|
155
166
|
directivesObj.link = {
|
|
156
167
|
url: 'https://specs.apollo.dev/federation/v2.0',
|
|
157
|
-
import:
|
|
158
|
-
'@extends',
|
|
159
|
-
'@external',
|
|
160
|
-
'@inaccessible',
|
|
161
|
-
'@key',
|
|
162
|
-
'@override',
|
|
163
|
-
'@provides',
|
|
164
|
-
'@requires',
|
|
165
|
-
'@shareable',
|
|
166
|
-
'@tag',
|
|
167
|
-
],
|
|
168
|
+
import: federationDirectives.map(dirName => `@${dirName}`),
|
|
168
169
|
};
|
|
169
|
-
|
|
170
|
+
const existingDirectives = schemaWithUnionType.getDirectives();
|
|
171
|
+
const filteredDirectives = existingDirectives.filter(directive => federationDirectives.includes(directive.name));
|
|
172
|
+
if (existingDirectives.length === filteredDirectives.length) {
|
|
173
|
+
return schemaWithUnionType;
|
|
174
|
+
}
|
|
175
|
+
const filteredSchema = (0, utils_2.mapSchema)(schemaWithUnionType, {
|
|
176
|
+
[utils_2.MapperKind.OBJECT_TYPE]: type => {
|
|
177
|
+
var _a, _b;
|
|
178
|
+
return new graphql_1.GraphQLObjectType({
|
|
179
|
+
...type.toConfig(),
|
|
180
|
+
astNode: type.astNode && {
|
|
181
|
+
...type.astNode,
|
|
182
|
+
directives: (_a = type.astNode.directives) === null || _a === void 0 ? void 0 : _a.filter(directive => federationDirectives.includes(directive.name.value)),
|
|
183
|
+
},
|
|
184
|
+
extensions: {
|
|
185
|
+
...type.extensions,
|
|
186
|
+
directives: Object.fromEntries(Object.entries(((_b = type.extensions) === null || _b === void 0 ? void 0 : _b.directives) || {}).filter(([key]) => federationDirectives.includes(key))),
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
[utils_2.MapperKind.INTERFACE_TYPE]: type => {
|
|
191
|
+
var _a, _b;
|
|
192
|
+
return new graphql_1.GraphQLInterfaceType({
|
|
193
|
+
...type.toConfig(),
|
|
194
|
+
astNode: type.astNode && {
|
|
195
|
+
...type.astNode,
|
|
196
|
+
directives: (_a = type.astNode.directives) === null || _a === void 0 ? void 0 : _a.filter(directive => federationDirectives.includes(directive.name.value)),
|
|
197
|
+
},
|
|
198
|
+
extensions: {
|
|
199
|
+
...type.extensions,
|
|
200
|
+
directives: Object.fromEntries(Object.entries(((_b = type.extensions) === null || _b === void 0 ? void 0 : _b.directives) || {}).filter(([key]) => federationDirectives.includes(key))),
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
[utils_2.MapperKind.COMPOSITE_FIELD]: fieldConfig => {
|
|
205
|
+
var _a, _b;
|
|
206
|
+
return {
|
|
207
|
+
...fieldConfig,
|
|
208
|
+
astNode: fieldConfig.astNode && {
|
|
209
|
+
...fieldConfig.astNode,
|
|
210
|
+
directives: (_a = fieldConfig.astNode.directives) === null || _a === void 0 ? void 0 : _a.filter(directive => federationDirectives.includes(directive.name.value)),
|
|
211
|
+
},
|
|
212
|
+
extensions: {
|
|
213
|
+
...fieldConfig.extensions,
|
|
214
|
+
directives: Object.fromEntries(Object.entries(((_b = fieldConfig.extensions) === null || _b === void 0 ? void 0 : _b.directives) || {}).filter(([key]) => federationDirectives.includes(key))),
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
return new graphql_1.GraphQLSchema({
|
|
220
|
+
...filteredSchema.toConfig(),
|
|
221
|
+
directives: filteredDirectives,
|
|
222
|
+
});
|
|
170
223
|
}
|
|
171
224
|
}
|
|
172
225
|
exports.default = FederationTransform;
|
package/esm/index.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { GraphQLObjectType, GraphQLUnionType, isObjectType } from 'graphql';
|
|
2
|
-
import { loadFromModuleExportExpression } from '@graphql-mesh/utils';
|
|
3
|
-
import { entitiesField, EntityType, serviceField } from '@apollo/subgraph/dist/types.js';
|
|
4
|
-
import { mapSchema, MapperKind, printSchemaWithDirectives } from '@graphql-tools/utils';
|
|
1
|
+
import { GraphQLInterfaceType, GraphQLObjectType, GraphQLSchema, GraphQLUnionType, isObjectType, } from 'graphql';
|
|
5
2
|
import set from 'lodash.set';
|
|
3
|
+
import { entitiesField, EntityType, serviceField } from '@apollo/subgraph/dist/types.js';
|
|
6
4
|
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
5
|
+
import { loadFromModuleExportExpression } from '@graphql-mesh/utils';
|
|
6
|
+
import { MapperKind, mapSchema, printSchemaWithDirectives } from '@graphql-tools/utils';
|
|
7
|
+
const federationDirectives = [
|
|
8
|
+
'extends',
|
|
9
|
+
'external',
|
|
10
|
+
'inaccessible',
|
|
11
|
+
'key',
|
|
12
|
+
'override',
|
|
13
|
+
'provides',
|
|
14
|
+
'requires',
|
|
15
|
+
'shareable',
|
|
16
|
+
'tag',
|
|
17
|
+
];
|
|
7
18
|
export default class FederationTransform {
|
|
8
19
|
constructor({ apiName, baseDir, config, importFn, }) {
|
|
9
20
|
this.noWrap = true;
|
|
@@ -151,18 +162,60 @@ export default class FederationTransform {
|
|
|
151
162
|
schemaWithUnionType.extensions.directives || {});
|
|
152
163
|
directivesObj.link = {
|
|
153
164
|
url: 'https://specs.apollo.dev/federation/v2.0',
|
|
154
|
-
import:
|
|
155
|
-
'@extends',
|
|
156
|
-
'@external',
|
|
157
|
-
'@inaccessible',
|
|
158
|
-
'@key',
|
|
159
|
-
'@override',
|
|
160
|
-
'@provides',
|
|
161
|
-
'@requires',
|
|
162
|
-
'@shareable',
|
|
163
|
-
'@tag',
|
|
164
|
-
],
|
|
165
|
+
import: federationDirectives.map(dirName => `@${dirName}`),
|
|
165
166
|
};
|
|
166
|
-
|
|
167
|
+
const existingDirectives = schemaWithUnionType.getDirectives();
|
|
168
|
+
const filteredDirectives = existingDirectives.filter(directive => federationDirectives.includes(directive.name));
|
|
169
|
+
if (existingDirectives.length === filteredDirectives.length) {
|
|
170
|
+
return schemaWithUnionType;
|
|
171
|
+
}
|
|
172
|
+
const filteredSchema = mapSchema(schemaWithUnionType, {
|
|
173
|
+
[MapperKind.OBJECT_TYPE]: type => {
|
|
174
|
+
var _a, _b;
|
|
175
|
+
return new GraphQLObjectType({
|
|
176
|
+
...type.toConfig(),
|
|
177
|
+
astNode: type.astNode && {
|
|
178
|
+
...type.astNode,
|
|
179
|
+
directives: (_a = type.astNode.directives) === null || _a === void 0 ? void 0 : _a.filter(directive => federationDirectives.includes(directive.name.value)),
|
|
180
|
+
},
|
|
181
|
+
extensions: {
|
|
182
|
+
...type.extensions,
|
|
183
|
+
directives: Object.fromEntries(Object.entries(((_b = type.extensions) === null || _b === void 0 ? void 0 : _b.directives) || {}).filter(([key]) => federationDirectives.includes(key))),
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
[MapperKind.INTERFACE_TYPE]: type => {
|
|
188
|
+
var _a, _b;
|
|
189
|
+
return new GraphQLInterfaceType({
|
|
190
|
+
...type.toConfig(),
|
|
191
|
+
astNode: type.astNode && {
|
|
192
|
+
...type.astNode,
|
|
193
|
+
directives: (_a = type.astNode.directives) === null || _a === void 0 ? void 0 : _a.filter(directive => federationDirectives.includes(directive.name.value)),
|
|
194
|
+
},
|
|
195
|
+
extensions: {
|
|
196
|
+
...type.extensions,
|
|
197
|
+
directives: Object.fromEntries(Object.entries(((_b = type.extensions) === null || _b === void 0 ? void 0 : _b.directives) || {}).filter(([key]) => federationDirectives.includes(key))),
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
[MapperKind.COMPOSITE_FIELD]: fieldConfig => {
|
|
202
|
+
var _a, _b;
|
|
203
|
+
return {
|
|
204
|
+
...fieldConfig,
|
|
205
|
+
astNode: fieldConfig.astNode && {
|
|
206
|
+
...fieldConfig.astNode,
|
|
207
|
+
directives: (_a = fieldConfig.astNode.directives) === null || _a === void 0 ? void 0 : _a.filter(directive => federationDirectives.includes(directive.name.value)),
|
|
208
|
+
},
|
|
209
|
+
extensions: {
|
|
210
|
+
...fieldConfig.extensions,
|
|
211
|
+
directives: Object.fromEntries(Object.entries(((_b = fieldConfig.extensions) === null || _b === void 0 ? void 0 : _b.directives) || {}).filter(([key]) => federationDirectives.includes(key))),
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
return new GraphQLSchema({
|
|
217
|
+
...filteredSchema.toConfig(),
|
|
218
|
+
directives: filteredDirectives,
|
|
219
|
+
});
|
|
167
220
|
}
|
|
168
221
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/transform-federation",
|
|
3
|
-
"version": "0.10.8
|
|
3
|
+
"version": "0.10.8",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "*"
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@apollo/subgraph": "2.3.0",
|
|
10
10
|
"@graphql-mesh/string-interpolation": "0.4.2",
|
|
11
|
-
"@graphql-mesh/types": "0.
|
|
12
|
-
"@graphql-mesh/utils": "0.43.7
|
|
11
|
+
"@graphql-mesh/types": "0.90.0",
|
|
12
|
+
"@graphql-mesh/utils": "0.43.7",
|
|
13
13
|
"@graphql-tools/delegate": "9.0.24",
|
|
14
14
|
"@graphql-tools/stitching-directives": "2.3.27",
|
|
15
15
|
"@graphql-tools/utils": "9.1.4",
|
package/typings/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { MeshTransform,
|
|
2
|
+
import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
|
|
3
3
|
import { SubschemaConfig } from '@graphql-tools/delegate';
|
|
4
4
|
export default class FederationTransform implements MeshTransform {
|
|
5
5
|
private apiName;
|
package/typings/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { MeshTransform,
|
|
2
|
+
import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
|
|
3
3
|
import { SubschemaConfig } from '@graphql-tools/delegate';
|
|
4
4
|
export default class FederationTransform implements MeshTransform {
|
|
5
5
|
private apiName;
|