Skip to content

Commit

Permalink
Merge pull request #82 from vektah/fix-infinit-loop
Browse files Browse the repository at this point in the history
fix infinit loop in OverlappingFieldsCanBeMerged rule
  • Loading branch information
vektah authored Nov 28, 2018
2 parents 28e162a + 6c769aa commit e805d08
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
16 changes: 14 additions & 2 deletions validator/imported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"testing"

Expand All @@ -20,7 +21,7 @@ import (
type Spec struct {
Name string
Rule string
Schema int
Schema string
Query string
Errors gqlerror.List
}
Expand Down Expand Up @@ -85,7 +86,18 @@ func runSpec(t *testing.T, schemas []*ast.Schema, deviations []*Deviation, filen
}
}

_, err := gqlparser.LoadQuery(schemas[spec.Schema], spec.Query)
// idx := spec.Schema
var schema *ast.Schema
if idx, err := strconv.Atoi(spec.Schema); err != nil {
var gqlErr *gqlerror.Error
schema, gqlErr = gqlparser.LoadSchema(&ast.Source{Input: spec.Schema, Name: spec.Name})
if gqlErr != nil {
t.Fatal(err)
}
} else {
schema = schemas[idx]
}
_, err := gqlparser.LoadQuery(schema, spec.Query)
var finalErrors gqlerror.List
for _, err := range err {
// ignore errors from other rules
Expand Down
4 changes: 4 additions & 0 deletions validator/rules/overlapping_fields_can_be_merged.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ func (m *overlappingFieldsCanBeMergedManager) collectConflictsBetweenFieldsAndFr

// (E) Then collect any conflicts between the provided collection of fields
// and any fragment names found in the given fragment.
baseFragmentSpread := fragmentSpread
for _, fragmentSpread := range fragmentSpreads {
if fragmentSpread.Name == baseFragmentSpread.Name {
continue
}
m.collectConflictsBetweenFieldsAndFragment(conflicts, areMutuallyExclusive, fieldsMap, fragmentSpread)
}
}
Expand Down
29 changes: 29 additions & 0 deletions validator/spec/Fuzz.spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,32 @@
query: '{r{__typename(s:0)}}'
errors:
- message: Cannot query field "r" on type "QueryRoot".

- name: 02 - infinit loop occured in OverlappingFieldsCanBeMerged rule
schema: |
type Query {
fieldA: A
}
type A {
s: String
}
query: |
{ ...F }
fragment F on Query {
fieldA { s }
...{
...{
...F
}
fieldA {
...notExists
}
}
}
errors:
# from KnownFragmentNames rule
- message: Unknown fragment "notExists".
- message: Unknown fragment "notExists".
- message: Unknown fragment "notExists".
# from NoFragmentCycles rule
- message: Cannot spread fragment "F" within itself.

0 comments on commit e805d08

Please sign in to comment.