Skip to content

Commit

Permalink
Added a chalice integration, documentation and tests
Browse files Browse the repository at this point in the history
Updated release notes and added chalice as a dev dependency
Added catching the json_body value error and removed unused type error
TypeError must be caught here as they payload might not be json
Removed the separate get and post methods
Added the chalice integration to the docs
Update docs/integrations/chalice.md
Added the suggestion to remove $ from the shell commands to be consistent

Co-authored-by: ignormies <bryce.beagle@gmail.com>
Update docs/integrations/chalice.md

Co-authored-by: ignormies <bryce.beagle@gmail.com>
Update strawberry/chalice/views.py

Co-authored-by: ignormies <bryce.beagle@gmail.com>
Update docs/integrations/chalice.md

Co-authored-by: ignormies <bryce.beagle@gmail.com>
Update docs/integrations/chalice.md

Co-authored-by: ignormies <bryce.beagle@gmail.com>
Update docs/integrations/chalice.md

Co-authored-by: ignormies <bryce.beagle@gmail.com>
Added a response type to the documentation
  • Loading branch information
mcsheehan committed Jul 14, 2021
1 parent bf5485d commit 5c360a5
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 95 deletions.
5 changes: 5 additions & 0 deletions RELEASE.md
@@ -0,0 +1,5 @@
Release type: patch

Added support for aws chalice, as well as unit tests and documentation, which illustrates example usage.
The options available for the graphiql view are listed in the documentation.

1 change: 1 addition & 0 deletions docs/README.md
Expand Up @@ -49,6 +49,7 @@
- [Django](./integrations/django.md)
- [Flask](./integrations/flask.md)
- [Sanic](./integrations/sanic.md)
- [Chalice](./integrations/chalice.md)
- [Pydantic **experimental**](./integrations/pydantic.md)

## Operations
Expand Down
66 changes: 66 additions & 0 deletions docs/integrations/chalice.md
@@ -0,0 +1,66 @@
---
title: Chalice
---

# 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
```shell
chalice new-project badger-project
cd badger-project
```

Replace the contents of app.py with the following:

```python
from chalice import Chalice
from chalice.app import Request, Response

import strawberry
from strawberry.chalice.views import GraphQLView

app = Chalice(app_name="BadgerProject")


@strawberry.type
class Query:
@strawberry.field
def greetings(self) -> str:
return "hello from the illustrious stack badger"


@strawberry.type
class 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
```shell
chalice local
```

GraphiQL will be hosted on localhost:8000/graphql


## Options

The `GraphQLView` accepts two options at the moment:

- `schema`: mandatory, the schema created by `strawberry.Schema`.
- `graphiql`: optional, defaults to `True`, whether to enable the GraphiQL interface.

0 comments on commit 5c360a5

Please sign in to comment.