strawberry
strawberry copied to clipboard
Introduce `.as_input` for object types
Imagine we have this type:
@strawberry.type
class Frequency:
kind: str
times: int
and we want to use it as input, to do so we need to make a copy of it pretty much:
@strawberry.input
class FrequencyInput:
kind: str
times: int
But what if we allowed doing something like this:
@strawberry.type
class Frequency:
kind: str
times: int
FrequencyInput = Frequency.as_input() # we don't have access to the variable name, but we'll append Input to the original name
FrequencyInput = Frequency.as_input(name="AddFrequencyInput")
FrequencyInput = Frequency.as_input(all_optional=True) # not sure about this yet
Upvote & Fund
- We're using Polar.sh so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.
Would absolutely love see this happen.
Stumbled on this issue when posting a question in strawberry discord community. I think having the brief here would be quite useful too:
We are using sqlalchemy to define db models of the data. On top of this, we need at least two classes to represent strawberry gql output and input. There is also a notion of the data itself (you can argue, however, that this could very well be represented by strawberry output, though, i.e. strawberry.type decorated class). And so we end up needing to define at least 3 classes with essentially the same data.
I have tried to abstract this away by creating what you see in the screenshot, however this does not really help with the fact that you still need to define all those classes separately. Usefulness of it rather lies in the fact that everything that you might need is contained in a single class.
Therefore, it would be a lot of help already if we could knock out needing to define at least one of these classes, namely input.