0.1.0 • Published 4 years ago
gql-codegen-pydantic v0.1.0
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, 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
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/graphql
generates:
./src/schema.py:
plugins:
- gql-codegen-pydantic
Limitations
Currently very limited
1. No configuration supported
1. No comments included in generated code
1. No support for documents
1. No resolver support for eg graphene or ariadne
1. Properties converted to snake_case
0.1.0
4 years ago