Skip to content

Commit bb27894

Browse files
committed
Validation: context.getFragmentSpreads now accepts selectionSet rather than fragment AST node
Commit: 688a1ee20db01ca80fdec2189298078380d81ed6 [688a1ee] Parents: cf9be87422 Author: Lee Byron <[email protected]> Date: 10 May 2016 at 9:54:10 AM SGT
1 parent 6b9ac5e commit bb27894

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ func NoFragmentCyclesRule(context *ValidationContext) *ValidationRuleInstance {
858858
}
859859
visitedFrags[fragmentName] = true
860860

861-
spreadNodes := context.FragmentSpreads(fragment)
861+
spreadNodes := context.FragmentSpreads(fragment.SelectionSet)
862862
if len(spreadNodes) == 0 {
863863
return
864864
}

validator.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ type ValidationContext struct {
9595
variableUsages map[HasSelectionSet][]*VariableUsage
9696
recursiveVariableUsages map[*ast.OperationDefinition][]*VariableUsage
9797
recursivelyReferencedFragments map[*ast.OperationDefinition][]*ast.FragmentDefinition
98-
fragmentSpreads map[HasSelectionSet][]*ast.FragmentSpread
98+
fragmentSpreads map[*ast.SelectionSet][]*ast.FragmentSpread
9999
}
100100

101101
func NewValidationContext(schema *Schema, astDoc *ast.Document, typeInfo *TypeInfo) *ValidationContext {
@@ -107,7 +107,7 @@ func NewValidationContext(schema *Schema, astDoc *ast.Document, typeInfo *TypeIn
107107
variableUsages: map[HasSelectionSet][]*VariableUsage{},
108108
recursiveVariableUsages: map[*ast.OperationDefinition][]*VariableUsage{},
109109
recursivelyReferencedFragments: map[*ast.OperationDefinition][]*ast.FragmentDefinition{},
110-
fragmentSpreads: map[HasSelectionSet][]*ast.FragmentSpread{},
110+
fragmentSpreads: map[*ast.SelectionSet][]*ast.FragmentSpread{},
111111
}
112112
}
113113

@@ -146,13 +146,13 @@ func (ctx *ValidationContext) Fragment(name string) *ast.FragmentDefinition {
146146
f, _ := ctx.fragments[name]
147147
return f
148148
}
149-
func (ctx *ValidationContext) FragmentSpreads(node HasSelectionSet) []*ast.FragmentSpread {
149+
func (ctx *ValidationContext) FragmentSpreads(node *ast.SelectionSet) []*ast.FragmentSpread {
150150
if spreads, ok := ctx.fragmentSpreads[node]; ok && spreads != nil {
151151
return spreads
152152
}
153153

154154
spreads := []*ast.FragmentSpread{}
155-
setsToVisit := []*ast.SelectionSet{node.GetSelectionSet()}
155+
setsToVisit := []*ast.SelectionSet{node}
156156

157157
for {
158158
if len(setsToVisit) == 0 {
@@ -189,14 +189,14 @@ func (ctx *ValidationContext) RecursivelyReferencedFragments(operation *ast.Oper
189189

190190
fragments := []*ast.FragmentDefinition{}
191191
collectedNames := map[string]bool{}
192-
nodesToVisit := []HasSelectionSet{operation}
192+
nodesToVisit := []*ast.SelectionSet{operation.SelectionSet}
193193

194194
for {
195195
if len(nodesToVisit) == 0 {
196196
break
197197
}
198198

199-
var node HasSelectionSet
199+
var node *ast.SelectionSet
200200

201201
node, nodesToVisit = nodesToVisit[len(nodesToVisit)-1], nodesToVisit[:len(nodesToVisit)-1]
202202
spreads := ctx.FragmentSpreads(node)
@@ -210,7 +210,7 @@ func (ctx *ValidationContext) RecursivelyReferencedFragments(operation *ast.Oper
210210
fragment := ctx.Fragment(fragName)
211211
if fragment != nil {
212212
fragments = append(fragments, fragment)
213-
nodesToVisit = append(nodesToVisit, fragment)
213+
nodesToVisit = append(nodesToVisit, fragment.SelectionSet)
214214
}
215215
}
216216

0 commit comments

Comments
 (0)