Create a WSGI Application for a GraphQL schema.
Project description
Create a WSGI Application for a GraphQL schema.
Usage
Use the GraphQLApplication from wsgi_graphql.
from wsgi_graphql import GraphQLApplication
application = GraphQLApplication(schema)
Options
schema: GraphQLSchema to serve with this application.
execute_options: Dictionary of options to be passed to graphql.execute via graphql_server.run_http_query. If the dictionary values are callable they will be called (see example below).
format_error: Function to format errors (defaults to graphql_server.default_format_error).
encode: Function to encode dictionary (defaults to graphql_server.json_encode).
All execute_options can be callable (i.e. functions) and will receive the current environ as an argument. This can be used for tasks like parsing authentication tokens and inserting results as context_value.
This snippet from the example.py sets the context_value to a dictionary containing the value of the request header greet.
application = GraphQLApplication(schema, execute_options={
'context_value': lambda environ: {
'greet': environ.get('HTTP_GREET')
}
})
This curl command will return {"data":{"hello":"world"}}.
curl --request POST\
--url http://localhost:8080\
--header 'Content-Type: application/graphql'\
--header 'greet: world'\
--data 'query {hello}'
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
File details
Details for the file wsgi_graphql-0.0.2.tar.gz
.
File metadata
- Download URL: wsgi_graphql-0.0.2.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20412c281b59d4add43464f858d62ede99d5fa016aab2acf7aced6534dc9a028 |
|
MD5 | 2f0276c1dc428747472d654f4b474588 |
|
BLAKE2b-256 | 9c6b1c855d459e428f811203375e56b97d5267676f3846cb509fc1420d2a2417 |