Skip to content

Conversation

@shangyian
Copy link
Contributor

@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

@netlify
Copy link

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

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.

1 participant