Generated Python GraphQL Client (via ariadne-codegen) #1410
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This sets up
ariadne-codegento 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:
It should be
cubeMetricsin place ofcube_metrics, since the original schema uses camel case.Usage
Here's an example that uses the generated client:
Test Plan
make checkpassesmake testshows 100% unit test coverageDeployment Plan