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.

Activity

Cito

Cito commented on Aug 28, 2020

@Cito
Member

You're right, the docstring is obviously incorrect - thanks for reporting. I commited a fix with hopefully proper example code now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @berekuk@Cito

        Issue actions

          GraphQLUnionType documentation is incorrect · Issue #105 · graphql-python/graphql-core