3

最近我想尝试除了 API 和 DB 之外的其他东西作为后端。我会说 Django 的图形堆栈。我选择 GraphQL 是因为它很受欢迎,并且作为数据库,我想尝试其他不适用于表、行和列的东西。我为这个任务选择了 Neo4j 及其 Django OGM neomodel。我开始阅读这两种技术的文档。与他们斗争了一点,我想整合他们,我发现没有这样的机会。我发现的文章是关于 Neo4j 和 DRF 或使用普通 RDB 的 GraphQL 的。

我创建了一些节点,现在我有一个应用程序是用户个人资料(我正在克隆社交网络)并将它们映射到 GraphQL 模式。然后我遇到了诸如此类的错误Country doesn't have attribute _meta

我的节点

# Node is AbstractNode with __abstract_node__ attribute set to True

class Country(Node):
    name = StringProperty()


class City(Node):
    name = StringProperty()

和架构

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)

这个图形堆栈是否合适,或者我遗漏了一些东西。我希望 Neo4j 节点能够序列化为 GraphQL 模式。

4

0 回答 0