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

Missing optional variable in AND statement generates invalid Cypher query #360

Closed
mrandrewhayes opened this issue Jul 26, 2021 · 1 comment · Fixed by #361
Closed

Missing optional variable in AND statement generates invalid Cypher query #360

mrandrewhayes opened this issue Jul 26, 2021 · 1 comment · Fixed by #361
Labels
bug Something isn't working

Comments

@mrandrewhayes
Copy link

Describe the bug
When building a GraphQL query using WHERE... AND with variables inside the AND statement, omitting an optional variable results in a Cypher error.

By contrast, it is possible to omit optional variables that are used outside the AND statement. In that case the query runs and the whole term is ignored in the resulting Cypher query.

Type definitions

type Event {
    id: ID!
    name: String
    start: DateTime
    end: DateTime
    activity: String
}

To Reproduce

  1. Use a server running Neo4j GraphQL 1.2.3 and a schema containing the above type definition
  2. Use a client such as Apollo Client that can pass a GraphQL query with variables to the server
  3. Run the query:
query ($rangeStart: DateTime, $rangeEnd: DateTime, $activity: String) {
  events (
    where: { 
      AND: [
        { start_GTE: $rangeStart }
        { start_LTE: $rangeEnd }
        { activity: $activity }
      ]
    }
  ) 
  {
    start
    activity
  }  
}            

with the variables

{
  "rangeStart": "2021-07-18T00:00:00+0100",
  "rangeEnd": "2021-07-18T23:59:59+0100"
}

... that is, omitting the optional variable $activity

Expected behavior
I would ideally like Event nodes with any value in the activity field to be included in the result

Actual result
The error message is returned to the client:

{
  "errors": [
    {
      "message": "Invalid input ')': expected whitespace, comment or an expression (line 2, column 85 (offset: 103))\n\"WHERE (this.start >= $this_AND_start_GTE AND this.start <= $this_AND1_start_LTE AND )\"\n                                                                                     ^",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "events"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "code": "Neo.ClientError.Statement.SyntaxError",
          "name": "Neo4jError"
        }
      }
    }
  ],
  "data": null
}

System (please complete the following information):

  • Windows
  • @neo4j/graphql@1.2.3
  • node 14.16.1
@mrandrewhayes mrandrewhayes added bug Something isn't working inbox labels Jul 26, 2021
danstarns added a commit to danstarns/graphql that referenced this issue Jul 27, 2021
danstarns added a commit to danstarns/graphql that referenced this issue Jul 27, 2021
@mrandrewhayes
Copy link
Author

Working perfectly in 1.2.4. Nice work! 🦅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant