Date / eq operator DateFilter bug in GraphQL
See original GitHub issueDescribe the bug
Having an issue querying by date field in GraphQL. eq
operator not working correctly in DateFilter via GraphQL. The query works if I hardcode the date into the query, but fails if I make it a variable. Bug?
Also, documentation appears to be wrong on the filters that Dates support (“in” for example, doesn’t work) https://www.sanity.io/docs/graphql#1c12c1798386
To Reproduce
In my model, date
is a date field.
Query variables: {date: "2021-06-22"}
query GetThing($date:Date) {
allThing(where:{date:{eq: $date}}) {
_id
date
}
}
Expected behavior
The query above returns 0 results. It should return 1 matching document:
{
"data": {
"allThing": [
{
"_id": "c9592994-303b-4e6e-92e4-e77309e640dd",
"date": "2021-06-22",
}
]
}
}
Hardcoding date as string returns the correct result:
query GetThing {
allThing(where:{date:{eq: "2021-06-22"}}) {
_id
date
}
}
Specifying an earlier date, then using gte
returns the correct result. Query variables: {date: "2021-06-21"}
. Does not solve my use case, but does highlight the issue.
query GetThing($date:Date) {
allThing(where:{date:{gte: $date}}) {
_id
date
}
}
Screenshots If applicable, add screenshots to help explain your problem.
Which versions of Sanity are you using? @sanity/cli 2.11.0 (latest: 2.12.0) @sanity/base 2.12.0 (up to date) @sanity/components 2.2.6 (up to date) @sanity/core 2.12.0 (up to date) @sanity/dashboard 2.10.5 (up to date) @sanity/default-layout 2.12.0 (up to date) @sanity/default-login 2.11.1 (up to date) @sanity/desk-tool 2.12.1 (up to date) @sanity/vision 2.11.2 (up to date)
What operating system are you using? Big Sur
Which versions of Node.js / npm are you running?
7.0.8 v15.2.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
This sounds like a bug, given your variable is in the correct format. I’ll take a look at this on Monday and check out what is going on when you pass a variable.
This has been deployed and fixed. Please re-open the issue if you still have issues.