Apollo Client GraphQL error is lost / undefined after second time loading the page (refreshing the browser)

Apollo Client GraphQL error is lost / undefined after second time loading the page (refreshing the browser)


0

I am using Apollo Client in my Astro project.

I have the following GraphQL query:

const { data, loading, errors } = await client.query({
  query: GET_PAGE,
  variables: {
    url: uri,
  },
  errorPolicy: 'all',
});

Also I defined my errorLink, based on the Apollo docs:

const errorLink = onError(({ graphQLErrors, networkError }) => {
  if (graphQLErrors)
    graphQLErrors.forEach(({ message, locations, path }) =>
      console.log(
        `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
      )
    );
  if (networkError) console.log(`[Network error]: ${networkError}`);
});

export const client = new ApolloClient({
  cache: new InMemoryCache(),
  ssrMode: true,
  link: from([errorLink, httpLink]),
});

When I go to e.g. a non-existing page first time a get the GraphQL error in my terminal:

[GraphQL error]: Message: 404: Not Found, Location: [object Object],
Path: page

When I refresh the same page the error is gone and is undefined.

When I add fetchPolicy: 'no-cache', to the query the GraphQL error is always showing.

Why is this and what do I have to do?


Load 3 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *