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.

relayPagination and network-only

See original GitHub issue

Hi All

I have the following query

query FriendsQuery($after: String!) {
  me {
    id
    friends(after: $after) {
      edges {
        node {
          ...FriendshipFragment
        }
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}

And the following hook


export const useFriends = () => {
  const client = useClient();
  const [{ fetching, error, data }] = useQuery<
    FriendsQueryQuery,
    FriendsQueryQueryVariables
  >({
    query: FRIENDS_QUERY,
    requestPolicy: "network-only",
    variables: {
      after: "",
    },
  });

  const friends =
    data === undefined ? undefined : data?.me?.friends ?? undefined;

  const fetchMore = React.useCallback(
    (cursor: string) => {
      return client
        .query<FriendsQueryQuery, FriendsQueryQueryVariables>(
          FRIENDS_QUERY,
          { after: cursor },
          { requestPolicy: "network-only" }
        )
        .toPromise();
    },
    [client]
  );

  return React.useMemo(
    () => ({
      fetching,
      error,
      friends,
      fetchMore,
    }),
    [fetching, error, friends, fetchMore]
  );

Results are merged using relayPagination

resolvers: {
  User: {
    friends: relayPagination()
  }
}

I have a component that does an infinite scrolling and shows all my friends.

When the component is unmounted and afterwards remounted i would like to fetch again the lists of friends (hence the network-only)

The problem is that due to the relay pagination the friends variable contains all the friends fetched from the previous mount with pageInfo.hasNextPage === false.

The only request that is requested again is the initial with after === “”

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
zenioscommented, Mar 27, 2020

As for the very specific, I dont think i am the only person who want to use relayPagination with cache-and-network || network-only

2reactions
zenioscommented, Jan 20, 2021

Nope i did the merging manually without using relayPagination

On Wed, Jan 20, 2021 at 12:14 PM Vinícius Lemes notifications@github.com wrote:

I’m having what I think is the same problem described here. @zenios https://github.com/zenios did you end up finding a solution/workaround?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FormidableLabs/urql/issues/672#issuecomment-763496418, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAV3YMDTQV6IZBXIBVZ52DS22UJFANCNFSM4LUQKTKA .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pagination Container
hasMore is a function available on the relay prop. This function indicates whether there are more pages to fetch from the server or...
Read more >
Understanding pagination: REST, GraphQL, and Relay
A connection is a paginated field on an object — for example, the friends field on a user or the comments field on...
Read more >
relayPagination and network-only · Issue #672 · urql- ...
The problem is that due to the relay pagination the friends variable contains all the friends fetched from the previous mount with pageInfo....
Read more >
Pagination with minimal effort in Relay
This article will focus on simple pagination, without filters, and only paginating forward. But, Relay can paginate backwards just as easily ...
Read more >
Effortless Pagination with GraphQL and Relay? Really!
You start to realize that the cursor-based setup of a connection, along with a Relay pagination container, does not lend itself to this...
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