GraphQL Adapter
The graphql_adapter module is a Python package that simplifies interactions with GraphQL servers. It abstracts away some of the pain points of using Python with GraphQL by providing a streamlined, asynchronous interface for sending GraphQL queries and mutations.
Installation
pip install graphql-adapter
Usage
The graphql_adapter module exports a single async function graphql_request.
Here's an example of how to use it:
from graphql_adapter import graphql_request
# A simple example query
query = """
query {
test {
field1
field2
}
}
"""
variables = {"key1": "value1", "key2": "value2"}
response = await graphql_request(
query=query,
variables=variables,
graphql_server="http://localhost:4000/graphql",
query_path="./gql"
)
print(response)
Function Parameters
query: The name of the GraphQL query or mutation. This should match the name of a.gqlfile in yourquery_pathdirectory.variables: A dictionary of variables to pass to the GraphQL query or mutation.graphql_server: The URL of your GraphQL server.headers(optional): A dictionary of headers to include in the request. Default is an empty dictionary.query_path(optional): The relative path to the directory containing your.gqlfiles. Default is./gql.
Return Values
The function will return the data from the GraphQL server's response. This data is processed as follows:
- If the server returns an error, the function will raise an exception.
- If the query was a mutation and the data contains a
returningfield, the function will return the value of thereturningfield. - If the data is a list, the function will return the first item in the list.
- If the data is a dictionary with only one item, the function will return that item.
Please note that due to the async nature of the function, you should await the function call to get the response.
Metadata
Release files for graphql-adapter 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| graphql_adapter-0.0.2.tar.gz | 2.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| graphql_adapter-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.1 kB
Release files / graphql_adapter-0.0.2.tar.gz
| Download URL | graphql_adapter-0.0.2.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
75bb02c8f447a40c933cf9fc34b5bb70fee162e16e4f49771fe6d2156ecc860a
|
|
BLAKE2b-256 checksum How to use checksums |
8fbccd2da51cfb439683e5d58a8fb0f0c7009abbd661b28ec8fc7b819bd2e331
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Release files / graphql_adapter-0.0.2-py3-none-any.whl
| Download URL | graphql_adapter-0.0.2-py3-none-any.whl |
|---|---|
| Size | 2.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6e876c2e3a6a5a0667531b6ebd4f656960bb116b3cc61ba0392c4ee83dd5d26e
|
|
BLAKE2b-256 checksum How to use checksums |
5bdad643e0507ede82798de99ba85fd29a6c9df0ef5c707148d82ee24ef6c563
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|