Skip to content

Commit

Permalink
fix to support schema printed by graphene package
Browse files Browse the repository at this point in the history
issue: graphql-python/graphene#1209

commit-id:1a2b2003
  • Loading branch information
kolia-kaploniuk committed Jul 19, 2024
1 parent bf4eb13 commit fd6e3c6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
10 changes: 1 addition & 9 deletions pkg/astparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,6 @@ func (p *Parser) parseImplementsInterfaces() (list ast.TypeList) {

p.read() // implements

acceptIdent := true
acceptAnd := true

for {
Expand All @@ -736,28 +735,21 @@ 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)
if cap(list.Refs) == 0 {
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
Expand Down
39 changes: 39 additions & 0 deletions pkg/astparser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fd6e3c6

Please sign in to comment.