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: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.3.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91bdad698ce2a9324bda54b4116adcece7352191affb64829cf704b07ecfa252 |
|
MD5 | bd18d955e1dd70e732926f5386b50c1b |
|
BLAKE2b-256 | 682377d50d1ae886125fccd737ba7d032b39a0ba8926e4d66ad8b89454ab882a |
Close
Hashes for starlette_graphene3-0.3.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7354198539b5bad346a68ecc8ff6fb5d905fa4c4c0ed01d00845b075bcce826c |
|
MD5 | 68816f94a61bcd5328bd380d3d96acf7 |
|
BLAKE2b-256 | a2d820bb30843c3891635e1058a119d1503105f81dd9e42f363e8295c0493a57 |