diff --git a/pkg/astparser/parser.go b/pkg/astparser/parser.go index f273d9663b..a228347362 100644 --- a/pkg/astparser/parser.go +++ b/pkg/astparser/parser.go @@ -727,7 +727,6 @@ func (p *Parser) parseImplementsInterfaces() (list ast.TypeList) { p.read() // implements - acceptIdent := true acceptAnd := true for { @@ -736,15 +735,12 @@ func (p *Parser) parseImplementsInterfaces() (list ast.TypeList) { case keyword.AND: if acceptAnd { acceptAnd = false - acceptIdent = true p.read() } else { p.errUnexpectedToken(p.read()) return } case keyword.IDENT: - if acceptIdent { - acceptIdent = false acceptAnd = true name := p.read() ref := p.document.AddNamedTypeWithPosition(name.Literal, name.TextPosition) @@ -752,12 +748,8 @@ func (p *Parser) parseImplementsInterfaces() (list ast.TypeList) { list.Refs = p.document.Refs[p.document.NextRefIndex()][:0] } list.Refs = append(list.Refs, ref) - } else { - p.errUnexpectedToken(p.read()) - return - } default: - if acceptIdent { + if !acceptAnd { p.errUnexpectedToken(p.read()) } return diff --git a/pkg/astparser/parser_test.go b/pkg/astparser/parser_test.go index 1cbaf7c358..3e1dbff0fe 100644 --- a/pkg/astparser/parser_test.go +++ b/pkg/astparser/parser_test.go @@ -927,6 +927,45 @@ func TestParser_Parse(t *testing.T) { } }) }) + // Workaround for graphene issue: https://github.com/graphql-python/graphene/issues/1209 + t.Run("implements optional variant - comma separated", func(t *testing.T) { + run(`type Car implements IVehicle & IMetrics, IWheel {}`, parse, false, func(doc *ast.Document, extra interface{}) { + person := doc.ObjectTypeDefinitions[0] + personName := doc.Input.ByteSliceString(person.Name) + if personName != "Car" { + panic("want Car") + } + // interfaces + + if len(person.ImplementsInterfaces.Refs) != 3 { + panic("want 3 interfaces") + } + + implementsVehicle := doc.Types[person.ImplementsInterfaces.Refs[0]] + if implementsVehicle.TypeKind != ast.TypeKindNamed { + panic("want TypeKindNamed") + } + if doc.Input.ByteSliceString(implementsVehicle.Name) != "IVehicle" { + panic("want IVehicle") + } + + implementsMetrics := doc.Types[person.ImplementsInterfaces.Refs[1]] + if implementsMetrics.TypeKind != ast.TypeKindNamed { + panic("want TypeKindNamed") + } + if doc.Input.ByteSliceString(implementsMetrics.Name) != "IMetrics" { + panic("want IMetrics") + } + + implementsWheel := doc.Types[person.ImplementsInterfaces.Refs[2]] + if implementsWheel.TypeKind != ast.TypeKindNamed { + panic("want TypeKindNamed") + } + if doc.Input.ByteSliceString(implementsWheel.Name) != "IWheel" { + panic("want IWheel") + } + }) + }) t.Run("input value definition list", func(t *testing.T) { run(` type Person { "name description"