graphql-query is a Python library that provides a complete Domain Specific Language (DSL) for constructing GraphQL queries programmatically. It allows developers to build complex GraphQL queries, mutations, and fragments using Python objects, simplifying the process of generating valid GraphQL syntax. The library is actively maintained with regular updates, currently at version 1.4.0.
pip install graphql-queryVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to construct basic GraphQL queries using the `Query`, `Field`, and `Argument` classes. The `render()` method converts the Python object structure into a valid GraphQL query string.
Upgrade Pydantic to version 2 or newer (`pip install pydantic>=2`) and ensure your codebase is compatible. If other dependencies still require Pydantic v1, consider isolating the graphql-query environment or using `pydantic.v1` namespace if applicable, though `graphql-query` specifically targets v2.
Ensure your project runs on Python 3.8 or a later version.
Review your project's direct `graphql-core` usage. Add `pip install graphql-core` if still needed independently of `graphql-query`.
Refer to the `graphql-query` documentation for advanced argument typing and ensure Python values align with expected GraphQL types (e.g., `Int`, `Boolean`, `ID`, `Float`).
Verify that the `value` argument in `Argument(name='...', value=...)` or other field properties matches the expected scalar type (e.g., string, int, bool, float) or correct list structure if a list is intended.
For any field that returns an object type (not a scalar), ensure you pass a list of `Field` objects to its `fields` argument, e.g., `Field(name='user', fields=[Field(name='id'), Field(name='name')])`.
Ensure `graphql-query` is at version 1.3.0 or higher. If you have other Pydantic-dependent libraries, you may need to update them or use Pydantic V2's compatibility features (like `pydantic.v1`) carefully. The `bump-pydantic` tool can help migrate your codebase.