question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Date / eq operator DateFilter bug in GraphQL

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
saasencommented, Jun 26, 2021

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.

0reactions
saasencommented, Sep 28, 2021

This has been deployed and fixed. Please re-open the issue if you still have issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date Filtering eq is Useless - GraphQL - Discuss Dgraph
Hardly ever do I need to find a node by the exact date to the second which is what the eq filter does....
Read more >
GraphQL Search and Filter – How to search and filter results ...
Searching and filtering is a standard part of any GraphQL API. In this article, we'll learn how to add filtering capabilities to your...
Read more >
Cannot query on a date range, get back no results each time
Very strange. Must be abstracting some other variable somehow, probably a bug on graphql's end. As soon as I tried a new variable...
Read more >
Date Filter: Core Feature of our Datagrid - AG Grid
Date Filter allows filtering dates with {equals, notEquals, lessThanOrEqual, greaterThan ... To create a new date filter in a column, all you need...
Read more >
Filtering - Linear API
To exclude them, you can add another not equals comparator: query HighPriorityIssues {. issues(filter: {. priority: { lte: 2, neq: 0 }. }) ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found