@graphql-mesh/transform-federation 0.11.3-alpha-20230214033834-6fa83ce80 → 0.11.4

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.
Files changed (3) hide show
  1. package/cjs/index.js +18 -11
  2. package/esm/index.js +19 -12
  3. package/package.json +3 -3
package/cjs/index.js CHANGED
@@ -8,15 +8,18 @@ const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
8
8
  const utils_1 = require("@graphql-mesh/utils");
9
9
  const utils_2 = require("@graphql-tools/utils");
10
10
  const federationDirectives = [
11
+ 'link',
12
+ 'key',
13
+ 'interfaceObject',
11
14
  'extends',
12
- 'external',
15
+ 'shareable',
13
16
  'inaccessible',
14
- 'key',
15
17
  'override',
18
+ 'external',
16
19
  'provides',
17
20
  'requires',
18
- 'shareable',
19
21
  'tag',
22
+ 'composeDirective',
20
23
  ];
21
24
  class FederationTransform {
22
25
  constructor({ apiName, baseDir, config, importFn, }) {
@@ -163,16 +166,24 @@ class FederationTransform {
163
166
  schemaWithUnionType.extensions = schemaWithUnionType.extensions || {};
164
167
  const directivesObj = (schemaWithUnionType.extensions.directives =
165
168
  schemaWithUnionType.extensions.directives || {});
169
+ const existingDirectives = schemaWithUnionType.getDirectives();
170
+ const filteredDirectives = existingDirectives.filter(directive => federationDirectives.includes(directive.name));
166
171
  directivesObj.link = {
167
172
  url: 'https://specs.apollo.dev/federation/' + (this.config.version || 'v2.0'),
168
- import: federationDirectives.map(dirName => `@${dirName}`),
173
+ import: filteredDirectives
174
+ .filter(({ name }) => name !== 'link')
175
+ .map(dirName => `@${dirName.name}`),
169
176
  };
170
- const existingDirectives = schemaWithUnionType.getDirectives();
171
- const filteredDirectives = existingDirectives.filter(directive => federationDirectives.includes(directive.name));
172
177
  if (existingDirectives.length === filteredDirectives.length) {
173
178
  return schemaWithUnionType;
174
179
  }
175
- const filteredSchema = (0, utils_2.mapSchema)(schemaWithUnionType, {
180
+ return (0, utils_2.mapSchema)(schemaWithUnionType, {
181
+ [utils_2.MapperKind.DIRECTIVE]: directive => {
182
+ if (federationDirectives.includes(directive.name)) {
183
+ return directive;
184
+ }
185
+ return null;
186
+ },
176
187
  [utils_2.MapperKind.OBJECT_TYPE]: type => {
177
188
  var _a, _b;
178
189
  return new graphql_1.GraphQLObjectType({
@@ -216,10 +227,6 @@ class FederationTransform {
216
227
  };
217
228
  },
218
229
  });
219
- return new graphql_1.GraphQLSchema({
220
- ...filteredSchema.toConfig(),
221
- directives: filteredDirectives,
222
- });
223
230
  }
224
231
  }
225
232
  exports.default = FederationTransform;
package/esm/index.js CHANGED
@@ -1,19 +1,22 @@
1
- import { GraphQLInterfaceType, GraphQLObjectType, GraphQLSchema, GraphQLUnionType, isObjectType, } from 'graphql';
1
+ import { GraphQLInterfaceType, GraphQLObjectType, GraphQLUnionType, isObjectType, } from 'graphql';
2
2
  import set from 'lodash.set';
3
3
  import { entitiesField, EntityType, serviceField } from '@apollo/subgraph/dist/types.js';
4
4
  import { stringInterpolator } from '@graphql-mesh/string-interpolation';
5
5
  import { loadFromModuleExportExpression } from '@graphql-mesh/utils';
6
6
  import { MapperKind, mapSchema, printSchemaWithDirectives } from '@graphql-tools/utils';
7
7
  const federationDirectives = [
8
+ 'link',
9
+ 'key',
10
+ 'interfaceObject',
8
11
  'extends',
9
- 'external',
12
+ 'shareable',
10
13
  'inaccessible',
11
- 'key',
12
14
  'override',
15
+ 'external',
13
16
  'provides',
14
17
  'requires',
15
- 'shareable',
16
18
  'tag',
19
+ 'composeDirective',
17
20
  ];
18
21
  export default class FederationTransform {
19
22
  constructor({ apiName, baseDir, config, importFn, }) {
@@ -160,16 +163,24 @@ export default class FederationTransform {
160
163
  schemaWithUnionType.extensions = schemaWithUnionType.extensions || {};
161
164
  const directivesObj = (schemaWithUnionType.extensions.directives =
162
165
  schemaWithUnionType.extensions.directives || {});
166
+ const existingDirectives = schemaWithUnionType.getDirectives();
167
+ const filteredDirectives = existingDirectives.filter(directive => federationDirectives.includes(directive.name));
163
168
  directivesObj.link = {
164
169
  url: 'https://specs.apollo.dev/federation/' + (this.config.version || 'v2.0'),
165
- import: federationDirectives.map(dirName => `@${dirName}`),
170
+ import: filteredDirectives
171
+ .filter(({ name }) => name !== 'link')
172
+ .map(dirName => `@${dirName.name}`),
166
173
  };
167
- const existingDirectives = schemaWithUnionType.getDirectives();
168
- const filteredDirectives = existingDirectives.filter(directive => federationDirectives.includes(directive.name));
169
174
  if (existingDirectives.length === filteredDirectives.length) {
170
175
  return schemaWithUnionType;
171
176
  }
172
- const filteredSchema = mapSchema(schemaWithUnionType, {
177
+ return mapSchema(schemaWithUnionType, {
178
+ [MapperKind.DIRECTIVE]: directive => {
179
+ if (federationDirectives.includes(directive.name)) {
180
+ return directive;
181
+ }
182
+ return null;
183
+ },
173
184
  [MapperKind.OBJECT_TYPE]: type => {
174
185
  var _a, _b;
175
186
  return new GraphQLObjectType({
@@ -213,9 +224,5 @@ export default class FederationTransform {
213
224
  };
214
225
  },
215
226
  });
216
- return new GraphQLSchema({
217
- ...filteredSchema.toConfig(),
218
- directives: filteredDirectives,
219
- });
220
227
  }
221
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-mesh/transform-federation",
3
- "version": "0.11.3-alpha-20230214033834-6fa83ce80",
3
+ "version": "0.11.4",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "*"
@@ -8,8 +8,8 @@
8
8
  "dependencies": {
9
9
  "@apollo/subgraph": "2.3.2",
10
10
  "@graphql-mesh/string-interpolation": "0.4.2",
11
- "@graphql-mesh/types": "0.91.3-alpha-20230214033834-6fa83ce80",
12
- "@graphql-mesh/utils": "0.43.11-alpha-20230214033834-6fa83ce80",
11
+ "@graphql-mesh/types": "0.91.3",
12
+ "@graphql-mesh/utils": "0.43.11",
13
13
  "@graphql-tools/delegate": "9.0.27",
14
14
  "@graphql-tools/stitching-directives": "2.3.30",
15
15
  "@graphql-tools/utils": "9.2.1",