Skip to content

Generated Python GraphQL Client (via ariadne-codegen)#1410

Draft
shangyian wants to merge 3123 commits intoDataJunction:mainfrom
shangyian:ariadne-codegen
Draft

Generated Python GraphQL Client (via ariadne-codegen)#1410
shangyian wants to merge 3123 commits intoDataJunction:mainfrom
shangyian:ariadne-codegen

Conversation

@shangyian
Copy link
Copy Markdown
Collaborator

@shangyian shangyian commented Jun 19, 2025

Summary

This sets up ariadne-codegen to automatically generate a fully typed GraphQL Python client. It attaches the generated files to the existing DJ python client. The client is regenerated as a part of the pre-commit hook whenever the graphql schema changes.

Issue with List Inputs

One issue I discovered while testing the generated client is that list inputs are converted into scalars in the client. This leads to issues running queries that take lists as inputs (e.g., findNodes(names: [String!], ...)).

This has been documented across various issues like mirumee/ariadne-codegen#321 and mirumee/ariadne-codegen#347. It is fixed by mirumee/ariadne-codegen#363, but the PR has not been merged.

Therefore, this PR currently depends on the forked version of ariadne-codegen that has this fix.

Issue with Snake Case

A second issue comes from using the default convert_to_snake_case -- not all cases are converted correctly between the two, and some fields use snake case in the generated client when it shouldn't, leading to errors running queries.

For example, the generated client produces:

    @classmethod
    def cube_metrics(cls) -> "NodeRevisionFields":
        return NodeRevisionFields("cube_metrics")

It should be cubeMetrics in place of cube_metrics, since the original schema uses camel case.

Usage

Here's an example that uses the generated client:

import asyncio
from datajunction.graphql_client import Client
from datajunction.graphql_client.enums import NodeType
from datajunction.graphql_client.custom_queries import Query
from datajunction.graphql_client.custom_fields import NodeFields, NodeRevisionFields

client = Client(url="http://localhost:8000/graphql")

async def get_cubes():
    find_cubes_query = Query.find_nodes(
        node_types=[NodeType.CUBE],
        tags=["xp.report"],
        fragment="member.",
    ).fields(
        NodeFields.name,
        NodeFields.current().fields(
            NodeRevisionFields.version,
            NodeRevisionFields.cube_metrics().fields(
                NodeFields.name,
            ),
        ),
    )
    response = await client.query(
        find_cubes_query,
        operation_name="get_cubes",
    )
    return response["findNodes"]

cubes = asyncio.run(get_cubes())

Test Plan

  • PR has an associated issue: #
  • make check passes
  • make test shows 100% unit test coverage

Deployment Plan

…handling

Better categorize the various exceptions into user vs system errors
GQL common dimensions query + dim attr output shape
Only generate preaggregated measures SQL where possible
samredai and others added 21 commits May 21, 2025 23:08
* Switch Dialect enum to strings in database

* Rebase

* Add docs for custom transpilation plugins

* Add test coverage and cleanup
* Speed up the recursive dimensions graph CTE query

* Fix

* Add node paths

* Consistency

* Cleanup and get to parity

* Fix additional tests

* Fix linters

* Fix reference link with roles

* Fix linters

* Fix lint

* Fix lint
Co-authored-by: GitHub Actions Bot <>
…on#1390)

* Add graphql schema generation script and seed with generated schema

* Include schema.graphql in packaging
* Add /cubes endpoint to get metadata on all cubes

* Change query param to catalog
…tion#1388)

* Fix the derived expression of count distinct metrics to use the count distinct argument

* Add separate treatment of measures for distinct quantifier aggregations

* Add support to complex expressions inside distinct-agg metrics

* Refactor names and add tests for resolving metric components

* Cleanup

* More naming cleanup

* Add graphql naming refactor

* Update comments and update GraphQL schema
* Add pagination to /cubes endpoint

* don't pull inactive nodes for /cubes/... endpoints
* Add endpoint to list available dialects

* Add support for GraphQL querying of dialects
Co-authored-by: GitHub Actions Bot <>
* Fix an issue where renaming dimensions for measures SQL creates should include both columns

* Fix tests

* Refactor to make it cleaner
…1396)

* Add option to delete materializations by node version.

* Lint and commments addressed.

* Comment addressed plus added node_revision_id to Materialization output.
* Replaces use of Depends(get_session) in get_context() with session middleware, since the former doesn't support teardown in Strawberry.

* Add test for db session middleware

* Fix tests
…ataJunction#1402)

* When a node is deactivated, its materializations should be as well

* Fix tests
Co-authored-by: GitHub Actions Bot <>
@netlify
Copy link
Copy Markdown

netlify bot commented Jun 19, 2025

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit 03afb72
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/6853a6a3fd90ac000858511a

shangyian and others added 6 commits June 18, 2025 22:28
* Add filtering on columns for node revisions in GQL

* Add tests for resolvers
* Add docker compose with superset

* Remove comments

* add password init

* Add secret key

* docker compose file that works with superset

* Fix

* Fix names

* Fix

---------

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants