-
-
Notifications
You must be signed in to change notification settings - Fork 543
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
How to serialize Strawberry models #3565
Comments
@mecampbellsoup I think adding support for (un)snake casing would be nice, but we would need to do via a schema configuration, since that depends on how the schema has been configured 😊 |
What API are you envisioning? (I know I opened the issue so it's rich for me to ask you that but, humor me! 😆) Then at the object type level might it be configurable similarly to Pydantic's class StorageClassPyd(PydanticModel):
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) |
I was thinking something like this: @strawberry.input
class Something:
name: str
something_else: str
data = Something(name="ABC", something_else="ABC")
strawberry.asdict(data, config={"auto_camel_case": True}) # this would be the same config passed to the schema but while writing this I realised that What's your reasoning behind not passing a dict to your test? 😊 |
Laziness! I just thought that this type of camel case to snake case conversion was happening internally quite a bit, since the FE JSON is typically formatted w/ I like using the strawberry types as a starting point though because that's the "public facing API", so in integration tests passing form data to GQL resolvers, it feels like the right thing (as opposed to e.g. using the Pydantic types). To your point though, we can pass dictionaries in tests. |
I'm writing some integration tests that use an HTTP client to hit our GQL API like so:
In this example,
saml_configuration_form
is a strawberry input type:This gets me halfway there, but
strawberry.asdict
seems to be limited to snake-casing (or rather, limited to however the fields are cased on theSAMLConfigurationPyd
model in this example).Would it be possible to support something like:
That way I can easily inflect the serialized form's keys.
Upvote & Fund
The text was updated successfully, but these errors were encountered: