Replies: 8 comments 5 replies
-
|
Hi, you need to load the schema by the load_schema_from_path. from ariadne import gql, load_schema_from_path
# load schema from file...
schema = load_schema_from_path("schema.graphql")
# ...directory containing graphql files...
schema = load_schema_from_path("schema")
# ...or inside Python files
schema = gql("""
type Query {
user: User
}
type User {
id: ID
username: String!
}
""") |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for answering. I am confused then about the usage of the codegen for the schema , how would I use it? Your answer seems not to be related at all to Code Generation And how would I avoid writing python dataclasses or base models for each input type and response type? |
Beta Was this translation helpful? Give feedback.
-
|
Hi @edmondop, quick clarification: ariadne-codegen generates client code, not server code. For building a server, use the main ariadne library as @mociepka showed. You don't need to write Pydantic/dataclass models - just return dicts from your resolvers. For a class-based server approach, check out ariadne-graphql-modules. |
Beta Was this translation helpful? Give feedback.
-
|
I am confused. It seems that documentation says Ariadne supports a schema first development approach, but in reality it doesn't? Manually curating hundreds or thousands of models on the server side is prohibitive |
Beta Was this translation helpful? Give feedback.
-
|
Hi @edmondop! You're misunderstanding what ariadne-codegen does and what Ariadne itself is designed for. ariadne-codegen is a CLIENT code generator - it generates typed Python clients to consume GraphQL APIs, not build them. Ariadne is NOT designed to generate Pydantic models or dataclasses. It works with plain Python objects and handles GraphQL serialization for you. Schema-first approach means you define your GraphQL schema first, then write resolvers that match it - not that code is automatically generated from the schema. You write the resolvers manually: # This is how Ariadne works (schema-first):
def resolve_user(_, info, id):
return {"id": id, "name": "John"} # Plain dict - no models neededIf you need hundreds of auto-generated Pydantic models for server-side validation, Ariadne is not the right tool for your use case. You're looking for functionality that Ariadne was never designed to provide. However, if you're interested in contributing, you could gather the requirements for your use case and we could collaborate on creating a solution. This might be something that would interest other users as well. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
I actually did it using the codegen perfectly and it works like a charm. I
used a trick. I had to define queries.graphql with full queries with all
fields, and it generated all pydantic models
It just required me to do this hack 😂😂😂
…On Sun, Sep 28, 2025 at 11:57 AM DamianCzajkowski ***@***.***> wrote:
I think you have a point. That's something that could be addressed by
implementing a server strategy in ariadne-codegen to generate types for
Ariadne servers. It wouldn't generate the whole server, of course, but only
the typing to maintain a single source of truth.
Are you interested in contributing this feature? It would be great to
understand your specific requirements first.
—
Reply to this email directly, view it on GitHub
<#384 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGGOKMQ7S5HJRMKHIDYDY33VAAPXAVCNFSM6AAAAACHW6MLS2VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTINJTGQ4DMMY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
|
Awesome. Will propose a design and then once we agree I will implement it
…On Sun, Sep 28, 2025 at 12:06 PM DamianCzajkowski ***@***.***> wrote:
Yes, I know this can be done with workarounds, but it's not always ideal
to rely on hacks :D
This could be a perfect feature addition, especially since the generated
client files aren't needed for server-side development anyway.
—
Reply to this email directly, view it on GitHub
<#384 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGGOKP5FDCWQ3ZM5AYLWKL3VABOTAVCNFSM6AAAAACHW6MLS2VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTINJTGQ4DSOI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
I have generated a GraphQLSchema from an existing schema, but it's not clear to me how to use this with
make_executable_schemato create my GraphQL server. I was interested in generating the python code from the schema to avoid having to maintain pydantic models or dataclasses for input and response types, but I haven't found a good way to do it.What's the right API to use?
Beta Was this translation helpful? Give feedback.
All reactions