starlette-graphene3


Namestarlette-graphene3 JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://github.com/ciscorn/starlette-graphene3
SummaryUse Graphene v3 on Starlette
upload_time2022-06-01 13:17:24
maintainer
docs_urlNone
authorTaku Fukada
requires_python>=3.7,<4.0
licenseMIT
keywords graphene graphql asgi starlette
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # starlette-graphene3

A simple ASGI app for using [Graphene](https://github.com/graphql-python/graphene) v3 with [Starlette](https://github.com/encode/starlette) / [FastAPI](https://github.com/tiangolo/fastapi).

![Test](https://github.com/ciscorn/starlette-graphene3/actions/workflows/test.yml/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/ciscorn/starlette-graphene3/branch/master/graph/badge.svg)](https://codecov.io/gh/ciscorn/starlette-graphene3)
[![pypi package](https://img.shields.io/pypi/v/starlette-graphene3?color=%2334D058&label=pypi%20package)](https://pypi.org/project/starlette-graphene3)

It supports:

- Queries and Mutations (over HTTP or WebSocket)
- Subscriptions (over WebSocket)
- File uploading (https://github.com/jaydenseric/graphql-multipart-request-spec)
- GraphiQL / GraphQL Playground

File uploading requires `python-multipart` to be installed.
## Alternatives

- [tartiflette](https://github.com/tartiflette/tartiflette) &mdash; Python GraphQL Engine by dailymotion
- [tartiflette-asgi](https://github.com/tartiflette/tartiflette-asgi)


## Installation

```bash
pip3 install -U starlette-graphene3
```


## Example

```python
import asyncio

import graphene
from graphene_file_upload.scalars import Upload

from starlette.applications import Starlette
from starlette_graphene3 import GraphQLApp, make_graphiql_handler


class User(graphene.ObjectType):
    id = graphene.ID()
    name = graphene.String()


class Query(graphene.ObjectType):
    me = graphene.Field(User)

    def resolve_me(root, info):
        return {"id": "john", "name": "John"}


class FileUploadMutation(graphene.Mutation):
    class Arguments:
        file = Upload(required=True)

    ok = graphene.Boolean()

    def mutate(self, info, file, **kwargs):
        return FileUploadMutation(ok=True)


class Mutation(graphene.ObjectType):
    upload_file = FileUploadMutation.Field()


class Subscription(graphene.ObjectType):
    count = graphene.Int(upto=graphene.Int())

    async def subscribe_count(root, info, upto=3):
        for i in range(upto):
            yield i
            await asyncio.sleep(1)


app = Starlette()
schema = graphene.Schema(query=Query, mutation=Mutation, subscription=Subscription)

app.mount("/", GraphQLApp(schema, on_get=make_graphiql_handler()))  # Graphiql IDE

# app.mount("/", GraphQLApp(schema, on_get=make_playground_handler()))  # Playground IDE
# app.mount("/", GraphQLApp(schema)) # no IDE
```

## GraphQLApp

`GraphQLApp(schema, [options...])`

```python
class GraphQLApp:
    def __init__(
        self,
        schema: graphene.Schema,  # Requied
        *,
        # Optional keyword parameters
        on_get: Optional[
            Callable[[Request], Union[Response, Awaitable[Response]]]
        ] = None,  # optional HTTP handler for GET requests
        context_value: ContextValue = None,
        root_value: RootValue = None,
        middleware: Optional[Middleware] = None,
        error_formatter: Callable[[GraphQLError], Dict[str, Any]] = format_error,
        logger_name: Optional[str] = None,
        playground: bool = False,  # deprecating
        execution_context_class: Optional[Type[ExecutionContext]] = None,
    ):
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ciscorn/starlette-graphene3",
    "name": "starlette-graphene3",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "graphene,graphql,asgi,starlette",
    "author": "Taku Fukada",
    "author_email": "naninunenor@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a9/3c/f216ea04650e56de248bc6995ee87652e7002693198d8edc1076f650c29c/starlette-graphene3-0.6.0.tar.gz",
    "platform": null,
    "description": "# starlette-graphene3\n\nA simple ASGI app for using [Graphene](https://github.com/graphql-python/graphene) v3 with [Starlette](https://github.com/encode/starlette) / [FastAPI](https://github.com/tiangolo/fastapi).\n\n![Test](https://github.com/ciscorn/starlette-graphene3/actions/workflows/test.yml/badge.svg?branch=master)\n[![codecov](https://codecov.io/gh/ciscorn/starlette-graphene3/branch/master/graph/badge.svg)](https://codecov.io/gh/ciscorn/starlette-graphene3)\n[![pypi package](https://img.shields.io/pypi/v/starlette-graphene3?color=%2334D058&label=pypi%20package)](https://pypi.org/project/starlette-graphene3)\n\nIt supports:\n\n- Queries and Mutations (over HTTP or WebSocket)\n- Subscriptions (over WebSocket)\n- File uploading (https://github.com/jaydenseric/graphql-multipart-request-spec)\n- GraphiQL / GraphQL Playground\n\nFile uploading requires `python-multipart` to be installed.\n## Alternatives\n\n- [tartiflette](https://github.com/tartiflette/tartiflette) &mdash; Python GraphQL Engine by dailymotion\n- [tartiflette-asgi](https://github.com/tartiflette/tartiflette-asgi)\n\n\n## Installation\n\n```bash\npip3 install -U starlette-graphene3\n```\n\n\n## Example\n\n```python\nimport asyncio\n\nimport graphene\nfrom graphene_file_upload.scalars import Upload\n\nfrom starlette.applications import Starlette\nfrom starlette_graphene3 import GraphQLApp, make_graphiql_handler\n\n\nclass User(graphene.ObjectType):\n    id = graphene.ID()\n    name = graphene.String()\n\n\nclass Query(graphene.ObjectType):\n    me = graphene.Field(User)\n\n    def resolve_me(root, info):\n        return {\"id\": \"john\", \"name\": \"John\"}\n\n\nclass FileUploadMutation(graphene.Mutation):\n    class Arguments:\n        file = Upload(required=True)\n\n    ok = graphene.Boolean()\n\n    def mutate(self, info, file, **kwargs):\n        return FileUploadMutation(ok=True)\n\n\nclass Mutation(graphene.ObjectType):\n    upload_file = FileUploadMutation.Field()\n\n\nclass Subscription(graphene.ObjectType):\n    count = graphene.Int(upto=graphene.Int())\n\n    async def subscribe_count(root, info, upto=3):\n        for i in range(upto):\n            yield i\n            await asyncio.sleep(1)\n\n\napp = Starlette()\nschema = graphene.Schema(query=Query, mutation=Mutation, subscription=Subscription)\n\napp.mount(\"/\", GraphQLApp(schema, on_get=make_graphiql_handler()))  # Graphiql IDE\n\n# app.mount(\"/\", GraphQLApp(schema, on_get=make_playground_handler()))  # Playground IDE\n# app.mount(\"/\", GraphQLApp(schema)) # no IDE\n```\n\n## GraphQLApp\n\n`GraphQLApp(schema, [options...])`\n\n```python\nclass GraphQLApp:\n    def __init__(\n        self,\n        schema: graphene.Schema,  # Requied\n        *,\n        # Optional keyword parameters\n        on_get: Optional[\n            Callable[[Request], Union[Response, Awaitable[Response]]]\n        ] = None,  # optional HTTP handler for GET requests\n        context_value: ContextValue = None,\n        root_value: RootValue = None,\n        middleware: Optional[Middleware] = None,\n        error_formatter: Callable[[GraphQLError], Dict[str, Any]] = format_error,\n        logger_name: Optional[str] = None,\n        playground: bool = False,  # deprecating\n        execution_context_class: Optional[Type[ExecutionContext]] = None,\n    ):\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Use Graphene v3 on Starlette",
    "version": "0.6.0",
    "project_urls": {
        "Homepage": "https://github.com/ciscorn/starlette-graphene3",
        "Repository": "https://github.com/ciscorn/starlette-graphene3"
    },
    "split_keywords": [
        "graphene",
        "graphql",
        "asgi",
        "starlette"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "994064647d16f04ffdaf6cb502f73e2137c5f05cd3b0e521ade85a91aae4fe5d",
                "md5": "b7d84241c5d3d0ff53c6af9beaabce52",
                "sha256": "193ff6e0900a3259ccf76b534cd84eaa2feefcaf92652b3b0f54fc784c80ce14"
            },
            "downloads": -1,
            "filename": "starlette_graphene3-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b7d84241c5d3d0ff53c6af9beaabce52",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 8954,
            "upload_time": "2022-06-01T13:17:26",
            "upload_time_iso_8601": "2022-06-01T13:17:26.140944Z",
            "url": "https://files.pythonhosted.org/packages/99/40/64647d16f04ffdaf6cb502f73e2137c5f05cd3b0e521ade85a91aae4fe5d/starlette_graphene3-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a93cf216ea04650e56de248bc6995ee87652e7002693198d8edc1076f650c29c",
                "md5": "d40834f268f05bd237c3af4c41e20637",
                "sha256": "cbe4ca397b24013d5b3161dd4144e9b3e836af0ef01a625bb6113946fc7d36d9"
            },
            "downloads": -1,
            "filename": "starlette-graphene3-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d40834f268f05bd237c3af4c41e20637",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 9318,
            "upload_time": "2022-06-01T13:17:24",
            "upload_time_iso_8601": "2022-06-01T13:17:24.523808Z",
            "url": "https://files.pythonhosted.org/packages/a9/3c/f216ea04650e56de248bc6995ee87652e7002693198d8edc1076f650c29c/starlette-graphene3-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-06-01 13:17:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ciscorn",
    "github_project": "starlette-graphene3",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "starlette-graphene3"
}
        
Elapsed time: 0.24201s