@@ -45,6 +45,7 @@ import {
4545 TypeDefinitionNode ,
4646 TypeExtensionNode ,
4747 UnionTypeDefinitionNode ,
48+ ValueNode ,
4849} from 'graphql' ;
4950import { astFromType } from './astFromType.js' ;
5051import { 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