You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say I have a graphql query that takes a parameter which is named after a reserved python keyword (e.g: from). Following python conventions, this is how I would declare it:
Here, name is used so that a user don't have to deal with the ugly underscore. Which is nice. However, there is a problem in the resolver:
defresolve_some_query(_, args, context, infos):
args["from_"] # KeyError ! Because the arg name is 'from' which is not what I expect.
Now this is not a big deal, I could just use args["from"] when I need the value. But it becomes a problem when I want to pass all the parameters to an other function like this:
Because my function signature would looks like this and cause a syntax error:
defcall_some_handler(from=None):
pass
I think trailing underscores should be removed when calling graphene.utils.str_converters.to_snake_case this would allow usage of python reserved keyword as parameters name while not breaking compatibility. If you guys agree with this I can make a PR during the weekend.
The text was updated successfully, but these errors were encountered:
I decided to fix the argument output name to be _from instead of from, as it simplifies and makes more clear how to retrieve the arguments from the python resolver.
This way, the previous function you expected to work, should work:
defresolve_some_query(_, args, context, infos):
args["from_"] # Not longer KeyError :)
Hi !
Let's say I have a graphql query that takes a parameter which is named after a reserved python keyword (e.g:
from
). Following python conventions, this is how I would declare it:Here,
name
is used so that a user don't have to deal with the ugly underscore. Which is nice. However, there is a problem in the resolver:Now this is not a big deal, I could just use
args["from"]
when I need the value. But it becomes a problem when I want to pass all the parameters to an other function like this:Because my function signature would looks like this and cause a syntax error:
I think trailing underscores should be removed when calling
graphene.utils.str_converters.to_snake_case
this would allow usage of python reserved keyword as parameters name while not breaking compatibility. If you guys agree with this I can make a PR during the weekend.The text was updated successfully, but these errors were encountered: