Complete Domain Specific Language (DSL) for GraphQL query in Python.
Slowing down. Last release over 2 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install graphql-querygraphql-query
graphql_query is a complete Domain Specific Language (DSL) for GraphQL query in Python. With this package you can to
- generate a correct GraphQL query string from a python classes;
- use and share similar Arguments, Variables and e.t.c between different queries;
- easily add new fields to your query;
- add Fragments and Directives to queries;
- generate graphql_query classes from pydantic data-model;
The documentation for graphql_query can be found at https://denisart.github.io/graphql-query/.
Quickstart
Install with pip
pip install graphql_query
Simple query
Code for the simple query
{
hero {
name
}
}
it is
from graphql_query import Operation, Query
hero = Query(name="hero", fields=["name"])
operation = Operation(type="query", queries=[hero])
print(operation.render())
"""
query {
hero {
name
}
}
"""
The render method for the graphql_query.Operation object
just returns the final string with a query. Inside the fields array of the graphql_query.Query object
you can use
str(a field name);- object of
graphql_query.Fieldtype; graphql_query.Fragmentandgraphql_query.InlineFragment.
Arguments, Variables and Directives
For generation of the following query