graphql-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
query Hero($episode: Episode, $withFriends: Boolean!) {
hero(episode: $episode) {
name
friends @include(if: $withFriends) {
name
}
}
}
we can use the following python code
from graphql_query import Argument, Directive, Field, Operation, Query, Variable
episode = Variable(name="episode", type="Episode")
withFriends = Variable(name="withFriends", type="Boolean!")
arg_episode = Argument(name="episode", value=episode)
arg_if = Argument(name="if", value=withFriends)
hero = Query(
name="hero",
arguments=[arg_episode],
fields=[
"name",
Field(
name="friends",
fields=["name"],
directives=[Directive(name="include", arguments=[arg_if])]
)
]
)
operation = Operation(
type="query",
name="Hero",
variables=[episode, withFriends],
queries=[hero]
)
print(operation.render())
"""
query Hero(
$episode: Episode
$withFriends: Boolean!
) {
hero(
episode: $episode
) {
name
friends @include(
if: $withFriends
) {
name
}
}
}
"""
You can find other examples in the documentation.
Metadata
Release files for graphql-query 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| graphql_query-1.4.0.tar.gz | 26.2 kB | Without provenance | Details for graphql_query-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graphql_query-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for graphql_query-1.4.0-py3-none-any.whl |
Total release size: 39.6 kB
Release files / graphql_query-1.4.0.tar.gz
| Download URL | graphql_query-1.4.0.tar.gz |
|---|---|
| Size | 26.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1cfe5eeaad8b0ed67ac3d9c4023ee9743851f98c6b2f673c67088cf42ebb57bb
|
|
BLAKE2b-256 checksum How to use checksums |
8b64377beef6c10b798f2ece54cfd3577db20102176c3a155469b92b4a3e3881
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.17
|
Release files / graphql_query-1.4.0-py3-none-any.whl
| Download URL | graphql_query-1.4.0-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
376ed550a7812425befbefb870daa21ce1696590fcb78c015215a43a5d7e51b7
|
|
BLAKE2b-256 checksum How to use checksums |
47edec732d18dd016eb4d4fa590e392d22dd35c93f26f17f709596deeb780497
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.17
|
Security for graphql-query 1.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.