{"id":25895458,"url":"https://github.com/diamondlightsource/graphql-ws-aiohttp","last_synced_at":"2025-03-02T22:31:43.664Z","repository":{"id":45638910,"uuid":"434270761","full_name":"DiamondLightSource/graphql-ws-aiohttp","owner":"DiamondLightSource","description":"A GraphQL WebSocket server and client to facilitate GraphQL queries, mutations and subscriptions over WebSocket","archived":false,"fork":false,"pushed_at":"2024-07-15T11:21:29.000Z","size":85,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-02-09T10:34:25.628Z","etag":null,"topics":["from-dls-controls"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DiamondLightSource.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-02T15:17:13.000Z","updated_at":"2024-07-15T11:21:34.000Z","dependencies_parsed_at":"2024-09-16T12:30:18.873Z","dependency_job_id":null,"html_url":"https://github.com/DiamondLightSource/graphql-ws-aiohttp","commit_stats":null,"previous_names":["dls-controls/graphql-ws-aiohttp"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiamondLightSource%2Fgraphql-ws-aiohttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiamondLightSource%2Fgraphql-ws-aiohttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiamondLightSource%2Fgraphql-ws-aiohttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiamondLightSource%2Fgraphql-ws-aiohttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DiamondLightSource","download_url":"https://codeload.github.com/DiamondLightSource/graphql-ws-aiohttp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241582515,"owners_count":19985845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["from-dls-controls"],"created_at":"2025-03-02T22:31:27.305Z","updated_at":"2025-03-02T22:31:43.654Z","avatar_url":"https://github.com/DiamondLightSource.png","language":"Python","readme":"graphql-ws-aiohttp\n===========================\n\n|code_ci| |coverage| |pypi_version| |license|\n\nPort of `graphql-ws-next`_ for `graphql-core v3`_.\n\nA GraphQL WebSocket server and client to facilitate GraphQL queries, mutations and subscriptions over WebSocket (for Python 3.6+).\nThis code is based on the current implementation of `subscriptions-transport-ws \u003chttps://github.com/apollographql/subscriptions-transport-ws\u003e`_.\n\n============== ==============================================================\nPyPI           ``pip install graphql-ws-aiohttp``\nSource code    https://github.com/dls-controls/graphql-ws-aiohttp\nChangelog      https://github.com/dls-controls/graphql-ws-aiohttp/blob/master/CHANGELOG.rst\n============== ==============================================================\n\n\nGetting Started\n===============\n\nStart by installing the package using pip:\n\n.. code: shell\n\n    pip install graphql-ws-next\n\nOr, by using your favorite package manager, like `Poetry \u003chttps://github.com/sdispater/poetry\u003e`_:\n\n.. code: shell\n\n    poetry add graphql-ws-next\n\n\nWith ``aiohttp``\n================\n\nUsage with ``aiohttp`` is simple:\n\n.. code: python\n\n    import aiohttp.web\n    import graphql_ws\n    from graphql_ws.aiohttp import AiohttpConnectionContext\n\n    async def handle_subscriptions(\n        request: aiohttp.web.Request\n    ) -\u003e aiohttp.web.WebSocketResponse:\n        wsr = aiohttp.web.WebSocketResponse(protocols=(graphql_ws.WS_PROTOCOL,))\n        request.app[\"websockets\"].add(wsr)\n        await wsr.prepare(request)\n        await request.app[\"subscription_server\"].handle(wsr, None)\n        request.app[\"websockets\"].remove(wsr)\n        return wsr\n\n    def make_app(schema: graphql.GraphQLSchema) -\u003e aiohttp.web.Application:\n        app = aiohttp.web.Application()\n        app.router.add_get(\"/subscriptions\", handle_subscriptions)\n\n        app[\"subscription_server\"] = graphql_ws.SubscriptionServer(\n            schema, AiohttpConnectionContext\n        )\n        app[\"websockets\"] = set()\n\n        async def on_shutdown(app):\n            await asyncio.wait([wsr.close() for wsr in app[\"websockets\"]])\n\n        app.on_shutdown.append(on_shutdown)\n        return app\n\n    if __name__ == '__main__':\n        app = make_app(schema)  # you supply your GraphQLSchema\n        aiohttp.web.run_app()\n\n\nFor other frameworks\n====================\n\nAdding support for other web frameworks is simple.\nA framework must provide a concrete implementation of ``graphql_ws.abc.AbstractConnectionContext``, and then it's ready to use with the ``SubscriptionServer``.\n\nUsage\n=====\n\nUsing `apollo-link-ws \u003chttps://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-ws\u003e`_ you can opt to use websockets for queries and mutations in addition to subscriptions.\n\nUse it with GraphiQL\n====================\n\nLook in the `demo\u003c./demo\u003e_` directory to see usage examples for GraphiQL.\nDue to the implementation of the javascript client for GraphiQL (`GraphiQL-Subscriptions-Fetcher \u003chttps://github.com/apollographql/GraphiQL-Subscriptions-Fetcher\u003e`_), queries and mutations will not be handled over websocket.\n\nContributing\n============\n\nThis project uses `Poetry \u003chttps://github.com/sdispater/poetry\u003e`_, so to contribute, simply fork and clone this repository, and then set up your virtual environment using:\n\n.. code: shell:\n\n    cd graphql-ws-next\n    poetry develop .\n\nIf you don't yet have Poetry installed, please follow the `documentation for installation \u003chttps://poetry.eustace.io/docs/#installation\u003e`_.\n\nCode formatting is done via `black \u003chttps://github.com/ambv/black\u003e`_, and code should be well-typed using `mypy \u003chttps://github.com/python/mypy\u003e`_.\n\n\nLicense\n=======\nThis package is licensed under the MIT License.\n\n.. _`graphql-ws-next`: https://github.com/dfee/graphql-ws-next\n.. _`graphql-core v3`: https://github.com/graphql-python/graphql-core\n\n.. |code_ci| image:: https://github.com/dls-controls/graphql-ws-aiohttp/workflows/Code%20CI/badge.svg?branch=master\n    :target: https://github.com/dls-controls/graphql-ws-aiohttp/actions?query=workflow%3A%22Code+CI%22\n    :alt: Code CI\n\n.. |coverage| image:: https://codecov.io/gh/dls-controls/graphql-ws-aiohttp/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/dls-controls/graphql-ws-aiohttp\n    :alt: Test Coverage\n\n.. |pypi_version| image:: https://img.shields.io/pypi/v/graphql-ws-aiohttp.svg\n    :target: https://pypi.org/project/graphql-ws-aiohttp\n    :alt: Latest PyPI version\n\n.. |license| image:: https://img.shields.io/badge/License-Apache%202.0-blue.svg\n    :target: https://opensource.org/licenses/Apache-2.0\n    :alt: Apache License\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiamondlightsource%2Fgraphql-ws-aiohttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiamondlightsource%2Fgraphql-ws-aiohttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiamondlightsource%2Fgraphql-ws-aiohttp/lists"}