Skip to content

Input type? #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Bingdom opened this issue May 18, 2023 · 3 comments
Open

Input type? #17

Bingdom opened this issue May 18, 2023 · 3 comments

Comments

@Bingdom
Copy link

Bingdom commented May 18, 2023

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.
@TimDumol
Copy link
Collaborator

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.

@Bingdom
Copy link
Author

Bingdom commented May 22, 2023

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?

@Ckk3
Copy link
Contributor

Ckk3 commented Sep 6, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants