graphene
graphene copied to clipboard
Undefined arguments always passed to resolvers
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
@jkimbo or anyone responsible. Please look into this. I am also experiencing this issue.
@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?
This was fixed by https://github.com/graphql-python/graphene/pull/1412 and is released in 3.1.0