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

why fetchMore sen two requests to my GraphQL server #9363

Closed
Tracked by #9504
videni opened this issue Jan 26, 2022 · 2 comments
Closed
Tracked by #9504

why fetchMore sen two requests to my GraphQL server #9363

videni opened this issue Jan 26, 2022 · 2 comments

Comments

@videni
Copy link

videni commented Jan 26, 2022

there is a button named "next" , when user clicks this button ,it is supposed to be one, but two requests sent to server.

 const { loading, error, data, fetchMore} = useQuery(GET_CUSTOMER_TICKETS, {
    variables: {
      first: DEFAULT_PAGE_SIZE,
      last: DEFAULT_PAGE_SIZE,
    },
  });
 

 const next = (after: string) =>  (e: React.SyntheticEvent) => {
    fetchMore({
      variables: {
        after
      },
    });
  };

the first time.

image

the second time:

image

you see , the second request without after cursor.

I don't know why.

there is a similar issue here, but add

extFetchPolicy: "cache-first"

not working at all.

@videni videni changed the title why fetchMore send too requests to SraphQL server why fetchMore send too requests to my GraphQL server Jan 26, 2022
@videni
Copy link
Author

videni commented Jan 26, 2022

I store these cursors with useState hook, then I got one request.


  const [after, setAfter] = useState<string|null>();
  const [before, setBefore] = useState<string|null>();

  const { loading, error, data, fetchMore} = useQuery(GET_CUSTOMER_TICKETS, {
    variables: {
      first: DEFAULT_PAGE_SIZE,
      after,
      last: DEFAULT_PAGE_SIZE,
      before
    },
  });

  const next = (after: string) =>  (e: React.SyntheticEvent) => {
    fetchMore({
      variables: {
        after
      },
    });

    setAfter(after);
    setBefore(null);
  };

image

the first one is an options request , so not related to this issue, however the `args of my read policy, called two times, one with the after cursor, one with no cursor. why the read function got called with no cursor? since the after cursor is passed to fetchMore function, I swear the after cursor is not empty.

 read(existing, options) {
      const {
        args,
        readField,
        canRead,
      } = options;
      if (!existing) {
        return existing;
      }

      const {
        first,
        after,
        last,
        before
      } = args as ConnectionParameter;
    ///...
}

@videni videni changed the title why fetchMore send too requests to my GraphQL server why fetchMore sen two requests to my GraphQL server Jan 26, 2022
@videni
Copy link
Author

videni commented Jan 26, 2022

closed, as it is similar with issue fetchMore and fetchPolicy: cache-and-network does not work together

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant