strawberry-sqlalchemy
strawberry-sqlalchemy copied to clipboard
Input type?
Hello,
I was wondering if there's a way to map to an input type?
In Strawberry, you could just do:
@strawberry.type
class User:
username: str
@strawberry.input
class UserInput(User):
pass
But doing that with this library doesn't make strawberry recognize it as an input
@_strawberryMapper.type(schema.User)
class User:
pass
@strawberry.input
class UserInput(User):
pass
_strawberryMapper.finalize()
Error:
25 TypeError: UserInput fields cannot be resolved. Input field type must be a GraphQL input type.
That's a use case we haven't considered. You can possibly try something like:
from dataclasses import make_dataclass
@_strawberryMapper.type(schema.User)
class User:
pass
_strawberryMapper.finalize()
UserInput = strawberry.input(make_dataclass('UserInput', [], bases=(_strawberryMapper.mapped_types['User'],))
Haven't actually tried this code, but maybe it will give you a good starting point.
Hi,
Thanks for the help.
Strangely, I'm getting the same problem.
What would be the main difference writing like that vs naturally? Except I suppose the additional methods dataclass provides.
I suspect there might be a property that doesn't get correctly overridden that strawberry uses to identify the type?
Hi, @Bingdom, you can use @strawberry.input with @strawberry_sqlalchemy_mapper.type.
Like this:
@strawberry.input
@strawberry_sqlalchemy_mapper.type(User)
class UserInput:
__exclude__ = ["id", "password_hash"]
This help me with that limitation, I hope it can help you too!