Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a chalice integration, documentation and tests
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
Showing
9 changed files
with
148 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Oops, something went wrong.