Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite refresh loops after adding a merge field. #8283

Open
ivands opened this issue May 25, 2021 · 2 comments
Open

Infinite refresh loops after adding a merge field. #8283

ivands opened this issue May 25, 2021 · 2 comments

Comments

@ivands
Copy link

ivands commented May 25, 2021

Ok so i have a query that should support cursor pagination.
I have 2 elements what use the same query.
But after adding the merge function inside the typePolicies, the queries will fetch infinitely.
This only happens because I have 2 elements on the page with this query.
Can someone please explain to me why this happens.
Because i'm lost for words.

query($query:String!, $limit:Int!, $cursor:String, $sort:SearchSort)
{
  game {
    search( input: { query: $query, limit: $limit, cursor: $cursor, sort: $sort } ) {
      found
      cursor
      items {
        id
        name
        provider
      }
    }
  }
}
const { loading, error, data } = useQuery(searchQuery, {
  fetchPolicy: 'cache-first',
  variables: {
    query,
    limit,
    sort,
  },
});
new InMemoryCache({
  typePolicies: {
    GameQuery: {
      fields: {
        search: {
          keyArgs: [ 'input', [ 'query', 'limit', 'sort' ] ],
          merge(existing = { items:[] }, incoming) => {
            return {
              cursor: incoming.cursor,
              found: incoming.found,
              items: [
                ...existing.items,
                ...incoming.items,
              ]
            }
          }
        }
      }
    }
  }
});

Versions
I'm using version 3.3.19

@benjamn
Copy link
Member

benjamn commented May 26, 2021

@ivands Can you try putting your code into a runnable reproduction so we can provide concrete advice?

As a side note, you generally don't want to include limit or sort arguments in your keyArgs, though I can't say for sure if that's a contributing factor here. Here's some discussion of what arguments belong in keyArgs.

@avoqado
Copy link

avoqado commented Jun 15, 2021

Same problem wtih infinitely fetch using offsetLimitPagination().
If I set keyArgs with one item, for example limit (but it doesn't suit me) it's works.
But if I set filter with many optins inside, I get infinitely fetch. And if I gen function instead array for keyArgs I also get nfinitely fetch.

What else is weird, I have 2 differents queries, one of them works all time, another get problems.

Query: {
  fields: {
    someField: {
      ...offsetLimitPagination(["limit"]), //works
      ...offsetLimitPagination(["filter"]), //doesn't work
    },
  },
 },

@bignimbus bignimbus removed the 🏓 awaiting-contributor-response requires input from a contributor label Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants