Skip to content

GraphQLUnionType documentation is incorrect #105

Closed
@berekuk

Description

@berekuk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions