starlette-graphene3
A simple ASGI app for using Graphene v3 with Starlette / FastAPI.
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 — Python GraphQL Engine by dailymotion
- tartiflette-asgi
Installation
pip3 install -U starlette-graphene3
Example
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...])
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,
):
Metadata
Release files for starlette-graphene3 0.6.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 |
|---|---|---|---|---|
| starlette-graphene3-0.6.0.tar.gz | 9.3 kB | Without provenance | Details for starlette-graphene3-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| starlette_graphene3-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for starlette_graphene3-0.6.0-py3-none-any.whl |
Total release size: 18.3 kB
Release files / starlette-graphene3-0.6.0.tar.gz
| Download URL | starlette-graphene3-0.6.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cbe4ca397b24013d5b3161dd4144e9b3e836af0ef01a625bb6113946fc7d36d9
|
|
BLAKE2b-256 checksum How to use checksums |
a93cf216ea04650e56de248bc6995ee87652e7002693198d8edc1076f650c29c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.9.12 Darwin/21.4.0
|
Release files / starlette_graphene3-0.6.0-py3-none-any.whl
| Download URL | starlette_graphene3-0.6.0-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
193ff6e0900a3259ccf76b534cd84eaa2feefcaf92652b3b0f54fc784c80ce14
|
|
BLAKE2b-256 checksum How to use checksums |
994064647d16f04ffdaf6cb502f73e2137c5f05cd3b0e521ade85a91aae4fe5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.9.12 Darwin/21.4.0
|
Security for starlette-graphene3 0.6.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.