Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Complex nested filtering doesn't appear to work anymore #586

Open
ookejimift opened this issue Feb 4, 2021 · 7 comments
Open

Complex nested filtering doesn't appear to work anymore #586

ookejimift opened this issue Feb 4, 2021 · 7 comments

Comments

@ookejimift
Copy link

ookejimift commented Feb 4, 2021

It appears the complex nested filtering bug described in #353 is back.

We have a schema as follows:

const Article = `type Article {
	title: String
	plannedPublishDate: DateTime
	contentType: String
	.....
}`;

If I request articles published after a certain date as follows:

{
  Article(
    filter: {
      AND: [
        {
          contentType: "article"
          plannedPublishDate_gte: { formatted: "2010-06-26T01:00:00.000Z" }
        }
      ]
    }
  ) {
    _id
  }
}

I get no result, however, if I repeat the same request without the logical AND thus:

{
  Article(
    filter: {
      contentType: "article"
      plannedPublishDate_gte: { formatted: "2010-06-26T01:00:00.000Z" }
    }
  ) {
    _id
  }
}

I get results (see screenshots below).

I have tested this in v2.17.1 and v2.19.2 and the results are the same (as described above), however, it works as expected in v2.11.3

image

image

@ookejimift ookejimift changed the title Complex nested filtering doesn't appear to work Complex nested filtering doesn't appear to work anymore Feb 4, 2021
@ookejimift
Copy link
Author

ookejimift commented Feb 4, 2021

Without the logical AND, the cypher is doing the correct date comparison article.plannedPublishDate >= datetime($filter.plannedPublishDate_gte), this is the full cypher


MATCH (`article`:`Article`) WHERE ((`article`.plannedPublishDate >= datetime($filter.plannedPublishDate_gte))) AND (`article`.contentType = $filter.contentType) RETURN `article` {_id: ID(`article`)} AS `article` +0ms
  neo4j-graphql-js {
  "offset": 0,
  "first": -1,
  "filter": {
    "plannedPublishDate_gte": "2010-06-26T01:00:00.000Z",
    "contentType": "article"
  }
}

However, with the logical AND, the cypher doesn't look right, note the equality comparison (instead of >=) article.plannedPublishDate = datetime(_AND.plannedPublishDate_gte.formatted), see full cypher below:

MATCH (`article`:`Article`) WHERE (ALL(_AND IN $filter.AND WHERE (((_AND.plannedPublishDate_gte.formatted IS NULL OR `article`.plannedPublishDate = datetime(_AND.plannedPublishDate_gte.formatted)))) AND (_AND.contentType IS NULL OR `article`.contentType = _AND.contentType))) RETURN `article` {_id: ID(`article`),updatedAt: { formatted: toString(`article`.updatedAt) }} AS `article` +3m
  neo4j-graphql-js {
  "offset": 0,
  "first": -1,
  "filter": {
    "AND": [
      {
        "plannedPublishDate_gte": {
          "formatted": "2010-06-26T01:00:00.000Z"
        },
        "contentType": "article"
      }
    ]
  }
}

@ookejimift
Copy link
Author

ookejimift commented Feb 12, 2021

This issue seems to only affect temporals and it was apparently introduced in v2.17.1 - this release.

Looking at the test here, the assertion does not seem right, even though the query filter is:

filter: {
     	  OR: [
          {
            datetime_gte: {
              formatted: "2018-11-23T10:30:01.002003004-08:00[America/Los_Angeles]"
            }
          }
        ]   
      }

The test is asserting
temporalNode.datetime = datetime(_OR.datetime_gte.formatted)
instead of
temporalNode.datetime >= datetime(_OR.datetime_gte.formatted)

@fnfbraga
Copy link

I am observing the same, date filters with operators other than the exact date do not retrieve any results.

gql query:
Form(first: $first, orderBy: $orderBy, offset: $offset, filter: {AND:[{createdOn:{year:2021, month:2, day:26}}]}) {
neo4j generated query:
MATCH (form:Form) WHERE (ALL(_AND IN $filter.AND WHERE (((_AND.createdOn.year IS NULL OR form.createdOn.year = _AND.createdOn.year) AND (_AND.createdOn.month IS NULL OR form.createdOn.month = _AND.createdOn.month) AND (_AND.createdOn.day IS NULL OR form.createdOn.day = _AND.createdOn.day))))) WITH formORDER BY form.id ASC RETURNform { .id ,createdOn: { formatted: toString(form.createdOn) } ...etc { "offset": 0, "first": 10, "filter": { "AND": [ { "createdOn": { "year": { "low": 2021, "high": 0 }, "month": { "low": 2, "high": 0 }, "day": { "low": 26, "high": 0 } } } ] },

return as result

but:

gql query

Form(first: $first, orderBy: $orderBy, offset: $offset, filter: {AND:[{**createdOn_lte**:{year:2021, month:2, day:**27**}}]}) {

MATCH (form:Form) WHERE (ALL(_AND IN $filter.AND WHERE (((_AND.createdOn_lte.year IS NULL OR form.createdOn.year = _AND.createdOn_lte.year) AND (_AND.createdOn_lte.month IS NULL OR form.createdOn.month = _AND.createdOn_lte.month) AND (_AND.createdOn_lte.day IS NULL OR form.createdOn.day = _AND.createdOn_lte.day))))) WITH formORDER BY form.id ASC RETURNform { .id ,createdOn: { formatted: toString(form.createdOn) }, ...etc { "offset": 0, "first": 10, "filter": { "AND": [ { "createdOn_lte": { "year": { "low": 2021, "high": 0 }, "month": { "low": 2, "high": 0 }, "day": { "low": 27, "high": 0 } } } ] },

does not

@wheresrhys
Copy link

I think when filtering on temporals formatted might not work. I've successfully filtered temporals setting the year, month, etc properties in the filter e.g.

{
  Article(
    filter: {
      AND: [
        {
          contentType: "article"
          plannedPublishDate_gte: { 
			year: 2010 
			month: 6 
			day: 26
		  }
        }
      ]
    }
  ) {
    _id
  }
}

@ookejimift
Copy link
Author

ookejimift commented Mar 8, 2021

I think when filtering on temporals formatted might not work. I've successfully filtered temporals setting the year, month, etc properties in the filter e.g.

This works in version < 2.17.1 but stops working once you upgrade to version ≥ 2.17.1

Below are screenshots from searches against the same database, the first one using version 2.11.3 and the second one using version 2.19.2

Version 2.11.3

image

Version 2.19.2

image

@chunkychode
Copy link

I am not sure they will to this bug as they are working on their new version. it's a Temporal bug that hard coded the equal operator in translate.js line 2879 and 2881

return `(${nullFieldPredicate}${propertyPath} = ${cypherTypeConstructor}(${listVariable}.${filterName}))`;

i am FAR from a javascript guy but created a fork that corrects it and am using it.
vizipi/neo4j-graphql-js

@michaeldgraham
Copy link
Collaborator

#608

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

No branches or pull requests

5 participants