useQuery data and error return undefined but network tab shows data

58 Views Asked by At

Hi I have a problem when trying to fetch data with urql's useQuery. Whenever I try to console.log() the data it says undefined but when I look in my network tab I can see the data. This only happens for useQuery mutations do work as expected.

This is my code:

const { executeQuery: getAddressDetails } = useQuery<AddressDetailsResponse>({
  query: ADDRESS_DETAILS_QUERY,
  pause: true,
  variables: {
    input: {
      context,
      session
    }
  },
  requestPolicy: 'network-only',
});

const fetchAddressDetails = async () => {
    const { data }  = await getAddressDetails();

    console.log(data.value);
    // shows undefined
};

I've also logged the result in onResults inside the mapExchange of urql like this:

const client = createClient({
  url: import.meta.env.VITE_GRAPHQL_URL ?? '',
  exchanges: [
    mapExchange({
      onResult(result) {
        console.log(result);
      }
    }),
    fetchExchange,
  ],
  fetchOptions: {
    headers: fetchHeaders()
  }
});

And here I DO see the data so I suspect something is going wrong with the caching I tried to fix it by adding cacheExchange({}) to the exchanges. But that didn't seem to have any effect.

0

There are 0 best solutions below