8000 Undefined arguments always passed to resolvers · Issue #1398 · graphql-python/graphene · GitHub
[go: up one dir, main page]

Skip to content

Undefined arguments always passed to resolvers #1398

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

Closed
stabacco opened this issue Jan 5, 2022 · 3 comments
Closed

Undefined arguments always passed to resolvers #1398

stabacco opened this issue Jan 5, 2022 · 3 comments
Labels

Comments

@stabacco
Copy link
stabacco commented Jan 5, 2022

Contrarily to what's described here: it looks like all the arguments with unset values are passed to the resolvers in graphene-3:

This is the query i am defining

class Query(graphene.ObjectType):

    hello = graphene.String(required=True, name=graphene.String())

    def resolve_hello(parent, info, **kwargs):
        return str(kwargs)

which i submit as

{
    hello
}

The result is :

{
    "data": {
        "hello": "{'name': None}"
    }
}

The expected returned value is :

{
    "data": {
        "hello": "{}"
    }
}

which is what we're getting with graphene-2.

My environment:

graphene==3.0
graphql-core==3.1.7
graphql-relay==3.1.0
graphql-server==3.0.0b4
@stabacco stabacco changed the title NonNull arguments always passed to resolvers Undefined arguments always passed to resolvers Jan 6, 2022
@DenisseRR
Copy link

@jkimbo or anyone responsible. Please look into this. I am also experiencing this issue.

@theodesp
Copy link

@DenisseRR it looks like the docs are right. Notice the first example, the third parameter is a named argument which if you don't provide a default value it will throw an error at runtime:

    def resolve_hello(parent, info, name):
        return name if name else 'World'

This will throw an error as name is not passed on as a parameter

TypeError: resolve_hello() missing 1 required positional argument: 'name'

vs

    def resolve_hello(parent, info, **kwargs):
        name = kwargs.get('name', 'World')
        return f'Hello, {name}!'

This one will work as we provide a default parameter for name because it does not exist. Does it make sense?

@erikwrede
Copy link
Member

This was fixed by #1412 and is released in 3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0