3

Recently I wanted to try something else besides API and DB for backend. I'd say a graph stack for Django. I choose GraphQL because of its popularity and as database I wanted to try something else that is not working with tables, rows and columns. I choose Neo4j for this task and its Django OGM neomodel. I started reading documentation of both technologies. Struggling with them a little bit I wanted to integrate them and I found out that there is no such opportunity. Articles that I found were written about either Neo4j and DRF or GraphQL with ordinary RDB.

I created some nodes, for now I've got one app that is a user profile (I'm doing a clone of social network) and mapped them to a GraphQL schema. Then I've got errors like Country doesn't have attribute _meta and etc.

My nodes

# Node is AbstractNode with __abstract_node__ attribute set to True

class Country(Node):
    name = StringProperty()


class City(Node):
    name = StringProperty()

And schema

class Query(graphene.ObjectType):
    countries = graphene.List(Country)
    cities = graphene.List(City)

    country = graphene.Field(Country)
    city = graphene.Field(City)

    def resolve_countries(self, info, **kwargs):
        return Country.nodes.all()

    def resolve_cities(self, info, **kwargs):
        return City.nodes.all()

    def resolve_country(self, info, **kwargs):
        pass

    def resolve_city(self, info, **kwargs):
        pass


schema = graphene.Schema(query=Query)

Is this graph stack appropriate or I'm missing something. I want Neo4j nodes being able to serialize to GraphQL schema.

nrgx
  • 325
  • 3
  • 13

0 Answers0