Use Graphene v3 on Starlette
Project description
starlette-graphene3
A simple ASGI app for using Graphene v3 with Starlette.
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
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...])
- (required)
schema
: graphene.Schema - (optional)
on_get
(default:None
): A request handler for HTTP GET request - (optional)
context_value
(default:None
) - (optional)
root_value
(default:None
) - (optional)
middleware
(default:None
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for starlette-graphene3-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47ae12eca910afe138fd124eef96f0d38cb0d43b0e002b29116aa2077c34eac6 |
|
MD5 | fccbf0b97876e30c1792e0c289f7e805 |
|
BLAKE2b-256 | c98dfe92c8e55b1770124fb3137b7718d56907f428ff76cdb65f7c6b61541005 |
Close
Hashes for starlette_graphene3-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3be282f02adababe1660865329cf34fe7c41e7ffe65dc83374faea20e6608610 |
|
MD5 | 0f2eb2f742ce68d5b7c324d1e8f3cc29 |
|
BLAKE2b-256 | e9f242cd843342322a172103247f18cb4a54fcbb5ebc42e960e4cb2d86397446 |