Skip to content

Commit 6291e14

Browse files
committed
fix(print-schema-with-directives): add all args to AST even if they don't exist in the def
1 parent 1d826c8 commit 6291e14

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed

.changeset/ninety-plums-explode.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+
Add all args from extensions to the AST even if they don't exist in the directive def

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

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
TypeDefinitionNode,
4646
TypeExtensionNode,
4747
UnionTypeDefinitionNode,
48+
ValueNode,
4849
} from 'graphql';
4950
import { astFromType } from './astFromType.js';
5051
import { astFromValue } from './astFromValue.js';
@@ -519,38 +520,27 @@ export function makeDirectiveNode(
519520
): DirectiveNode {
520521
const directiveArguments: Array<ArgumentNode> = [];
521522

522-
if (directive != null) {
523-
for (const arg of directive.args) {
524-
const argName = arg.name;
525-
const argValue = args?.[argName];
526-
if (argValue !== undefined) {
527-
const value = astFromValue(argValue, arg.type);
528-
if (value) {
529-
directiveArguments.push({
530-
kind: Kind.ARGUMENT,
531-
name: {
532-
kind: Kind.NAME,
533-
value: argName,
534-
},
535-
value,
536-
});
537-
}
523+
for (const argName in args) {
524+
const argValue = args[argName];
525+
let value: Maybe<ValueNode>;
526+
if (directive != null) {
527+
const arg = directive.args.find(arg => arg.name === argName);
528+
if (arg) {
529+
value = astFromValue(argValue, arg.type);
538530
}
539531
}
540-
} else {
541-
for (const argName in args) {
542-
const argValue = args[argName];
543-
const value = astFromValueUntyped(argValue);
544-
if (value) {
545-
directiveArguments.push({
546-
kind: Kind.ARGUMENT,
547-
name: {
548-
kind: Kind.NAME,
549-
value: argName,
550-
},
551-
value,
552-
});
553-
}
532+
if (value == null) {
533+
value = astFromValueUntyped(argValue);
534+
}
535+
if (value != null) {
536+
directiveArguments.push({
537+
kind: Kind.ARGUMENT,
538+
name: {
539+
kind: Kind.NAME,
540+
value: argName,
541+
},
542+
value,
543+
});
554544
}
555545
}
556546

0 commit comments

Comments
 (0)