Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQLUnionType documentation is incorrect #105

Closed
berekuk opened this issue Aug 28, 2020 · 1 comment
Closed

GraphQLUnionType documentation is incorrect #105

berekuk opened this issue Aug 28, 2020 · 1 comment

Comments

@berekuk
Copy link

berekuk commented Aug 28, 2020

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.

@Cito
Copy link
Member

Cito commented Aug 28, 2020

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

@Cito Cito closed this as completed Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants