Skip to content

Commit

Permalink
fix(utils): print specifiedBy directive correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Aug 31, 2021
1 parent be6fdb8 commit 3f6ec05
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-beds-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': patch
---

fix(utils): print specifiedBy directive correctly
5 changes: 4 additions & 1 deletion packages/utils/src/print-schema-with-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
};
Expand Down
6 changes: 5 additions & 1 deletion packages/utils/tests/print-schema-with-directives.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 3f6ec05

Please sign in to comment.