Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Generate pydantic types from any graphql schema

License

Notifications You must be signed in to change notification settings

qw-in/graphql-codegen-pydantic

Repository files navigation

Warning

Unfortunatly, I never did find the time to flesh out this plugin & I've moved on from both GraphQL & Python for the time being.

If you are looking for alternatives, consider @jhnnsrs's turms (see #10).

Please feel free to contact me if you are interested in taking over this package. Thanks!

--Quinn (@qw-in)

Pydantic type generation for graphql

graphql-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, List
from pydantic import BaseModel


class Author(BaseModel):
    name: Optional[str]
    books: Optional[List[Optional['Book']]]


class Book(BaseModel):
    title: Optional[str]
    author: Optional['Author']

Warning

graphql-codegen-pydantic is currently still very experimental and is not ready for production use

Installation

  1. Set up graphql-codegen
  2. Install graphql-codegen-pydantic
yarn add graphql-codegen-pydantic -D
  1. Add python file to codegen.yml
schema: http://localhost:3000/graphql
generates:
  ./src/schema.py:
    plugins:
      - pydantic

Limitations

Currently very limited

  1. No configuration supported
  2. No comments included in generated code
  3. No support for documents
  4. No resolver support for eg graphene or ariadne
  5. Properties converted to snake_case

Releases

No releases published

Packages

No packages published