Skip to content

Commit

Permalink
fix(print-schema-with-directives): add all args to AST even if they d…
Browse files Browse the repository at this point in the history
…on't exist in the def
  • Loading branch information
ardatan committed Aug 12, 2024
1 parent 1d826c8 commit 6291e14
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-plums-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': patch
---

Add all args from extensions to the AST even if they don't exist in the directive def
50 changes: 20 additions & 30 deletions packages/utils/src/print-schema-with-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
TypeDefinitionNode,
TypeExtensionNode,
UnionTypeDefinitionNode,
ValueNode,
} from 'graphql';
import { astFromType } from './astFromType.js';
import { astFromValue } from './astFromValue.js';
Expand Down Expand Up @@ -519,38 +520,27 @@ export function makeDirectiveNode(
): DirectiveNode {
const directiveArguments: Array<ArgumentNode> = [];

if (directive != null) {
for (const arg of directive.args) {
const argName = arg.name;
const argValue = args?.[argName];
if (argValue !== undefined) {
const value = astFromValue(argValue, arg.type);
if (value) {
directiveArguments.push({
kind: Kind.ARGUMENT,
name: {
kind: Kind.NAME,
value: argName,
},
value,
});
}
for (const argName in args) {
const argValue = args[argName];
let value: Maybe<ValueNode>;
if (directive != null) {
const arg = directive.args.find(arg => arg.name === argName);
if (arg) {
value = astFromValue(argValue, arg.type);
}
}
} else {
for (const argName in args) {
const argValue = args[argName];
const value = astFromValueUntyped(argValue);
if (value) {
directiveArguments.push({
kind: Kind.ARGUMENT,
name: {
kind: Kind.NAME,
value: argName,
},
value,
});
}
if (value == null) {
value = astFromValueUntyped(argValue);
}
if (value != null) {
directiveArguments.push({
kind: Kind.ARGUMENT,
name: {
kind: Kind.NAME,
value: argName,
},
value,
});
}
}

Expand Down

0 comments on commit 6291e14

Please sign in to comment.