graphql-python / graphene-pydantic

Integrate GraphQL with your Pydantic models
Other
229 stars 44 forks source link

Document PydanticObjectType.resolve_foo member functions #50

Closed mnieber closed 3 years ago

mnieber commented 3 years ago

I was delighted that the following works (I copied something from django_graphene code), but AFAICT it's not a documented feature

class Resolution(PydanticObjectType):
    class Meta:
        model = ResolutionModel
        exclude_fields = ("status",)

    status = graphene.String()

    def resolve_status(self, info, **kwargs):
        return str(self.status)

I suppose you can add any additional field to a PydanticObjectType by declaring it and adding a resolve function for it? It would be nice to add this to the docs.

necaris commented 3 years ago

@mnieber Nice find! I believe this is not unique to PydanticObjectType but actually a feature of the base graphene.ObjectType (that would explain why it works with django_graphene too) -- see https://docs.graphene-python.org/en/stable/api/#object-types .Where would you suggest we should call this out specifically? I agree it's not very obvious from the base class documentation.

mnieber commented 3 years ago

I created a PR: https://github.com/graphql-python/graphene-pydantic/pull/51. Let me know if you prefer something slightly different (or if you wish, you can change the PR)

necaris commented 3 years ago

Closed by #51