Skip to main content

Adds GraphQL support to your Chalice application

Project description

Chalice-GraphQL

Adds GraphQL support to your Chalice application.

Based on [flask-graphql] by Syrus Akbary and [aiohttp-graphql] by Devin Fee.

travis coveralls

Usage

Add the GraphQLView from chalice_graphql to dispatch requests for your desired route(s)

from chalice import Chalice
from chalice_graphql import GraphQLView

from schema import schema

app = Chalice(app_name='helloworld')

@app.route(
    '/graphql',
    methods=['GET', 'POST'],
    content_types=['application/graphql', 'application/json', 'application/x-www-form-urlencoded']
)
def graphql():
    gql_view = GraphQLView(schema=schema, graphiql=True)
    return gql_view.dispatch_request(app.current_request)

# Optional, for adding batch query support (used in Apollo-Client)
@app.route(
    '/graphql/batch',
    methods=['GET', 'POST'],
    content_types=['application/graphql', 'application/json', 'application/x-www-form-urlencoded']
)
def graphql_batch():
    gql_view = GraphQLView(schema=schema, batch=True)
    return gql_view.dispatch_request(app.current_request)

This will add /graphql endpoint to your app and enable the GraphiQL IDE.

Supported options for GraphQLView

  • schema: The GraphQLSchema object that you want the view to execute when it gets a valid request.
  • context: A value to pass as the context_value to graphql execute function. By default is set to dict with request object at key request.
  • root_value: The root_value you want to provide to graphql execute.
  • pretty: Whether or not you want the response to be pretty printed JSON.
  • graphiql: If True, may present GraphiQL when loaded directly from a browser (a useful tool for debugging and exploration).
  • graphiql_version: The graphiql version to load. Defaults to "1.0.3".
  • graphiql_template: Inject a Jinja template string to customize GraphiQL.
  • graphiql_html_title: The graphiql title to display. Defaults to "GraphiQL".
  • batch: Set the GraphQL view as batch (for using in Apollo-Client or ReactRelayNetworkLayer)
  • middleware: A list of graphql middlewares.
  • encode: the encoder to use for responses (sensibly defaults to graphql_server.json_encode).
  • format_error: the error formatter to use for responses (sensibly defaults to graphql_server.default_format_error.
  • subscriptions: The GraphiQL socket endpoint for using subscriptions in graphql-ws.
  • headers: An optional GraphQL string to use as the initial displayed request headers, if not provided, the stored headers will be used.
  • default_query: An optional GraphQL string to use when no query is provided and no stored query exists from a previous session. If not provided, GraphiQL will use its own default query.
  • header_editor_enabled: An optional boolean which enables the header editor when true. Defaults to false.
  • should_persist_headers: An optional boolean which enables to persist headers to storage when true. Defaults to false.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Chalice-GraphQL-0.1.0.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file Chalice-GraphQL-0.1.0.tar.gz.

File metadata

  • Download URL: Chalice-GraphQL-0.1.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.6.7

File hashes

Hashes for Chalice-GraphQL-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d7038fb4c4a5b905762b3a4f43e5ac1c66811b941ead615ae243447c1a5167f3
MD5 f8c840f7facb586bc4f635db8c2b04c7
BLAKE2b-256 715886d205b5bc730490b2f7551e15baa72f0538c64c024e172b65acef32c1de

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page