在 Neo4j GraphQL 中使用 onConnectOrCreate 时,如何向新节点添加属性?
我正在使用 Neo4j 的 GraphQL 库,尝试使用 connectOrCreate 来创建新图像,其定义如下:
type Image {
id: ID! @id(autogenerate: true),
url: String! @unique,
creator: User! @relationship(type: "CREATED_BY", direction: OUT),
}
并且根据 Neo4j 网站上的文档,我应该能够说如果未找到具有 url 字段的节点,然后创建一个并设置一些属性。像这样:
mutation NEW_POST {
createPosts(input: { images: {
connectOrCreate: [{
where: { node: { url: "https://picsum.photos/600" }}
onCreate: { where: { node: { creator: { node: { id: "userId"}}}}},
}]}}){
posts {
id
}
}
}
但是,对于 onCreate Field 输入,我唯一的选项是 id
和 url
。意思是,我实际上无法像这里那样添加创建者属性。
“Field \”creator \”不是由类型\“ImageOnCreateInput \”定义的。”,
您认为这是有意的,还是知道我应该在哪里寻找指导? 我正在查看此文档: https://neo4j.com/docs /graphql-manual/current/mutations/create/ 显示 onCreate: { node: { title: "Forrest Gump" } }
实现了我希望实现的目标。
I'm using Neo4j's GraphQL library, trying to use connectOrCreate for a new Image, which is defined like this:
type Image {
id: ID! @id(autogenerate: true),
url: String! @unique,
creator: User! @relationship(type: "CREATED_BY", direction: OUT),
}
And based on the documentation on the Neo4j website, I should be able to say if a node with the url field is not found, then create one and set some properties. Like this:
mutation NEW_POST {
createPosts(input: { images: {
connectOrCreate: [{
where: { node: { url: "https://picsum.photos/600" }}
onCreate: { where: { node: { creator: { node: { id: "userId"}}}}},
}]}}){
posts {
id
}
}
}
However, for the onCreate Field Input, my only options are id
and url
. Meaning, I can't actually add the creator property like I do here.
"Field \"creator\" is not defined by type \"ImageOnCreateInput\".",
Do you think this is intended, or any idea where I should look for guidance?
I'm looking at this documentation: https://neo4j.com/docs/graphql-manual/current/mutations/create/ which shows onCreate: { node: { title: "Forrest Gump" } }
achieving what I hope to achieve.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 url 为
https://picsum.photos/600
的节点不存在,则将使用突变的onCreate
部分中提供的信息创建一个新节点。创建的。此“onCreate”节点(使用ImageOnCreateInput
)将自动连接指定为“锚点”的节点。请参阅我在您提供的稍作修改的突变中的评论:您可以尝试和使用文档中提供的 typeDefs 和突变(https://neo4j.com/docs/graphql-manual/current/mutations/create/#_connectorcreate_relationships)来查看
connectOrCreate
关系突变是如何运行的。If the node with the url
https://picsum.photos/600
does not exist, a new node node with the information provided in theonCreate
part of the mutation will be created. This "onCreate" node (withImageOnCreateInput
) will automatically connect the node that is specified as the "anchor". See my comments in the slightly modified mutation that you provided:You can experiment and play with the typeDefs and mutation provided in the documentation (https://neo4j.com/docs/graphql-manual/current/mutations/create/#_connectorcreate_relationships) to see how the
connectOrCreate
relationship mutation is operating.