Skip to content

Commit

Permalink
fix(federation): do not import @link from spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Feb 14, 2023
1 parent db11a7d commit 696f9c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-comics-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/transform-federation': patch
---

Do not import @link from the spec
11 changes: 7 additions & 4 deletions packages/transforms/federation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,19 @@ export default class FederationTransform implements MeshTransform {
schemaWithUnionType.extensions = schemaWithUnionType.extensions || {};
const directivesObj: any = ((schemaWithUnionType.extensions as any).directives =
schemaWithUnionType.extensions.directives || {});
directivesObj.link = {
url: 'https://specs.apollo.dev/federation/' + (this.config.version || 'v2.0'),
import: federationDirectives.filter(name => name !== 'link').map(dirName => `@${dirName}`),
};

const existingDirectives = schemaWithUnionType.getDirectives();
const filteredDirectives = existingDirectives.filter(directive =>
federationDirectives.includes(directive.name),
);

directivesObj.link = {
url: 'https://specs.apollo.dev/federation/' + (this.config.version || 'v2.0'),
import: filteredDirectives
.filter(({ name }) => name !== 'link')
.map(dirName => `@${dirName.name}`),
};

if (existingDirectives.length === filteredDirectives.length) {
return schemaWithUnionType;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/transforms/federation/test/federation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('transform-federation', () => {
schema,
});
expect(printSchemaWithDirectives(transformedSchema)).toMatchInlineSnapshot(`
"schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@extends", "@external", "@inaccessible", "@key", "@override", "@provides", "@requires", "@shareable", "@tag"]) {
"schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: []) {
query: Query
}
Expand Down

0 comments on commit 696f9c7

Please sign in to comment.