neo4j-graphql-js icon indicating copy to clipboard operation
neo4j-graphql-js copied to clipboard

apoc generated from graphql query is not correct

Open adamclark64 opened this issue 6 years ago • 4 comments

I have a query defined as

    byParent(id: Int): [movie]
        @cypher(
            statement: "MATCH (movie:movie)-->(c:movie) WHERE ID(movie)=$id RETURN c"
        )

and a graphql query of

query {
  byParent(id: 108) {
    _id
  }
}

this generated

WITH apoc.cypher.runFirstColumn("MATCH (movie:movie)-->(c:movie) WHERE ID(movie)=$id RETURN c", {id:$id}, True)

and returns nothing. but if I hardcode $id to say, 108. i get expected results. similar to this query below that works in desktop browser

CALL apoc.cypher.run("MATCH (movie:movie)-->(c:movie) WHERE ID(movie)=108 RETURN c", {id:108})

work in the desktop browser and so does

MATCH (movie:movie)-->(c:movie) WHERE ID(movie)=108 RETURN c

What is the correct way to get apoc to translate this graphql query / can i add apoc to the gql schema definitions like the apoc procedures added in.

byParent(id: Int): [movie]
        @cypher(
            statement: "CALL apoc.cypher.run('MATCH (movie:movie)-->(c:movie) WHERE ID(movie)=$id RETURN c', {id:$id})"
        )

would be great but I know is not a solution

adamclark64 avatar Dec 14 '18 21:12 adamclark64

@adamclark64 Can you share the full generated Cypher query and the Cypher parameters as well (should be logged together)?

johnymontana avatar Dec 14 '18 21:12 johnymontana

graphql query

{
  byParent(id: 108) {
    _id
  }
}

outputs this in the console

WITH apoc.cypher.runFirstColumn("MATCH (movie:movie)-->(c:movie) WHERE ID(movie)=$id RETURN c", {id:$id}, True) AS x UNWIND x AS movie
    RETURN movie {_id: ID(movie)} AS movie SKIP $offset
{ offset: 0, first: -1, id: 108 }

The query below works in the neo4j browser when I swap out the id like {id:108} but not sure why the output above returns nothing

RETURN apoc.cypher.runFirstColumn("MATCH (movie:movie)-->(c:movie) WHERE ID(movie)=$id RETURN c", {id:108}, True)

adamclark64 avatar Dec 14 '18 22:12 adamclark64

the above seems to be only a partial query, it misses the params, and the "true"

WITH apoc.cypher.runFirstColumn("MATCH (movie:movie)-->(c:movie) WHERE ID(movie)=$id RETURN c", {id:$id}, True) AS x UNWIND x AS movie
    RETURN movie {_id: ID(movie)} AS movie SKIP $offset
{ offset: 0, first: -1, id: 108 }

jexp avatar Jan 09 '19 22:01 jexp

https://github.com/neo4j-graphql/neo4j-graphql-js/issues/608

michaeldgraham avatar May 02 '21 04:05 michaeldgraham