Fastapi: graphql example

Created on 11 Jan 2019  路  8Comments  路  Source: tiangolo/fastapi

It would be useful to show how to accomplish integrating fastapi with graphene or another graphQL interface. Its touched on lightly in the docs, but I couldn't find a complete example that reuses the good parts of fastapi and pydantic.

Is this too far out of scope for a suggestion?

Most helpful comment

FYI @tiangolo (and anyone else who's interested) we just released our Graphene + Pydantic layer which we're using in a FastAPI project: https://pypi.org/project/graphene-pydantic/ -- hope it's helpful for folks!

All 8 comments

Yep, it's still missing from the docs.

There are a couple other features that are provided directly by Starlette that I haven't documented yet. And some that I have to update the docs in Starlette directly first.

But I have it planned and I'll add them :smile:


For GraphQL it would depend directly on Graphene, exactly as in Starlette.

I think I might create a Pydantic/Graphene layer latter, to be able to use Python types for GraphQL. I would build it as an external package (so that others outside FastAPI can use it too). But that's more in the mid/long-term.

GraphQL docs are now live at: https://fastapi.tiangolo.com/tutorial/graphql/ :tada: :rocket:

thanks @tiangolo. I will definitely be on the lookout for the pydantic type-based stuff. I found a talk given by Alec Macqueen at Europython 2018 where he discusses some work his company was doing internally in this realm (type-annotation qraphql magic). I don't believe they open-sourced anything yet, but he may have some ideas that will help. I pinned the start time for ye for the juicy bits.

video

Thanks for the video, I finally got to see it. It looks interesting indeed.

FYI @tiangolo (and anyone else who's interested) we just released our Graphene + Pydantic layer which we're using in a FastAPI project: https://pypi.org/project/graphene-pydantic/ -- hope it's helpful for folks!

GraphQL docs are now live at: https://fastapi.tiangolo.com/tutorial/graphql/ :tada: :rocket:

This link doesn鈥檛 work anymore

You should be able to search on the doc website but https://fastapi.tiangolo.com/advanced/graphql/

Hello there, inspired on the graphene-pydantic packaged I created the pydantic2graphene, this is a package that allows you to re-use the pydantic schemas that you use on your FastAPI endpoints to also generate graphene objects for your GraphQL endpoint.

You can checkout a full example of re-using schemas to get your REST and GraphQL endpoints running.

https://github.com/lfvilella/pydantic2graphene/tree/master/docs/examples/fastapi_graphql_and_rest

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tsdmrfth picture tsdmrfth  路  3Comments

kkinder picture kkinder  路  3Comments

RogerioDosSantos picture RogerioDosSantos  路  3Comments

iwoloschin picture iwoloschin  路  3Comments

vnwarrior picture vnwarrior  路  3Comments