aiographql-client


Nameaiographql-client JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/abn/aiographql-client
SummaryAn asyncio GraphQL client built on top of aiohttp and graphql-core-next
upload_time2024-02-22 02:45:50
maintainer
docs_urlNone
authorArun Neelicattu
requires_python>=3.8,<4.0
licenseMIT
keywords aiohttp asyncio client graphql graphql-core graphql-core-next
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Asynchronous GraphQL Client
[![PyPI version](https://badge.fury.io/py/aiographql-client.svg)](https://badge.fury.io/py/aiographql-client)
[![Python Versions](https://img.shields.io/pypi/pyversions/aiographql-client)](https://pypi.org/project/aiographql-client/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Documentation Status](https://readthedocs.org/projects/aiographql-client/badge/?version=latest)](https://aiographql-client.readthedocs.io/en/latest/?badge=latest)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=abn_aiographql-client&metric=alert_status)](https://sonarcloud.io/dashboard?id=abn_aiographql-client)
[![](https://github.com/abn/aiographql-client/workflows/Test%20Suite/badge.svg)](https://github.com/abn/aiographql-client/actions?query=workflow%3A%22Test+Suite%22)

An asynchronous GraphQL client built on top of aiohttp and graphql-core-next. The client by default introspects schemas and validates all queries prior to dispatching to the server.

## Documentation

For the most recent project documentation, you can visit https://aiographql-client.readthedocs.io/.

## Installation
`pip install aiographql-client`

## Example Usage
Here are some example usages of this client implementation. For more examples, and advanced scenarios,
see [Usage Examples](https://aiographql-client.readthedocs.io/en/latest/examples.html) section in
the documentation.

### Simple Query
```py
async def get_logged_in_username(token: str) -> GraphQLResponse:
    client = GraphQLClient(
        endpoint="https://api.github.com/graphql",
        headers={"Authorization": f"Bearer {token}"},
    )
    request = GraphQLRequest(
        query="""
            query {
              viewer {
                login
              }
            }
        """
    )
    return await client.query(request=request)
```

```console
>>> import asyncio
>>> response = asyncio.run(get_logged_in_username("<TOKEN FROM GITHUB GRAPHQL API>"))
>>> response.data
{'viewer': {'login': 'username'}}
```

### Query Subscription
```py
async def print_city_updates(client: GraphQLClient, city: str) -> None:
    request = GraphQLRequest(
        query="""
            subscription ($city:String!) {
              city(where: {name: {_eq: $city}}) {
                description
                id
              }
            }
        """,
        variables={"city": city},
    )
    # subscribe to data and error events, and print them
    await client.subscribe(
        request=request, on_data=print, on_error=print, wait=True
    )
```

For custom event specific callback registration, see [Callback Registry Documentation](https://aiographql-client.readthedocs.io/en/latest/examples.html#callback-registry).

### Query Validation Failures
If your query is invalid, thanks to graphql-core-next, we get a detailed exception in the traceback.

```
aiographql.client.exceptions.GraphQLClientValidationException: Query validation failed

Cannot query field 'ids' on type 'chatbot'. Did you mean 'id'?

GraphQL request (4:13)
3:           chatbot {
4:             ids, bot_names
               ^
5:           }

Cannot query field 'bot_names' on type 'chatbot'. Did you mean 'bot_name' or 'bot_language'?

GraphQL request (4:18)
3:           chatbot {
4:             ids, bot_names
                    ^
5:           }

```

### Query Variables & Operations
Support for multi-operation requests and variables is available via the client. For example,
the following request contains multiple operations. The instance specifies default values to use.

```py
request = GraphQLRequest(
    query="""
    query get_bot_created($id: Int) {
      chatbot(where: {id: {_eq: $id}}) {
        id, created
      }
    }
    query get_bot_name($id: Int) {
      chatbot(where: {id: {_eq: $id}}) {
        id, bot_name
      }
    }
    """,
    variables={"id": 109},
    operation="get_bot_name"
)
```

The default values can be overridden at the time of making the request if required.

```py
await client.query(request=request, variables={"id": 20}, operation="get_bot_created")
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/abn/aiographql-client",
    "name": "aiographql-client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "aiohttp,asyncio,client,graphql,graphql-core,graphql-core-next",
    "author": "Arun Neelicattu",
    "author_email": "arun.neelicattu@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0d/ee/f070997ed988a6e00e7415bc2cb947321236a3af253ebab10db9656d421f/aiographql_client-1.1.0.tar.gz",
    "platform": null,
    "description": "# Asynchronous GraphQL Client\n[![PyPI version](https://badge.fury.io/py/aiographql-client.svg)](https://badge.fury.io/py/aiographql-client)\n[![Python Versions](https://img.shields.io/pypi/pyversions/aiographql-client)](https://pypi.org/project/aiographql-client/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Documentation Status](https://readthedocs.org/projects/aiographql-client/badge/?version=latest)](https://aiographql-client.readthedocs.io/en/latest/?badge=latest)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=abn_aiographql-client&metric=alert_status)](https://sonarcloud.io/dashboard?id=abn_aiographql-client)\n[![](https://github.com/abn/aiographql-client/workflows/Test%20Suite/badge.svg)](https://github.com/abn/aiographql-client/actions?query=workflow%3A%22Test+Suite%22)\n\nAn asynchronous GraphQL client built on top of aiohttp and graphql-core-next. The client by default introspects schemas and validates all queries prior to dispatching to the server.\n\n## Documentation\n\nFor the most recent project documentation, you can visit https://aiographql-client.readthedocs.io/.\n\n## Installation\n`pip install aiographql-client`\n\n## Example Usage\nHere are some example usages of this client implementation. For more examples, and advanced scenarios,\nsee [Usage Examples](https://aiographql-client.readthedocs.io/en/latest/examples.html) section in\nthe documentation.\n\n### Simple Query\n```py\nasync def get_logged_in_username(token: str) -> GraphQLResponse:\n    client = GraphQLClient(\n        endpoint=\"https://api.github.com/graphql\",\n        headers={\"Authorization\": f\"Bearer {token}\"},\n    )\n    request = GraphQLRequest(\n        query=\"\"\"\n            query {\n              viewer {\n                login\n              }\n            }\n        \"\"\"\n    )\n    return await client.query(request=request)\n```\n\n```console\n>>> import asyncio\n>>> response = asyncio.run(get_logged_in_username(\"<TOKEN FROM GITHUB GRAPHQL API>\"))\n>>> response.data\n{'viewer': {'login': 'username'}}\n```\n\n### Query Subscription\n```py\nasync def print_city_updates(client: GraphQLClient, city: str) -> None:\n    request = GraphQLRequest(\n        query=\"\"\"\n            subscription ($city:String!) {\n              city(where: {name: {_eq: $city}}) {\n                description\n                id\n              }\n            }\n        \"\"\",\n        variables={\"city\": city},\n    )\n    # subscribe to data and error events, and print them\n    await client.subscribe(\n        request=request, on_data=print, on_error=print, wait=True\n    )\n```\n\nFor custom event specific callback registration, see [Callback Registry Documentation](https://aiographql-client.readthedocs.io/en/latest/examples.html#callback-registry).\n\n### Query Validation Failures\nIf your query is invalid, thanks to graphql-core-next, we get a detailed exception in the traceback.\n\n```\naiographql.client.exceptions.GraphQLClientValidationException: Query validation failed\n\nCannot query field 'ids' on type 'chatbot'. Did you mean 'id'?\n\nGraphQL request (4:13)\n3:           chatbot {\n4:             ids, bot_names\n               ^\n5:           }\n\nCannot query field 'bot_names' on type 'chatbot'. Did you mean 'bot_name' or 'bot_language'?\n\nGraphQL request (4:18)\n3:           chatbot {\n4:             ids, bot_names\n                    ^\n5:           }\n\n```\n\n### Query Variables & Operations\nSupport for multi-operation requests and variables is available via the client. For example,\nthe following request contains multiple operations. The instance specifies default values to use.\n\n```py\nrequest = GraphQLRequest(\n    query=\"\"\"\n    query get_bot_created($id: Int) {\n      chatbot(where: {id: {_eq: $id}}) {\n        id, created\n      }\n    }\n    query get_bot_name($id: Int) {\n      chatbot(where: {id: {_eq: $id}}) {\n        id, bot_name\n      }\n    }\n    \"\"\",\n    variables={\"id\": 109},\n    operation=\"get_bot_name\"\n)\n```\n\nThe default values can be overridden at the time of making the request if required.\n\n```py\nawait client.query(request=request, variables={\"id\": 20}, operation=\"get_bot_created\")\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An asyncio GraphQL client built on top of aiohttp and graphql-core-next",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/abn/aiographql-client",
        "Repository": "https://github.com/abn/aiographql-client"
    },
    "split_keywords": [
        "aiohttp",
        "asyncio",
        "client",
        "graphql",
        "graphql-core",
        "graphql-core-next"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b1c039955d3f78aa328b62cc80e69b6339675ecee3b9d25035b477f756e8a4a",
                "md5": "f433bd5e245ee0cc1710b28527479500",
                "sha256": "67b2d92086558d07c43db8071a9b9a328df7786b72d172ce7dddff4ddefa52aa"
            },
            "downloads": -1,
            "filename": "aiographql_client-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f433bd5e245ee0cc1710b28527479500",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 14890,
            "upload_time": "2024-02-22T02:45:45",
            "upload_time_iso_8601": "2024-02-22T02:45:45.112749Z",
            "url": "https://files.pythonhosted.org/packages/5b/1c/039955d3f78aa328b62cc80e69b6339675ecee3b9d25035b477f756e8a4a/aiographql_client-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0deef070997ed988a6e00e7415bc2cb947321236a3af253ebab10db9656d421f",
                "md5": "7060e7176d9382880818b12c96ba9cfa",
                "sha256": "9ea7a03dd0f1bf4e034234b64064ca39608dea188dafe592752fb34092421a41"
            },
            "downloads": -1,
            "filename": "aiographql_client-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7060e7176d9382880818b12c96ba9cfa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 13767,
            "upload_time": "2024-02-22T02:45:50",
            "upload_time_iso_8601": "2024-02-22T02:45:50.080349Z",
            "url": "https://files.pythonhosted.org/packages/0d/ee/f070997ed988a6e00e7415bc2cb947321236a3af253ebab10db9656d421f/aiographql_client-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-22 02:45:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "abn",
    "github_project": "aiographql-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aiographql-client"
}
        
Elapsed time: 0.18520s