neo4j / graphql

A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations.
https://neo4j.com/docs/graphql-manual/current/
Apache License 2.0
501 stars 147 forks source link

Alias does not work with Point types #1537

Closed marcoklein closed 2 years ago

marcoklein commented 2 years ago

Describe the bug The @alias directive does not work with the Point type. The generated cypher still uses the "old" name instead of the aliased property.

Type definitions Foo has a Neo4j property of point.

type Foo {
  point: Point
  geo_point: Point @alias(property: "point")
}

To Reproduce Steps to reproduce the behavior:

  1. Create schema with Point and alias to Point property in Neo4j
  2. Start server with logging on to see generated logs
  3. See that it uses the original attribute name instaed of the alias

See also Screenshots / Debug Logs below

Expected behavior Use alias in cypher query so it can run distance searches.

Screenshots

Debug Logs

With alias defined it creates the wrong point Cypher (e.g. pointing to geo_point instead of point expected by alias (see WHERE distance(this.geo_point...)

debug Connection [0][bolt-13303225] C: BEGIN {"mode":"r"}
debug Connection [0][bolt-13303225] C: RUN MATCH (this:Site)
WHERE distance(this.geo_point, point($this_geo_point_LTE.point)) <= $this_geo_point_LTE.distance
RETURN this { .id } as this
LIMIT $this_limit {"this_geo_point_LTE":{"point":{"longitude":48.8791666666661,"latitude":2.3124},"distance":1000},"this_limit":{"low":10,"high":0}} {}
debug Connection [0][bolt-13303225] C: PULL {"n":{"low":1000,"high":0}}
debug Connection [0][bolt-13303225] S: SUCCESS {"signature":112,"fields":[{}]}
debug Connection [0][bolt-13303225] S: SUCCESS {"signature":112,"fields":[{"t_first":{"low":1,"high":0},"fields":["this"],"qid":{"low":0,"high":0}}]}
debug Connection [0][bolt-13303225] S: SUCCESS {"signature":112,"fields":[{"type":"r","t_last":{"low":794,"high":0},"db":"neo4j"}]}
debug Connection [0][bolt-13303225] C: COMMIT
debug Connection [0][bolt-13303225] S: SUCCESS {"signature":112,"fields":[{"bookmark":"FB:kcwQcCvfMbhBSAyHnft6n2mPy8oADGbZkA=="}]}
debug Connection [0][bolt-13303225] C: RESET
debug Connection [0][bolt-13303225] S: SUCCESS {"signature":112,"fields":[{}]}

With point it works fine:

debug Connection [0][bolt-13308451] created for the pool localhost:7687
debug Connection [0][bolt-13308451] C: BEGIN {"mode":"r"}
debug Connection [0][bolt-13308451] C: RUN MATCH (this:Site)
WHERE distance(this.point, point($this_point_LTE.point)) <= $this_point_LTE.distance
RETURN this { .id } as this
LIMIT $this_limit {"this_point_LTE":{"point":{"longitude":2.3124,"latitude":48.8791666666661},"distance":1000},"this_limit":{"low":10,"high":0}} {}
debug Connection [0][bolt-13308451] C: PULL {"n":{"low":1000,"high":0}}
debug Connection [0][bolt-13308451] S: SUCCESS {"signature":112,"fields":[{}]}
debug Connection [0][bolt-13308451] S: SUCCESS {"signature":112,"fields":[{"t_first":{"low":33,"high":0},"fields":["this"],"qid":{"low":0,"high":0}}]}
debug Connection [0][bolt-13308451] S: RECORD {"signature":113,"fields":[[{"id":"5660250"}]]}
debug Connection [0][bolt-13308451] S: RECORD {"signature":113,"fields":[[{"id":"5662471"}]]}
debug Connection [0][bolt-13308451] S: RECORD {"signature":113,"fields":[[{"id":"5660272"}]]}

System (please complete the following information):

Additional context

neo4j-team-graphql commented 2 years ago

Many thanks for raising this bug report @marcoklein. :bug: We will now attempt to reproduce the bug based on the steps you have provided.

Please ensure that you've provided the necessary information for a minimal reproduction, including but not limited to:

If you have a support agreement with Neo4j, please link this GitHub issue to a new or existing Zendesk ticket.

Thanks again! :pray:

tbwiss commented 2 years ago

Hi @marcoklein! Thanks for reaching out! Just to double-check, what were the GraphQL queries you used for the two different debug logs above?

Tip: You can enable debug logging for the GraphQL server itself rather than checking the driver or database logs, see here. This will print the incoming GraphQL query, the executed cypher including parameters, and the received records.

darrellwarde commented 2 years ago

@marcoklein, paging again here to see if you can provide some GraphQL queries/mutations to trigger this behaviour - we can't reverse engineer the output Cypher.

marcoklein commented 2 years ago

Here you go.

@neo4j/graphql:graphql Incoming GraphQL:
Query:
{
  sites(
    options: {limit: 10}
    where: {geo_point_LTE: {point: {latitude: 48.8791666666661, longitude: 2.3124}, distance: 1000.0}}
  ) {
    id
    point {
      latitude
      longitude
    }
    geo_point {
      latitude
      longitude
    }
  }
}
Variables:
{} +0ms
  @neo4j/graphql:auth JWT not configured +0ms
  @neo4j/graphql:execute About to execute Cypher:
Cypher:
MATCH (this:Site)
WHERE distance(this.geo_point, point($this_geo_point_LTE.point)) <= $this_geo_point_LTE.distance
RETURN this { .id, point: apoc.cypher.runFirstColumn('RETURN
CASE this.point IS NOT NULL
        WHEN true THEN { point: this.point }
        ELSE NULL
END AS result',{ this: this },false), geo_point: apoc.cypher.runFirstColumn('RETURN
CASE this.point IS NOT NULL
        WHEN true THEN { point: this.point }
        ELSE NULL
END AS result',{ this: this },false) } as this
LIMIT $this_limit
Params:
{
  "this_geo_point_LTE": {
    "point": {
      "longitude": 2.3124,
      "latitude": 48.8791666666661
    },
    "distance": 1000
  },
  "this_limit": {
    "low": 10,
    "high": 0
  }
} +0ms
  @neo4j/graphql:execute Execute successful, received 0 records +2s
tbwiss commented 2 years ago

@marcoklein thanks for providing the query! I see that you are using the version 2.5.9 of the @neo4j/graphl library. Do your circumstances/environment allow you to update to the latest version? With the latest version, 3.4.0, this problem is resolved.

darrellwarde commented 2 years ago

Closing this issue as resolved given that the issue cannot be reproduced in the latest version of the library. Thanks for the report!

marcoklein commented 2 years ago

Thank you. We will prioritize an upgrade then.

On Tue, Jun 28, 2022, 16:11 Darrell Warde @.***> wrote:

Closed #1537 https://github.com/neo4j/graphql/issues/1537 as completed.

— Reply to this email directly, view it on GitHub https://github.com/neo4j/graphql/issues/1537#event-6894431571, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSRL3POXZP5UTSZB7YVJWLVRMBX3ANCNFSM5YC3OLAQ . You are receiving this because you were mentioned.Message ID: @.***>