Closed
Description
GraphQLUnionType currently gives the following example of its usage:
class PetType(GraphQLUnionType):
name = 'Pet'
types = [DogType, CatType]
def resolve_type(self, value, _type):
if isinstance(value, Dog):
return DogType()
if isinstance(value, Cat):
return CatType()
I believe this documentation is incorrect; PetType()
can't be instantiated since GraphQLUnionType's __init__
takes name and types as required parameters.
Calling PetType(name=PetType.name, ...)
is obviously terrible, and implementing an empty __init__
which doesn't call super()
feels unsafe.
Also, even if there's a way to define a UnionType via inheritance which I'm missing, I don't see why GraphQLUnionType example should be different from GraphQLInterfaceType example, which uses the normal function call API.
Activity
Fix example in docstring of GraphQLUnionType (#105)
Cito commentedon Aug 28, 2020
You're right, the docstring is obviously incorrect - thanks for reporting. I commited a fix with hopefully proper example code now.