From 50609df81998a3878a58df2b5c52c9368676681b Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 31 Aug 2021 17:46:04 +0300 Subject: [PATCH] fix(utils): print specifiedBy directive correctly --- .changeset/rare-beds-report.md | 5 +++++ packages/utils/src/print-schema-with-directives.ts | 5 ++++- packages/utils/tests/print-schema-with-directives.spec.ts | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .changeset/rare-beds-report.md diff --git a/.changeset/rare-beds-report.md b/.changeset/rare-beds-report.md new file mode 100644 index 00000000000..dd8b40126c6 --- /dev/null +++ b/.changeset/rare-beds-report.md @@ -0,0 +1,5 @@ +--- +'@graphql-tools/utils': patch +--- + +fix(utils): print specifiedBy directive correctly diff --git a/packages/utils/src/print-schema-with-directives.ts b/packages/utils/src/print-schema-with-directives.ts index bca3ab371bb..e35a120b182 100644 --- a/packages/utils/src/print-schema-with-directives.ts +++ b/packages/utils/src/print-schema-with-directives.ts @@ -471,7 +471,10 @@ export function astFromScalarType( ? makeDirectiveNodes(schema, directivesInExtensions) : (type.astNode?.directives as DirectiveNode[]) || []; - if ('specifiedBy' in type && !directives.some(directiveNode => directiveNode.name.value === 'specifiedBy')) { + if ( + (type as any)['specifiedByUrl'] && + !directives.some(directiveNode => directiveNode.name.value === 'specifiedBy') + ) { const specifiedByArgs = { url: (type as any)['specifiedByUrl'], }; diff --git a/packages/utils/tests/print-schema-with-directives.spec.ts b/packages/utils/tests/print-schema-with-directives.spec.ts index 4108123390b..f8439208ac1 100644 --- a/packages/utils/tests/print-schema-with-directives.spec.ts +++ b/packages/utils/tests/print-schema-with-directives.spec.ts @@ -212,7 +212,11 @@ describe('printSchemaWithDirectives', () => { const output = printSchemaWithDirectives(schema); - expect(output).toContain('scalar JSON'); + if ('specifiedByUrl' in GraphQLJSON) { + expect(output).toContain(`scalar JSON @specifiedBy(url: "${(GraphQLJSON as any).specifiedByUrl}")`); + } else { + expect(output).toContain('scalar JSON'); + } expect(output).toContain('type Other'); expect(output).toContain('type TestType'); expect(output).toContain('type Query');