Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-02-2022 08:11 AM
Neo4j GraphQL
When using connectOrCreate
How do I specify in the mutation a property to add to the newly connected or created edge?
Thank you
06-02-2022 10:47 PM
Hi @david_loving!
You can specify one or several properties as part of the "onCreate".
For create mutations, see the following example: https://neo4j.com/docs/graphql-manual/current/mutations/create/#_connectorcreate_relationships
For update mutations, see this example: https://neo4j.com/docs/graphql-manual/current/mutations/update/#_connectorcreate_relationships
In both cases, the property "title" with the value "Forrest Gump" is added to the newly created edge/node.
Hope that clarifies it!
06-03-2022 05:55 AM - edited 06-03-2022 06:12 AM
<deleted>
06-03-2022 06:11 AM - edited 06-03-2022 06:36 AM
Like this...
https://neo4j.com/docs/graphql-manual/current/type-definitions/relationships/
like createPeople, actedInMovies, connect, edge, roles but instead using connectOrCreate (instead of connect).
edge and edge properties does / do not appear to be supported in connectOrCreate
06-07-2022 12:46 AM - edited 06-09-2022 12:00 AM
type Actor {
name: String!
movies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn") // <- note the properties parameter here
}
type Movie {
title: String
id: ID! @id
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn”) // <- note the properties parameter here
}
interface ActedIn @relationshipProperties { // specify your relationship properties here as an interface
roles: [String!]
}
mutation CreateActors {
createActors(
input: [
{
name: "Jon Doe"
movies: {
connectOrCreate: [
{
where: { node: { id: "1234" } }
onCreate: {
node: { title: "Forrest Gump" }
edge: { roles: ["Harry"] } // <- edge properties
}
}
]
}
}
]
) {
actors {
name
}
}
}
07-12-2022 08:31 AM
Thank you for trying but obviously I have not communicated the problem well enough. This is not an acceptable solution. I will handle with separate calls.
11-01-2022 09:12 PM - edited 11-01-2022 09:26 PM
I'm having a similar problem. In my case, I want to create a comment in a comment section, but if the comment is the first one, the comment section may or may not already exist.
So I thought I should use connectOrCreate, because if a comment section already exists, I should use that. Otherwise I should create another one.
The problem is that a comment section only consists of an ID and relationships to other nodes, so I can't create it with only primitive types. When I tried to create a comment section in the onCreate using relationships to those other nodes, I got the same "Property values can only be of primitive types" error. So I came to the same conclusion as OP, which is that the use case just isn't supported.
The relationship properties don't solve the problem because the node is still being created with the property "title" instead of a relationship to another specific node.
In case anyone is wondering why I don't create comments directly linked to a post, it's because the same post can be shared in multiple different places, and in each place it has a different comment section. Therefore I decided that comments, comment sections and the original posts should all be separate nodes. If it's a bad practice to have a node that only consists of only relationships to other nodes, please let me know what would be a better way of doing it.
All the sessions of the conference are now available online