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)
- 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
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, playground=True))
GraphQLApp
GraphQLApp(schema, [options...])
- (required)
schema
: graphene.Schema - (optional)
playground
(default:True
) - (optional)
context_value
(default:None
) - (optional)
root_value
(default:None
) - (optional)
middleware
(default:None
) - (optional)
playground_options
: (default:{}
)
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.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd490dab88339a5d8a420e1710354f3c8c8594b3a5185d459fa079fcfd531339 |
|
MD5 | 5aa49bda9f97f027502f78fedd9417ea |
|
BLAKE2b-256 | 5d924179b22ae9a3fc548fc651c2097412d7c61efc8b4976dcc32cd46c3f4f0e |
Close
Hashes for starlette_graphene3-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d9a65bacb1f7efb92247cf767e952ac1a96f2a5eeb9630d59abd907b7a4851a |
|
MD5 | 59773d142ae0e8561893086ca9ae2ae2 |
|
BLAKE2b-256 | c5044efb98961a26592db3654763498f00b8fbcb91702a5438024ee7cb8ff494 |