{ } Schemato

GraphQL to Pydantic Converter

Paste a GraphQL sample, get production-ready Pydantic code. Runs entirely in your browser.

Examples:

Simple SDL with non-null and optional fields

InputGraphQL
OutputPydantic

About this converter

Use a Python service to consume a GraphQL API while keeping types aligned with the SDL.

Why convert GraphQL to Pydantic

  • Get parsing, validation, and serialization in one Python class.
  • Power FastAPI request/response models with zero extra boilerplate.
  • Replace ad-hoc dict access with typed attributes that IDEs understand.

How to use

  1. Paste your GraphQL on the left panel, or pick one of the sample tabs above.
  2. The converter infers field names, optionality, and types automatically.
  3. Copy the generated Pydantic on the right and drop it straight into your codebase.

Common pitfalls

  • Pydantic is strict about types by default. If your real data sometimes contains unexpected fields, you may want to set `model_config = ConfigDict(extra='ignore')`.
  • Optional fields get `Optional[X] = None` only when the sample shows null. Real-world APIs often have more optional fields than a single sample reveals.
  • Datetime strings stay as `str` — switch to `datetime` if you want Pydantic to parse them.

FAQ

Is this graphql to pydantic converter free?
Yes. It is fully free, no signup, and runs entirely in your browser. We do not store your input.
Does it work with nested objects and arrays?
Yes. Nested objects produce separate named types, and arrays infer the element type from the first non-null sample.
What about optional / nullable fields?
Fields whose value is null in the sample (or marked optional in JSON Schema / Prisma / GraphQL) are marked optional/nullable in the output. For real APIs, you may want to widen optionality manually after generation.
Can I generate Pydantic from multiple GraphQL samples?
Today the tool processes a single sample. For more aggressive inference across multiple shapes, run the converter on the union/merge of your samples or open an issue.
Is the source code available?
Yes — the entire project is open source. See the GitHub link in the footer.

Related converters