从graph(neo4j)数据库检索graphene django和graphql的关系属性
我正在尝试创建一个简单的应用程序(使用django和python创建一个GraphQLAPI)。事情进展顺利,但我遇到了一个问题,我不知道该怎么办(我已经搜索了好几天了,但我只是放弃了),所以我希望这里有人能帮我(见下面我的内容) 我正在使用Django和graphene Django以及neo4j作为(图形)数据库。我也在使用中继模式 使用graphql,我可以查询产品的所有属性,也可以查询关系(哪个产品属于哪个类别,反之亦然) 现在我的问题是:在neo4j中,关系也有它们自己的属性,但我不知道如何获取这些属性(例如,我想知道何时创建关系,这是关系上的一个属性) 我目前有两种节点类型:类别和产品请参见下面的模型(models.py): 下面是我使用的graphene django代码(schema.py): 我的想法是,也许我可以尝试创建一个额外的字段,并编写一个解析器来执行原始查询以获取关系和属性(如下所示) 现在要执行关系,我需要2个id进行如下查询: 匹配(n:Category)-[r]->(x:Product),其中id(n)=2358和id(x)=187返回n,x,r 所以我可以得到r的关系性质 我的问题是我无法获取连接节点的id(只有root.id)。是否有方法获取父id?或者是我的整个思维方式都错了,有一个函数(我不知道,也许是石墨烯?)可以以不同的(希望更好的)方式实现我想要的从graph(neo4j)数据库检索graphene django和graphql的关系属性,django,neo4j,graphql,graphene-python,graphene-django,Django,Neo4j,Graphql,Graphene Python,Graphene Django,我正在尝试创建一个简单的应用程序(使用django和python创建一个GraphQLAPI)。事情进展顺利,但我遇到了一个问题,我不知道该怎么办(我已经搜索了好几天了,但我只是放弃了),所以我希望这里有人能帮我(见下面我的内容) 我正在使用Django和graphene Django以及neo4j作为(图形)数据库。我也在使用中继模式 使用graphql,我可以查询产品的所有属性,也可以查询关系(哪个产品属于哪个类别,反之亦然) 现在我的问题是:在neo4j中,关系也有它们自己的属性,但我不知
谢谢您的帮助。我没有将neo4j与django一起使用,但这应该可以:
class ProductType(DjangoObjectType):
relationship = graphene.String()
class Meta:
model = Product
neomodel_filter_fields = {
'name': ['exact', 'icontains'],
'price': ['exact'],
}
interfaces = (relay.Node, )
def resolve_relationship(self, root,info, args):
return self.id # or self.relationship.id or do any thing you want
您需要添加relationship=graphene.String(source=“”)
class CategoryType(DjangoObjectType):
class Meta:
model = Category
neomodel_filter_fields = {
'name': ['exact', 'icontains'],
'shortname': ['exact'],
}
interfaces = (relay.Node, )
class ProductType(DjangoObjectType):
class Meta:
model = Product
neomodel_filter_fields = {
'name': ['exact', 'icontains'],
'price': ['exact'],
}
interfaces = (relay.Node, )
class ProductType(DjangoObjectType):
relationship = graphene.String()
class Meta:
model = Product
neomodel_filter_fields = {
'name': ['exact', 'icontains'],
'price': ['exact'],
}
interfaces = (relay.Node, )
def resolve_relationship(root,info, args):
#perform the raw query here
class ProductType(DjangoObjectType):
relationship = graphene.String()
class Meta:
model = Product
neomodel_filter_fields = {
'name': ['exact', 'icontains'],
'price': ['exact'],
}
interfaces = (relay.Node, )
def resolve_relationship(self, root,info, args):
return self.id # or self.relationship.id or do any thing you want