Skip to content

Commit

Permalink
Fix parseObjectDef will terminate when object has bad syntax (graph-g…
Browse files Browse the repository at this point in the history
  • Loading branch information
cnnrrss committed Feb 23, 2022
1 parent ef6fd96 commit 180fc98
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,19 +408,19 @@ func parseObjectDef(l *common.Lexer) *types.ObjectTypeDefinition {
continue
}

if l.Peek() == scanner.Ident {
l.ConsumeKeyword("implements")
if l.Peek() != scanner.Ident {
break
}

for l.Peek() != '{' && l.Peek() != '@' {
if l.Peek() == '&' {
l.ConsumeToken('&')
}
l.ConsumeKeyword("implements")

object.InterfaceNames = append(object.InterfaceNames, l.ConsumeIdent())
for l.Peek() != '{' && l.Peek() != '@' {
if l.Peek() == '&' {
l.ConsumeToken('&')
}
continue
}

object.InterfaceNames = append(object.InterfaceNames, l.ConsumeIdent())
}
}
l.ConsumeToken('{')
object.Fields = parseFieldsDef(l)
Expand Down
13 changes: 13 additions & 0 deletions internal/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,19 @@ Second line of the description.
return nil
},
},
{
name: "Parses type invalid syntax",
sdl: `
type U = T
`,
validateError: func(err error) error {
msg := `graphql: syntax error: unexpected "=", expecting "{" (line 2, column 11)`
if err == nil || err.Error() != msg {
return fmt.Errorf("expected error %q, but got %q", msg, err)
}
return nil
},
},
{
name: "Description is correctly parsed for non-described types",
sdl: `
Expand Down

0 comments on commit 180fc98

Please sign in to comment.