@@ -4,7 +4,6 @@ import type { Maybe } from '../../jsutils/Maybe.js';
4
4
import { GraphQLError } from '../../error/GraphQLError.js' ;
5
5
6
6
import type {
7
- ArgumentNode ,
8
7
DirectiveNode ,
9
8
FieldNode ,
10
9
FragmentDefinitionNode ,
@@ -593,7 +592,7 @@ function findConflict(
593
592
}
594
593
595
594
// Two field calls must have the same arguments.
596
- if ( ! sameArguments ( node1 . arguments , node2 . arguments ) ) {
595
+ if ( ! sameArguments ( node1 , node2 ) ) {
597
596
return [
598
597
[ responseName , 'they have differing arguments' ] ,
599
598
[ node1 ] ,
@@ -651,24 +650,36 @@ function findConflict(
651
650
}
652
651
653
652
function sameArguments (
654
- arguments1 : ReadonlyArray < ArgumentNode > = [ ] ,
655
- arguments2 : ReadonlyArray < ArgumentNode > = [ ] ,
653
+ node1 : FieldNode | DirectiveNode ,
654
+ node2 : FieldNode | DirectiveNode ,
656
655
) : boolean {
657
- if ( arguments1 ?. length !== arguments2 ?. length ) {
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 ) {
658
663
return false ;
659
664
}
660
- return arguments1 . every ( ( argument1 ) => {
661
- const argument2 = arguments2 . find (
662
- ( argument ) => argument . name . value === argument1 . name . value ,
663
- ) ;
664
- if ( ! argument2 ) {
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 ) {
665
675
return false ;
666
676
}
667
- return stringifyValue ( argument1 . value ) === stringifyValue ( argument2 . value ) ;
677
+
678
+ return stringifyValue ( value1 ) === stringifyValue ( value2 ) ;
668
679
} ) ;
669
680
}
670
681
671
- function stringifyValue ( value : ValueNode ) : string {
682
+ function stringifyValue ( value : ValueNode ) : string | null {
672
683
return print ( sortValueNode ( value ) ) ;
673
684
}
674
685
@@ -689,7 +700,7 @@ function sameStreams(
689
700
return true ;
690
701
} else if ( stream1 && stream2 ) {
691
702
// check if both fields have equivalent streams
692
- return sameArguments ( stream1 . arguments , stream2 . arguments ) ;
703
+ return sameArguments ( stream1 , stream2 ) ;
693
704
}
694
705
// fields have a mix of stream and no stream
695
706
return false ;
0 commit comments