Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-15-2019 10:41 AM
I want to use merge instead of create for making nodes. Since GraphQL does not make the merge statement for me, I am trying to make it myself.
This is what I am tying.
type Mutation {
MergeLesson(id: ID!, name: String!, language: String!, dialect: String , description: String):Lesson!
@cypher(
statement: "MERGE(lesson:Lesson{id: $id, name: $name, language: $language, dialect: $dialect, description: $description})"
)
}
mutation MergeLesson {
MergeLesson (id: "1", name: "test", language: "English",
dialect: "USA", description: "Testing funtion"){
name
language
dialect
description
}
}
and I Tryed
mutation MergeLesson($id: ID! $name: String!, $language: String!, $dialect: String!, $description: String!) {
MergeLesson (id: $id, name: $name, language: $language,
dialect: $dialect, description: $description){
name
language
dialect
description
}
}
I am having many problems and was wondering if there was a better way to do.
{
"errors": [
{
"message": "Cannot return null for non-nullable field Mutation.MergeLesson.",
Should I keep trying to get it to work this way or try something else?
07-15-2019 11:43 AM
Hey @futuristnicole -
I think the issue here is that the Cypher statement in the @cypher
schema directive needs to return the node. Also, it is usually a good idea to MERGE
only on the properties that identify uniqueness (which in your case sounds like name and language?). So something like this:
type Mutation {
MergeLesson(id: ID, name: String!, language: String!, dialect: String, description: String): Lesson! @cypher(statement:"""
MERGE (lesson:Lesson {name: $name, language: $language})
SET lesson.id = $id, lesson.dialect = $dialect, lesson.description = $description
RETURN lesson
""")
}
One issue here is you might get Cypher errors if dialect
or description
are not included as the cypher query expects those to be passed as parameters (but they won't be if they're not passed in arguments), so it might be better to use an input type for this:
input MergeLessonInput {
id: ID,
name: String!,
language: String!,
dialect: String,
description: String
}
type Mutation {
MergeLesson(lessonInput: MergeLessonInput!): Lesson! @cypher(statement:"""
MERGE (lesson:Lesson {name: $lessonInput.name, language: $lessonInput.language})
SET lesson = $lessonInput
RETURN lesson
""")
}
All the sessions of the conference are now available online