fastapi/docs/en/docs/advanced/graphql.md
Sebastián Ramírez 6205935323
Add support for docs translations (#1168)
* 🌐 Refactor file structure to support internationalization

*  Update tests changed after i18n

* 🔀 Merge Typer style from master

* 🔧 Update MkConfig with Typer-styles

* 🎨 Format mkdocs.yml with cannonical form

* 🎨 Format mkdocs.yml

* 🔧 Update MkDocs config

*  Add docs translation scripts dependencies

*  Add Typer scripts to handle translations

*  Add missing translation snippet to include

*  Update contributing docs, add docs for translations

* 🙈 Add docs_build to gitignore

* 🔧 Update scripts with new locations and docs scripts

* 👷 Update docs deploy action with translations

* 📝 Add note about languages not supported in the theme

*  Add first translation, for Spanish
2020-03-26 20:09:53 +01:00

1.4 KiB

GraphQL

FastAPI has optional support for GraphQL (provided by Starlette directly), using the graphene library.

You can combine normal FastAPI path operations with GraphQL on the same application.

Import and use graphene

GraphQL is implemented with Graphene, you can check Graphene's docs for more details.

Import graphene and define your GraphQL data:

{!../../../docs_src/graphql/tutorial001.py!}

Add Starlette's GraphQLApp

Then import and add Starlette's GraphQLApp:

{!../../../docs_src/graphql/tutorial001.py!}

!!! info Here we are using .add_route, that is the way to add a route in Starlette (inherited by FastAPI) without declaring the specific operation (as would be with .get(), .post(), etc).

Check it

Run it with Uvicorn and open your browser at http://127.0.0.1:8000.

You will see GraphiQL web user interface:

More details

For more details, including:

  • Accessing request information
  • Adding background tasks
  • Using normal or async functions

check the official Starlette GraphQL docs.