Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid mutation query for one-to-many relations #292

Open
congard opened this issue May 4, 2023 · 0 comments
Open

Invalid mutation query for one-to-many relations #292

congard opened this issue May 4, 2023 · 0 comments

Comments

@congard
Copy link

congard commented May 4, 2023

Describe the bug
As in the title - invalid mutation query for one-to-many relations: auto-generated add* and delete* mutations generate invalid Cypher query.

Test Case

package org.example.graphql

import org.neo4j.graphql.SchemaBuilder
import org.neo4j.graphql.Translator

fun main() {
    val sdl = /* GraphQL scheme */
    val schema = SchemaBuilder.buildSchema(sdl)
    val translator = Translator(schema)

    val mutation = /* GraphQL mutation */

    println(translator.translate(mutation, params = HashMap<String, Any>().also {
        it["id"] = 0
        it["belongsTo"] = listOf(1, 2, 3)
    }))
}

GraphQL schema

type Item {
    _id: ID!
    name: String!
    belongsTo: [Category!]! @relation(name: "BelongsTo")
}

type Category {
    _id: ID!
    name: String!
}

GraphQL request

mutation ItemMutateBelongsTo(
    $id: ID!,
    $belongsTo: [ID!]!
) {
    addItemBelongsTo(
        _id: $id,
        belongsTo: $belongsTo
    ) {
        _id
    }
}

Expected cypher query

MATCH (from:Item)
WHERE id(from) = toInteger($id)
MATCH (to:Category)
WHERE id(to) in $belongsTo // <---- here
MERGE (from)-[:BelongsTo]->(to)
WITH DISTINCT from AS addItemBelongsTo
RETURN addItemBelongsTo {
	_id: id(addItemBelongsTo)
} AS addItemBelongsTo

Generated cypher query

MATCH (from:Item)
WHERE id(from) = toInteger($id)
MATCH (to:Category)
WHERE id(to) = toInteger($belongsTo) // <---- invalid, $belongsTo is a list, not just a single integer
MERGE (from)-[:BelongsTo]->(to)
WITH DISTINCT from AS addItemBelongsTo
RETURN addItemBelongsTo {
	_id: id(addItemBelongsTo)
} AS addItemBelongsTo

Additional context
neo4j-graphql-java version: 1.7.0 (also tested 1.6.0 and 1.5.0 - the same issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant