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

2

6

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?

Zaragoza answered 17/12, 2016 at 17:52 Comment(0)
C
6

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.

Cortes answered 13/1, 2017 at 8:37 Comment(1)
Can you tell how to set the schema for elasticsearch so I can query using graphql.Plated
R
0

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

Yet, still alpha.

Rothko answered 26/8, 2019 at 19:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.