Skip to main content

ASGI support for the Tartiflette Python GraphQL engine

Project description

tartiflette-asgi logo

Build status Package version Code style

tartiflette-asgi is a wrapper that provides ASGI support for the Tartiflette Python GraphQL engine.

It is ideal for serving a GraphQL API over HTTP, or adding a GraphQL API endpoint to an existing ASGI application (e.g. FastAPI, Starlette, Quart, etc).

Full documentation is available at: https://tartiflette.github.io/tartiflette-asgi

Requirements

tartiflette-asgi is compatible with:

  • Python 3.6, 3.7 or 3.8.
  • Tartiflette 1.x.

Quickstart

First, install Tartiflette's external dependencies, as explained in the Tartiflette tutorial.

Then, you can install Tartiflette and tartiflette-asgi using pip:

pip install tartiflette "tartiflette-asgi==0.*"

You'll also need an ASGI web server. We'll use Uvicorn here:

pip install uvicorn

Create an application that exposes a TartifletteApp instance:

from tartiflette import Resolver
from tartiflette_asgi import TartifletteApp

@Resolver("Query.hello")
async def hello(parent, args, context, info):
    name = args["name"]
    return f"Hello, {name}!"

sdl = "type Query { hello(name: String): String }"
app = TartifletteApp(sdl=sdl, path="/graphql")

Save this file as graphql.py, then start the server:

uvicorn graphql:app

Make an HTTP request containing a GraphQL query:

curl http://localhost:8000/graphql -d '{ hello(name: "Chuck") }' -H "Content-Type: application/graphql"

You should get the following JSON response:

{ "data": { "hello": "Hello, Chuck!" } }

To learn more about using tartiflette-asgi, head to the documentation: https://tartiflette.github.io/tartiflette-asgi

Contributing

Want to contribute? Awesome! Be sure to read our Contributing guidelines.

Changelog

Changes to this project are recorded in the changelog.

License

MIT

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

0.10.0 - 2021-01-19

Added

  • Add official compatibility with Tartiflette 1.3.x. (Pull #132)

0.9.0 - 2020-06-10

Removed

  • Drop deprecated mount helpers module. Prefer using the mounting mechanism of your ASGI framework. (Pull #119)

Changed

  • Update dependency on Starlette to 0.13.*. (Pull #106)
  • Convert internal modules to private naming. All public API should be accessed from the top-level tartiflette_asgi package. (Pull #117)

Added

  • Add compatibility with Starlette 0.13.*. (Pull #106)

0.8.0 - 2020-06-04

Added

  • Add support for Tartiflette 1.2.x. (Pull #115)

Fixed

  • Fix GraphiQL subscriptions endpoint when using ASGI sub-mounting. (Pull #98)
  • Fix protocol mismatch error when serving GraphiQL over HTTPS. (Pull #114)

0.7.1 - 2019-10-28

Fixed

  • Requests containing malformed JSON now return a 400 Bad Request error response instead of 500 Internal Server Error. (Pull #81)

0.7.0 - 2019-10-27

Changed

  • Renamed project to tartiflette-asgi.

0.6.0 - 2019-10-18

Added

  • Add support for Tartiflette 1.x. (Pull #58)
  • Officialize support for Python 3.8. (Pull #80)

Removed

  • Drop support for Tartiflette 0.x. (Pull #58)

0.5.2 - 2019-10-09

Added

  • Add support for Python 3.8. (Pull #55)

Fixed

  • Type annotations are now correctly detected by mypy. (Pull #66)
  • Fix a bug that prevented the GraphiQL web interface from making queries when the application was mounted on a parent ASGI app. (Pull #51)

0.5.1 - 2019-07-16

Fixed

  • Fixed a bug that prevented accessing the GraphiQL interface when subscriptions were not enabled.

0.5.0 - 2019-07-12

Added

  • WebSocket subscriptions, configurable with the new subscriptions option on TartifletteApp.
  • Pass extra context to resolvers using the new context option on TartifletteApp.

0.4.0 - 2019-07-04

Added

  • Support for Tartiflette 0.12.x.
  • Add a mount module with submounting helpers.
  • Add mount.starlette().

Changed

  • Due to the new engine cooking API in Tartiflette 0.12, TartifletteApp now includes a startup event handler responsible for building the GraphQL engine. If submounting, it must be registered on the parent ASGI app. Helpers in the mount module take care of this for you.

Removed

  • Drop support for Tartiflette 0.11.x and below.

0.3.0 - 2019-07-03

Added

  • GraphiQL configuration via the GraphiQL helper. Options: path, default_query, default_headers, default_variables, template.

Changed

  • Internal refactoring that leverages more of Starlette's capabilities.
  • Documentation improvements.

0.2.0 - 2019-06-10

Added

  • Support for starlette>=0.12 (previously >=0.12.0b3).
  • Tartiflette is now installed too when installing tartiflette-asgi.

Changed

  • The default path is now "" (previously "/").
  • The request is now accessible in the GraphQL context via context["req"] (previously context["request"]).
  • If no error occurred, the errors field is not present in the response anymore (previously was None).

Fixed

  • More robust URL matching on TartifletteApp.

0.1.1 - 2019-04-28

Fixed

  • Add missing graphiql.html package asset.

0.1.0 - 2019-04-26

Added

Features:

  • TartifletteApp ASGI application.
  • Built-in GraphiQL client.

Project-related additions:

  • Package setup.
  • Changelog.
  • Contributing guide.
  • README and documentation.

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

tartiflette-asgi-0.10.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

tartiflette_asgi-0.10.0-py2.py3-none-any.whl (14.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file tartiflette-asgi-0.10.0.tar.gz.

File metadata

  • Download URL: tartiflette-asgi-0.10.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for tartiflette-asgi-0.10.0.tar.gz
Algorithm Hash digest
SHA256 3bea008a2d2fb34eef6298592c1fb77c9d68fb9c150fd519d158644ffa53d21a
MD5 5d8bbb93cd6d9069f8832708ff58ba4a
BLAKE2b-256 c07d6174253e41a9b0cc14929305047f11327da6b0d0cde7fb139e3960c0501f

See more details on using hashes here.

File details

Details for the file tartiflette_asgi-0.10.0-py2.py3-none-any.whl.

File metadata

  • Download URL: tartiflette_asgi-0.10.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for tartiflette_asgi-0.10.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2a047319bee963302bfb73af037078a63871772cc1fd1b5c21ddc920b12795e8
MD5 40c548f47293850988b1af871097360b
BLAKE2b-256 b81fdeafb544f58dcfc124596405cb6ae83392cf59eeec8c9ea72fabe1a49043

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