Chalice
Strawberry comes with an AWS Chalice integration. It provides a view that you can use to serve your GraphQL schema:
Use the Chalice CLI to create a new project
chalice new-project badger-projectcd badger-project
Replace the contents of app.py with the following:
from chalice import Chalicefrom chalice.app import Request, Response
import strawberryfrom strawberry.chalice.views import GraphQLView app = Chalice(app_name="BadgerProject")
@strawberry.typeclass Query: @strawberry.field def greetings(self) -> str: return "hello from the illustrious stack badger"
@strawberry.typeclass Mutation: @strawberry.mutation def echo(self, string_to_echo: str) -> str: return string_to_echo schema = strawberry.Schema(query=Query, mutation=Mutation)view = GraphQLView(schema=schema, render_graphiql=True)
@app.route("/graphql", methods=["GET", "POST"], content_types=["application/json"])def handle_graphql() -> Response: request: Request = app.current_request result = view.execute_request(request) return result
And then run chalice local
to start the localhost
chalice local
The GraphiQL interface can then be opened in your browser on http://localhost:8000/graphql
Options
The GraphQLView
accepts two options at the moment:
schema
: mandatory, the schema created bystrawberry.Schema
.graphiql
: optional, defaults toTrue
, whether to enable the GraphiQL interface.