Skip to content

Commit 3f6ec05

Browse files
committed
fix(utils): print specifiedBy directive correctly
1 parent be6fdb8 commit 3f6ec05

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.changeset/rare-beds-report.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/utils': patch
3+
---
4+
5+
fix(utils): print specifiedBy directive correctly

packages/utils/src/print-schema-with-directives.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,10 @@ export function astFromScalarType(
471471
? makeDirectiveNodes(schema, directivesInExtensions)
472472
: (type.astNode?.directives as DirectiveNode[]) || [];
473473

474-
if ('specifiedBy' in type && !directives.some(directiveNode => directiveNode.name.value === 'specifiedBy')) {
474+
if (
475+
(type as any)['specifiedByUrl'] &&
476+
!directives.some(directiveNode => directiveNode.name.value === 'specifiedBy')
477+
) {
475478
const specifiedByArgs = {
476479
url: (type as any)['specifiedByUrl'],
477480
};

packages/utils/tests/print-schema-with-directives.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ describe('printSchemaWithDirectives', () => {
212212

213213
const output = printSchemaWithDirectives(schema);
214214

215-
expect(output).toContain('scalar JSON');
215+
if ('specifiedByUrl' in GraphQLJSON) {
216+
expect(output).toContain(`scalar JSON @specifiedBy(url: ${(GraphQLJSON as any).specifiedByUrl})`);
217+
} else {
218+
expect(output).toContain('scalar JSON');
219+
}
216220
expect(output).toContain('type Other');
217221
expect(output).toContain('type TestType');
218222
expect(output).toContain('type Query');

0 commit comments

Comments
 (0)