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.

Multi-argument custom query invalidation doesn't seem to work

See original GitHub issue

Issue Description

In a project, I have lists of entities called “hypotheses” that need to be refreshed via live queries. These lists are fetched using the following query:

type Query {
    project: ID!
    law: Int
    filters: ListFiltersInput!
  ): HypothesisPage!

Hypotheses are tied to specific “laws” (identified by integers). The second argument law can be null which returns all hypotheses regardless of their laws. I’m trying to invalidate based on a custom index that looks like this:

  field: "Query.hypotheses",
  args: ["project", "law"]

Here is the document I use on the frontend:

export const HypothesesQuery = gql`

  query Hypotheses($project: ID!, $law: Int, $filters: ListFiltersInput!)
    @live {
    hypotheses(project: $project, law: $law, filters: $filters) {

Now when creating an hypothesis with a createHypothesis mutation (resolver is successfully called), the following invalidation doesn’t work:


(project._id.toHexString() has the correct value) Any idea of what’s going on? Thank you.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

strblrcommented, May 16, 2022

You would still have the hard-coded double quotes, which can bring weird indices collision. For example imagine a nullable query argument of type String: null and "null" would serialize to the same index.

n1ru4lcommented, May 16, 2022

I see your point, in that case, JSON.stringify (aka might be the best solution. 🤔

I think adding json-stable-stringify as a dependency should be fine.

@strblr Would you like to create a PR with some tests and an implementation?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-Query and Query Invalidation Question - Stack Overflow
The way to achieve this using react-query is via queryCache.invalidateQueries to invalidate the cache after the mutation. From the docs:.
Read more >
Query Invalidation | TanStack Query Docs
For that purpose, the QueryClient has an invalidateQueries method that lets you intelligently mark queries as stale and potentially refetch them too! tsx....
Read more >
invalidateQueries doesn't work when enabled attribute is set ...
Hi, im using "react-query": "^3.24.3" and this issue is still happening, i have a query defined with enable: false and when i want...
Read more >
Reading and writing data to the cache - Apollo GraphQL Docs
Watched queries can control what happens when they're invalidated by updates to the cache, by passing options like fetchPolicy and nextFetchPolicy to client....
Read more >
Mastering Mutations in React Query | TkDodo's blog
There is however a second, integral part to working with data: ... A mutation that likes a blog post has no ties towards...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found