Skip to content

Commit

Permalink
validation: NoUndefinedVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed May 23, 2017
1 parent c39ffec commit 83e2f31
Show file tree
Hide file tree
Showing 4 changed files with 433 additions and 32 deletions.
16 changes: 10 additions & 6 deletions internal/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Operation struct {
Vars common.InputValueList
SelSet *SelectionSet
Directives common.DirectiveList
Loc errors.Location
}

type OperationType string
Expand Down Expand Up @@ -119,8 +120,7 @@ func parseDocument(l *common.Lexer) *Document {
d := &Document{}
for l.Peek() != scanner.EOF {
if l.Peek() == '{' {
op := &Operation{Type: Query}
op.Name.Loc = l.Location()
op := &Operation{Type: Query, Loc: l.Location()}
op.SelSet = parseSelectionSet(l)
d.Operations = append(d.Operations, op)
continue
Expand All @@ -129,7 +129,9 @@ func parseDocument(l *common.Lexer) *Document {
loc := l.Location()
switch x := l.ConsumeIdent(); x {
case "query":
d.Operations = append(d.Operations, parseOperation(l, Query))
op := parseOperation(l, Query)
op.Loc = loc
d.Operations = append(d.Operations, op)

case "mutation":
d.Operations = append(d.Operations, parseOperation(l, Mutation))
Expand All @@ -138,7 +140,9 @@ func parseDocument(l *common.Lexer) *Document {
d.Operations = append(d.Operations, parseOperation(l, Subscription))

case "fragment":
d.Fragments = append(d.Fragments, parseFragment(l, loc))
frag := parseFragment(l)
frag.Loc = loc
d.Fragments = append(d.Fragments, frag)

default:
l.SyntaxError(fmt.Sprintf(`unexpected %q, expecting "fragment"`, x))
Expand Down Expand Up @@ -166,8 +170,8 @@ func parseOperation(l *common.Lexer, opType OperationType) *Operation {
return op
}

func parseFragment(l *common.Lexer, loc errors.Location) *FragmentDecl {
f := &FragmentDecl{Loc: loc}
func parseFragment(l *common.Lexer) *FragmentDecl {
f := &FragmentDecl{}
f.Name = l.ConsumeIdentWithLoc()
l.ConsumeKeyword("on")
f.On = common.TypeName{Ident: l.ConsumeIdentWithLoc()}
Expand Down
2 changes: 1 addition & 1 deletion internal/tests/testdata/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ require('./src/validation/__tests__/KnownFragmentNames-test');
require('./src/validation/__tests__/KnownTypeNames-test');
require('./src/validation/__tests__/LoneAnonymousOperation-test');
require('./src/validation/__tests__/NoFragmentCycles-test');
// require('./src/validation/__tests__/NoUndefinedVariables-test');
require('./src/validation/__tests__/NoUndefinedVariables-test');
require('./src/validation/__tests__/NoUnusedFragments-test');
// require('./src/validation/__tests__/NoUnusedVariables-test');
// require('./src/validation/__tests__/OverlappingFieldsCanBeMerged-test');
Expand Down
Loading

0 comments on commit 83e2f31

Please sign in to comment.