How to build a GraphQL API on top of a Django/Elasticsearch/MySQL backend?

3.3k views Asked by At

I'm looking into develop a GraphQL API. I have a django/elasticsearch/mysql backend and I'm figuring out how GraphQL fits into this picture.

I reading about the graphene-django project but it seems tightly coupled with the Django ORM, so I'm wondering if elasticsearch can fits in this recipe.

I'm just starting this research so there is a chance that even this question is making no sense.

Any clue about how to do this?

2

There are 2 answers

1
Eran Kampf On BEST ANSWER

graphene is a generic GraphQL server implementation from python. Using graphene you can build a representation of your graph data and query it from anywhere (MySQL, ElasticSearch, Mongo, whatever) - each field's value is basically resolved by a resolver function which can read data from wherever needed.

graphene-django is just an extension of graphene that automatically wraps django ORM and lets you easily expose django ORM objects as part of your schema without going through the hassle of defining re-defining all the objects and fields already defined in the ORM model.

It does not, however, limit you to only use the django ORM. You can have many objects in relationships in your GraphQL schema, some objects can work against the django ORM while others can read from ElasticSearch or wherever else you store data.

I would suggest you watch this short video as an intro on how to get started writing your GraphQL server - https://www.youtube.com/watch?v=UBGzsb2UkeY Then head on to http://graphene-python.org and check out the docs.

0
Artur Barseghyan On

Some attempts are started at https://pypi.org/project/graphene-elastic/

Yet, still alpha.