Pydantic type generation for graphql
gql-codegen-pydantic
is a plugin for graphql-codegen
that generates Pydantic types from any graphql schema
Example
type Book { title: String author: Author} type Author { name: String books: [Book]}
becomes
from typing import Optional, Listfrom pydantic import BaseModel name: books: title: author:
Warning
gql-codegen-pydantic
is currently still very experimental and is not ready for production use
Installation
- Set up
graphql-codegen
- Install
gql-codegen-pydantic
yarn add gql-codegen-pydantic -D
- Add python file to
codegen.yml
schema: http://localhost:3000/graphqlgenerates: ./src/schema.py: plugins: - gql-codegen-pydantic
Limitations
Currently very limited
- No configuration supported
- No comments included in generated code
- No support for documents
- No resolver support for eg graphene or ariadne
- Properties converted to
snake_case