Closed conao3 closed 1 year ago
From looking at Pydantic's docs, for all the supported versions this should be great -- field.alias
defaults to name
if it's not set.
As you pointed out, I thought this patch would work correctly because pydantic returns the default name if no alias is set, but graphene adopts the explicitly set snake case field name in the schema as it is, so the field name that used to automatically convert to camelCase were not being converted. Therefore, the field names are now set to graphene's name only when alias is set.
In fact, pydantic's alias should be set in snake case and graphql should be converted depending on auto_camelcase
in graphene.Schema (document), but this care I will address in another PR.
@conao3 thank you for the further testing! I have approved the PR, but it looks like the tests are failing for an unrelated reason, so I will have to fix that first.
This PR fixes #38.
Graphene sample
In other words, the same behavior as this working graphene can be made to work for a pydantic model
Graphene-pydantic sample
After this patch, this script works, so perhaps this patch is good. I have not been able to fully verify the other behavior.
sample output
Advice is welcome!