apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.38k stars 2.66k forks source link

fetchMore with fetchPolicy: "no-cache" makes two requests #11965

Closed username14415 closed 3 months ago

username14415 commented 4 months ago

Issue Description

fetchMore useQuery with fetchPolicy: "no-cache" just makes two requests. One with variables and the second request is with default variables. I can't post a link to reproduction, the requests are visible on the backend. NextJS 14.2 dev mode.

Link to Reproduction

-

Reproduction Steps

const { loading, fetchMore } = useQuery(GET_MESSAGES, { fetchPolicy: "no-cache", onCompleted: handleCompleted, onError: handleError, variables: { slug: params.slug, }, });

@apollo/client version

3.10.8

alessbell commented 3 months ago

Hi there @username14415 👋 Unfortunately, without a reproduction there's not much I do to help. If you're able to create one, I'd be happy to take a look.

username14415 commented 3 months ago

@alessbell

const GET_MESSAGES = gql query GetMessages($slug: String!, $offset: Int) { getMessages(slug: $slug, offset: $offset) { id content } }

const { fetchMore } = useQuery(GET_MESSAGES, { fetchPolicy: "no-cache", variables: { slug: "example-slug } }); const fetch = await fetchMore({ variables: { offset: 123 }});

Using fetchMore with "fetchPolicy: "no-cache" shows 2 requests. The requests are visible on the backend. The first request has my own set variables (in this case offset: 123 and default variable slug). The second request has only default variable (slug).

jerelmiller commented 3 months ago

Hey @username14415 👋

I believe I'm able to reproduce this. Check out this reproduction which shows the multiple requests. I see the 2nd request kicked off after the first resolves. It helps to open this up the app in a separate window: https://y37kx4-3000.csb.app/. For whatever reason console logs are duplicated in the split view version giving a false sense of what is happening.

jerelmiller commented 3 months ago

I've got a failing test written for this in https://github.com/apollographql/apollo-client/pull/11974. I've discovered some deeper issues with this as well that I think we need to discuss as a team, so I'm going to leave this in draft for now. Thanks for reporting the issue!

github-actions[bot] commented 3 months ago

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

github-actions[bot] commented 2 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.