@@ -52,27 +52,32 @@ export function NoFragmentCycles(context: ValidationContext): any {
52
52
// the graph to find all possible cycles.
53
53
function detectCycleRecursive ( fragmentName ) {
54
54
var spreadNodes = spreadsInFragment [ fragmentName ] ;
55
- for ( var i = 0 ; i < spreadNodes . length ; ++ i ) {
56
- var spreadNode = spreadNodes [ i ] ;
57
- if ( knownToLeadToCycle . has ( spreadNode ) ) {
58
- continue ;
59
- }
60
- if ( spreadNode . name . value === initialName ) {
61
- var cyclePath = spreadPath . concat ( spreadNode ) ;
62
- cyclePath . forEach ( spread => knownToLeadToCycle . add ( spread ) ) ;
63
- errors . push ( new GraphQLError (
64
- cycleErrorMessage ( initialName , spreadPath . map ( s => s . name . value ) ) ,
65
- cyclePath
66
- ) ) ;
67
- continue ;
68
- }
69
- if ( spreadPath . some ( spread => spread === spreadNode ) ) {
70
- continue ;
71
- }
55
+ if ( spreadNodes ) {
56
+ for ( var i = 0 ; i < spreadNodes . length ; ++ i ) {
57
+ var spreadNode = spreadNodes [ i ] ;
58
+ if ( knownToLeadToCycle . has ( spreadNode ) ) {
59
+ continue ;
60
+ }
61
+ if ( spreadNode . name . value === initialName ) {
62
+ var cyclePath = spreadPath . concat ( spreadNode ) ;
63
+ cyclePath . forEach ( spread => knownToLeadToCycle . add ( spread ) ) ;
64
+ errors . push ( new GraphQLError (
65
+ cycleErrorMessage (
66
+ initialName ,
67
+ spreadPath . map ( s => s . name . value )
68
+ ) ,
69
+ cyclePath
70
+ ) ) ;
71
+ continue ;
72
+ }
73
+ if ( spreadPath . some ( spread => spread === spreadNode ) ) {
74
+ continue ;
75
+ }
72
76
73
- spreadPath . push ( spreadNode ) ;
74
- detectCycleRecursive ( spreadNode . name . value ) ;
75
- spreadPath . pop ( ) ;
77
+ spreadPath . push ( spreadNode ) ;
78
+ detectCycleRecursive ( spreadNode . name . value ) ;
79
+ spreadPath . pop ( ) ;
80
+ }
76
81
}
77
82
}
78
83
0 commit comments