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))
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.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfa00a97b47999088ec45f2cbc37d69e0f5a1b395a3ca0cd4fb32df6a9c50b42 |
|
MD5 | 62df42ccbf07b53f9db6a9b4d3c3cedd |
|
BLAKE2b-256 | 07e89ee2432f4545caaabdb9f58ee2bf0d435077dcdd70afe4aa99c76e5f1e89 |
Close
Hashes for starlette_graphene3-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99f61eda228bbd10da69aa9447e96dd994892ee14d7eae1f7a764997a7e4aec1 |
|
MD5 | bfdc6e0cd68563a8d0b6505d361f3cf2 |
|
BLAKE2b-256 | e539020e47c6ab3b3fb7c3991a4d7cc51b25118800aae991c71b4168dfa6a090 |