GraphQL query works with GraphiQL editor but returns "null" in my program

Hi,

So this is my query :

 {
    allProducts {
      edges {
        node {
          body {
            ... on ProductBodyProduct_description {
              variation {
                ... on ProductBodyProduct_descriptionDefaultSlice {
                  primary {
                    title
                    price
                  }
                  items {
                    image
                  }
                }
              }
            }
          }
        }
      }
    }
  }

I grab all documents of type Product then I want to access the fields inside their "product_description" slice.

It works fine on GraphiQL where I get my data:

But in my program I get { data: null, loading: false, networkStatus: 7, stale: true }. So not a 400 error but no data.

This is my program:

After some tests I figured that I get the data as long as I dont use union types. For example if I fetch all documents or just do:

{
  allProducts {
    edges {
      node {
        test
      }
    }
  }
}

Then in my program I properly get:

{
  data: {
    allProducts: { edges: [Array], __typename: 'ProductConnectionConnection' }
  },
  loading: false,
  networkStatus: 7,
  stale: false
}

Any idea why it's not working as soon as I try to access my slice ?

Hi Lucien,

Welcome to the Prismic community.

It seems the problem here is that you are using the CDN in your endpoint call where that is not correct.
Basically, your endpoint call should something like:

https://handyamo-www.prismic.io/graphql

For more please check our documentations for GraphQL

Please let us know if you need any further assistance,
Fares

Thanks Fares. I removed the CDN part in the endpoint but the query was still returning null. I ""fixed"" the problem by adding fetchPolicy: 'no-cache' in the query parameter like this:

 client.query({ query: query(), fetchPolicy: 'no-cache' })

Now I get my data. So was this a cache issue ?

Hi @lucien

My understanding of the issue is that you where using the cdn in the endpoint, this was incorrect, using CDN in the endpoint is actually recommended.

When you did your first request with the cache activated your null response got cached, so you had to disable to the cache to make it work.

But the cache is not the issue here, you can activate the cache back and it should work (if it doesn't work then you need flush your cache).

Hope that this helps,
Fares

This thread has been closed due to inactivity. Flag to reopen.