pydantic2graphene

Easy way to convert pydantic2graphene models to graphene objects.


Keywords
python, api, graphql, graphene, pydantinc, pydantic, python3, python310, python37, python38, python39
License
MIT
Install
pip install pydantic2graphene==0.5.1

Documentation

pydantic2graphene

CI Forwards Compatibility Coverage pypi versions license

Easy way to convert pydantic2graphene models to graphene objects.

Install

$ pip install pydantic2graphene

A Simple Example

Using to_graphene

import pydantic
import pydantic2graphene

class User(pydantic.BaseModel):
    email: str
    active: bool = False

UserGql = pydantic2graphene.to_graphene(User)

Converting to multiple graphene types with ConverterToGrapheneBase

import pydantic
import pydantic2graphene

class User(pydantic.BaseModel):
    email: str
    active: bool = False

class UserConverter(pydantic2graphene.ConverterToGrapheneBase):
    class Config:
        model = User

UserGql = UserConverter.as_class()  # graphene.ObjectType
UserInputGql = UserConverter.as_class(graphene.InputObjectType)
UserInterfaceGql = UserConverter.as_class(graphene.Interface)

More Examples