@@ -7,8 +7,8 @@ import type {
7
7
DirectiveNode ,
8
8
FieldNode ,
9
9
FragmentDefinitionNode ,
10
- ObjectValueNode ,
11
10
SelectionSetNode ,
11
+ ValueNode ,
12
12
} from '../../language/ast.js' ;
13
13
import { Kind } from '../../language/kinds.js' ;
14
14
import { print } from '../../language/printer.js' ;
@@ -592,7 +592,7 @@ function findConflict(
592
592
}
593
593
594
594
// Two field calls must have the same arguments.
595
- if ( stringifyArguments ( node1 ) !== stringifyArguments ( node2 ) ) {
595
+ if ( ! sameArguments ( node1 , node2 ) ) {
596
596
return [
597
597
[ responseName , 'they have differing arguments' ] ,
598
598
[ node1 ] ,
@@ -649,19 +649,38 @@ function findConflict(
649
649
}
650
650
}
651
651
652
- function stringifyArguments ( fieldNode : FieldNode | DirectiveNode ) : string {
653
- // FIXME https://github.com/graphql/graphql-js/issues/2203
654
- const args = /* c8 ignore next */ fieldNode . arguments ?? [ ] ;
655
-
656
- const inputObjectWithArgs : ObjectValueNode = {
657
- kind : Kind . OBJECT ,
658
- fields : args . map ( ( argNode ) => ( {
659
- kind : Kind . OBJECT_FIELD ,
660
- name : argNode . name ,
661
- value : argNode . value ,
662
- } ) ) ,
663
- } ;
664
- return print ( sortValueNode ( inputObjectWithArgs ) ) ;
652
+ function sameArguments (
653
+ node1 : FieldNode | DirectiveNode ,
654
+ node2 : FieldNode | DirectiveNode ,
655
+ ) : boolean {
656
+ const args1 = node1 . arguments ;
657
+ const args2 = node2 . arguments ;
658
+
659
+ if ( args1 === undefined || args1 . length === 0 ) {
660
+ return args2 === undefined || args2 . length === 0 ;
661
+ }
662
+ if ( args2 === undefined || args2 . length === 0 ) {
663
+ return false ;
664
+ }
665
+
666
+ if ( args1 . length !== args2 . length ) {
667
+ return false ;
668
+ }
669
+
670
+ const values2 = new Map ( args2 . map ( ( { name, value } ) => [ name . value , value ] ) ) ;
671
+ return args1 . every ( ( arg1 ) => {
672
+ const value1 = arg1 . value ;
673
+ const value2 = values2 . get ( arg1 . name . value ) ;
674
+ if ( value2 === undefined ) {
675
+ return false ;
676
+ }
677
+
678
+ return stringifyValue ( value1 ) === stringifyValue ( value2 ) ;
679
+ } ) ;
680
+ }
681
+
682
+ function stringifyValue ( value : ValueNode ) : string | null {
683
+ return print ( sortValueNode ( value ) ) ;
665
684
}
666
685
667
686
function getStreamDirective (
@@ -681,7 +700,7 @@ function sameStreams(
681
700
return true ;
682
701
} else if ( stream1 && stream2 ) {
683
702
// check if both fields have equivalent streams
684
- return stringifyArguments ( stream1 ) === stringifyArguments ( stream2 ) ;
703
+ return sameArguments ( stream1 , stream2 ) ;
685
704
}
686
705
// fields have a mix of stream and no stream
687
706
return false ;
0 commit comments