Apollo GraphQL local state getting undefined with useQuery on refreshing app

Viewed 830

I get my data on the first initial load, and then if I refresh my app, my data becomes undefined. Only when I change the default state, I get the initial load data again.

const cache = new InMemoryCache();
cache.writeData({
  data: {
    apples: {
      sets: [],
      __typename: 'Apples',
    },
  },
});

In one of my components, I have:

const {data, loading, error} = useQuery(appleSets);
console.log('local state', data, loading, error, useQuery(appleSets));

const appleSets = gql`
  query {
    apples @client {
      sets
    }
  }
`;

On the first load, I get my console logged with apple data and the sets empty array, but then when I refresh, it becomes undefined. If I change the default values, the initial load gets data again. Why does this undefined?

0 Answers
Related