A Pydantic integration for Graphene.
pip install "graphene-pydantic"Here is a simple Pydantic model:
import pydantic class PersonModel(pydantic.BaseModel): id: uuid.UUID first_name: str last_name: strTo create a GraphQL schema for it you simply have to write the following:
import graphene from graphene_pydantic import PydanticObjectType class Person(PydanticObjectType): class Meta: model = PersonModel # only return specified fields only_fields = ("name",) # exclude specified fields exclude_fields = ("id",) class Query(graphene.ObjectType): people = graphene.List(User) def resolve_people(self, info): return get_people() # function returning `PersonModel`s schema = graphene.Schema(query=Query)Then you can simply query the schema:
query = ''' query { people { firstName, lastName } } ''' result = schema.execute(query)Please see the examples directory for more.