Use Graphene v3 on Starlette
Project description
starlette_graphene3
An ASGI app for Graphene v3 (version 3). This can replace starlette.graphql.GraphQLApp
that is made for Graphene v2.
It supports:
- WebSockets (Subscriptions)
- File uploading (https://github.com/jaydenseric/graphql-multipart-request-spec)
- GraphQL Playground
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))
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.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 367a7de1a716991b11b69001e21e3a1ada80d9ca8d667d9cfb63ecfc90bfdd51 |
|
MD5 | 83b8a66451eb6a60dfaec0b41edb0058 |
|
BLAKE2b-256 | 499c310b0518a5887f0bc996508361b8a08afb541d71042b458376121259e83a |
Close
Hashes for starlette_graphene3-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0b9b7ffb7f2dc2c47d1498eb0383b5dec414976d151f5ab7cd5f4ff13da7421 |
|
MD5 | 7fc8fb3e98bd3c69126e05c4bb5cbbca |
|
BLAKE2b-256 | 7c245985dbcd7d8960e7b7e81033bc8415d223d3a2f2c353c323c2efe4a7d743 |