Skip to content

Commit

Permalink
Make stripFederationFromSupergraph less strict (#19)
Browse files Browse the repository at this point in the history
Remove only federation-related directives
  • Loading branch information
kamilkisiela authored Nov 23, 2023
1 parent a5e5d40 commit e0ef0bb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/asd-asd-asd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@theguild/federation-composition': patch
---

Make `stripFederationFromSupergraph` less strict and remove only Federation directives
46 changes: 39 additions & 7 deletions src/graphql/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,51 @@
import { DefinitionNode, DirectiveDefinitionNode, DocumentNode, Kind, visit } from 'graphql';
import {
DefinitionNode,
DirectiveDefinitionNode,
DocumentNode,
Kind,
specifiedDirectives,
visit,
} from 'graphql';

export function isDirectiveDefinition(node: DefinitionNode): node is DirectiveDefinitionNode {
return node.kind === Kind.DIRECTIVE_DEFINITION;
}

export function stripFederationFromSupergraph(supergraph: DocumentNode) {
function remove() {
return null;
function removeDirective(node: {
name: {
value: string;
};
}) {
const directiveName = node.name.value;
const isSpecifiedDirective = specifiedDirectives.some(d => d.name === directiveName);
if (!isSpecifiedDirective) {
const isFederationDirective =
directiveName === 'link' ||
directiveName === 'inaccessible' ||
directiveName === 'tag' ||
directiveName === 'join__graph' ||
directiveName === 'join__type' ||
directiveName === 'join__implements' ||
directiveName === 'join__unionMember' ||
directiveName === 'join__enumValue' ||
directiveName === 'join__field';

if (isFederationDirective) {
return null;
}
}
}

return visit(supergraph, {
DirectiveDefinition: remove,
Directive: remove,
SchemaDefinition: remove,
SchemaExtension: remove,
DirectiveDefinition: removeDirective,
Directive: removeDirective,
SchemaDefinition() {
return null;
},
SchemaExtension() {
return null;
},
EnumTypeDefinition: node => {
if (
node.name.value === 'core__Purpose' ||
Expand Down

0 comments on commit e0ef0bb

Please sign in to comment.