strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

De-shadow resolver arguments that have the same name as builtin functions

Open patrick91 opened this issue 4 years ago โ€ข 9 comments

this:

@strawberry.field
def my_resolver(self, id_: strawberry.ID) -> ...:
    ...

should change the id_ name to be id on the schema.

patrick91 avatar Feb 27 '21 17:02 patrick91

This should also work with arguments with the same name as Python keywords

BryceBeagle avatar Feb 28 '21 01:02 BryceBeagle

Similar in function to #725. Potentially one of the solutions will rely on the other

BryceBeagle avatar Feb 28 '21 01:02 BryceBeagle

Not sure this is a good idea because it feels like too much magic to me. What if you want to have an argument with a trailing underscore? I think being able to override the name of an argument (#725) is a better solution than automagically renaming arguments.

jkimbo avatar Feb 28 '21 07:02 jkimbo

Would having this be a feature that can be enabled/disabled work?

BryceBeagle avatar Feb 28 '21 15:02 BryceBeagle

Would having this be a feature that can be enabled/disabled work?

I think this might be a good trade-off.

By the way we should to the same for autoCamecasing, so we could do both at once (post-refactor I'd say).

What do you think @jkimbo?

patrick91 avatar Feb 28 '21 15:02 patrick91

Being able to enable/disable would definitely be better but I worry that itโ€™s something that could cause some confusion when someone comes across it for the first time since itโ€™s not that obvious. Maybe itโ€™s opt in behaviour?

jkimbo avatar Feb 28 '21 18:02 jkimbo

Yes, Iโ€™d make it opt-in :)

patrick91 avatar Feb 28 '21 18:02 patrick91

This would be a great addition. Same issue with mutation arguments:

@strawberry.mutation
def order_create(input: OrderCreateInput) -> ...:
   ...

input is often used for mutations, which conflicts with Python's input() function.

saschametz avatar May 11 '22 09:05 saschametz

@saschametz please have a look at https://github.com/strawberry-graphql/strawberry/issues/725. This should be supported already ๐Ÿ˜Š

skilkis avatar May 11 '22 09:05 skilkis

I'm going to close this issue, we have support for renaming arguments and we didn't have people asking for something like this ๐Ÿ˜Š We can always revisit it in future :)

patrick91 avatar Oct 20 '22 16:10 patrick91