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

Filtering _Neo4jDateTime within AND, OR condition resulting in "Neo4jError: No such field: formatted" #495

Closed
CraigDeverall opened this issue Aug 9, 2020 · 12 comments · Fixed by #531

Comments

@CraigDeverall
Copy link

CraigDeverall commented Aug 9, 2020

Assignment(filter: { AND: [ { OR: [ {AND: {start_lt: {formatted:$end}, start_gt: {formatted:$start}}}, {AND: {end_lt: {formatted:$end}, end_gt: {formatted:$start}}}, {AND: {start_lt: {formatted:$start}, end_gt: {formatted:$end}}}, ]}, {timeline: {name: $timelineName}} ]}) { id }

This causes an error: "Neo4jError: No such field: formatted"

Where as:
Assignment(filter: {start_lt: {formatted:$end}, start_gt: {formatted:$start}}) { id }
does not.

assignments( filter: { AND: [ { OR: [ { AND: { start_lt: { year: 2021 }, start_gt: { year: 2020 } } } { AND: { end_lt: { year: 2021 }, end_gt: { year: 2020 } } } { AND: { start_lt: { year: 2020 }, end_gt: { year: 2021 } } } ] } { timeline: { name: $timelineName } } ] } )

Is also a valid working query, so it seems just an issue with using {formatted: ""} inside of AND and OR conditions.

@NawarA
Copy link

NawarA commented Oct 6, 2020

After upgrading to 2.16.4, DateTime is bugged

This works: 👍
image

This fails 👎
image
This fails 👎
image

with the error
image

Though, it looks like the DB still recognizes formatted, so it must be a transpiling issue
image

Error, as of 2.16.4. I checked 2.16.3, and all tests pass. Its an issue with the current release (2.16.4)

@NawarA
Copy link

NawarA commented Oct 6, 2020

Also, I'd like to clarify...this issue does not have to do with Filtering _Neo4jDateTime within AND, OR condition resulting in. Instead, creating any kind of node with a temporal value fails...so this is probably a critical bug, if anyone pushed 2.16.4 to production, and they rely on temporal values...their production code for node creation is affected / broken due to this. I'm happy to open a separate issue, as it relates to node creation, not filtering, but it is the same error message, so I posted it here

@NawarA
Copy link

NawarA commented Oct 6, 2020

one final note, if anyone is affected by this, my temporarily work-around is to use stop using formatted and manually destructure all dates...which is lame...but at least it'll prevent the code from crashing...hopefully a hot patch is released in 2.16.5

function temporaryPatchForNeo4jGraphQLBug(isoString) {
  const date = new Date(isoString);
  // return an obj neo4j understands
  return {
    year: date.getUTCFullYear(),
    month: date.getUTCMonth() + 1,
    day: date.getUTCDate(),
    hour: date.getUTCHours(),
    minute: date.getUTCMinutes(),
    second: date.getUTCSeconds(),
    millisecond: date.getUTCMilliseconds(),
    timezone: 'Z'
  };
}

johnymontana pushed a commit that referenced this issue Nov 6, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
* makes test script more specific

* exports some filter argument builders

* experimental support for where / data mutation arguments

* Update node.js

* experimental support for where / data mutation arguments

* experimental support for where / data mutation arguments

* experimental support for where / data mutation arguments

* exports schema comparison helpers

now used by both the normal and experimental augmentation tests

* adds test for experimental augmented schema

* adds typeDefs for experimental augmentation test

* Update augmentSchemaTest.test.js

* augmentation test for experimental schema

* adds tests for experimental node and relationship mutation arguments

* removes unused arguments and branches on array emptiness

* fixed temporal ordering and filtering

#524: unified the translation of nested orderBy arguments for relationship fields into translateNestedOrderingArgument, fixed schemaType argument to be innerSchemaType, for call in relationFieldOnNodeType

#495: uses parentIsListArgument to buildNeo4jTypeTranslation, to appropriately translate temporal filters used within OR / AND list filters

* adds tests for fixing #495 and #524

* blocks empty string "" from passing

this results in letting the cypher error pass through, caused by datetime(""), if an empty string is provided for a .formatted argument

* removed now unused function argument

* Update input-values.js
@NawarA
Copy link

NawarA commented Nov 13, 2020

I still see this as an issue on 12.17.1

For example, on our client (apollo-client)
image

Using the correct way to save a timestamp:
image

yields No such field: formatted
image

but if we use the workaround
image
image

Then everything goes through, with status 200

So I'd say actually, this issue shouldn't be marked as closed for now, as it still open in 12.17.1

@NawarA
Copy link

NawarA commented Nov 13, 2020

@johnymontana please reopen, as it stills an open issue apparently on 12.17.1

Thank you 🙏

@udaykor
Copy link

udaykor commented Nov 21, 2020

@johnymontana I have this on 2.17.1. Apparently I can create datetimes by destructuring from new Date(). Would love to use formatted

@udaykor
Copy link

udaykor commented Nov 25, 2020

@NawarA I reckon this is something wrong with the graphql client we are using. I am using Apollo Boost v0.4.9.

When I try this with GraphQL playground, everything goes well and { formatted: <ISO_DATE_STRING> } works but fails when I send from apollo-boost. My suspicion is that the client library to talk to GraphQL is unable to introspect

@udaykor
Copy link

udaykor commented Nov 26, 2020

@NawarA My issue is only with Update and Merge, I can created ISOString dates though

#537

@NawarA
Copy link

NawarA commented Nov 26, 2020

We're using @apollo/client: ^3.2.9...so the current apollo client. You should consider switching, since apollo-boost is now "retired" and has been replaced by @apollo/client.

Screenshot from the apollo site.
image

I believe you're correct. The open issue allows developers to save DateTime using formatted, but thereafter, neo4j-graphql-js 2.17.1 causes requests to crash when trying to update the same DateTime property using formatted.

PS: happy thanksgiving :)

@udaykor
Copy link

udaykor commented Nov 27, 2020

Happy Thanks giving mate, Yes I just made changes to move to apollo client. The issue is with APOC not this library though from what I found from my neo4j logs

@igokul1973
Copy link

igokul1973 commented Apr 3, 2021

Hi to all! Also having this issue.
@michaeldgraham
Hi! I analysed the issue and it seems to have been introduced with your new mutation.js file - https://github.com/neo4j-graphql/neo4j-graphql-js/blob/master/src/translate/mutation/mutation.js around 4 months ago. It apparently rewrites the logic of creating the cypher mutation with params, which causes the error in question.
If you look at the line 593 in your commit 36a754a then one can suppose that here you should've taken into consideration the updateParams variable from above in the code. Given in params.params there is an original field of temporal type such as: {updated_at: {formatted: '2020-12-12...'}}, the updateParams.params has the updated_at converted to {updated_at: '2020-12-12...'}. Since the query itself contains ..., updatedAt: datetime($params.updatedAt), ... the params for the updated_at should be like in the updateParams.params. Please take it into consideration and fix the error.

@chunkychode
Copy link

@igokul1973
This library is being replaced with @neo4j/graphql, do i doubt this will be fixed. i've been using a fork that deals with this issue this pr

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

Successfully merging a pull request may close this issue.

5 participants