Issue with group containing relationships

Good day I am having an issue with queuing against a group that contains a relationship.

I have tried the following:

  const collections = await api.getAllByType('collection', {
    graphQuery: ` {
      collection {
        title
        description
        products {
          products_product {
            uid
            title
            product_image
            modal_image
          }
        }
      }
    }`
  })

Also tried using

await api.getAllByType('collection', {
    fetchLinks: ['product.product_image', 'product.title']
  })

Both of these queries compile and work but in the end the data inside the relationship returns undefined.

[0] TypeError: /Users/johngrange/Projects/portfolio/views/pages/collections.pug:13
[0]     11|           each collection in collections
[0]     12|             each product in collection.data.products
[0]   > 13|               h1= product.data.title

[0] Cannot read property 'title' of undefined

It also fails in code if I try the following:

  collections[0].data.products.forEach(product => {
    console.log(product)
    console.log(product.title)
  })
[0]   products_product: {
[0]     id: 'Y7uIehEAACEAJtPO',
[0]     type: 'product',
[0]     tags: [],
[0]     lang: 'en-us',
[0]     slug: 'silver-necklace',
[0]     first_publication_date: '2023-01-09T03:22:41+0000',
[0]     last_publication_date: '2023-01-15T04:47:13+0000',
[0]     uid: 'silver_necklace',
[0]     data: {
[0]       uid: 'silver_necklace',
[0]       title: 'Silver Necklace',
[0]       product_image: [Object],
[0]       modal_image: [Object]
[0]     },
[0]     link_type: 'Document',
[0]     isBroken: false
[0]   }
[0] }
[0] undefined // This should be the title, and even though it shows above clearly it is not accessiable

I have also tried:

console.log(product.data.title) 
[0] (node:63478) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'title' of undefined
[0]     at /Users/johngrange/Projects/portfolio/app.js:123:30
[0]     at Array.forEach (<anonymous>)
[0]     at /Users/johngrange/Projects/portfolio/app.js:121:32
[0]     at processTicksAndRejections (internal/process/task_queues.js:95:5)

In addition , it seems my GraphQL explorer does not work, when I try to query I only get back "", and the documentation tab is empty.

Actually I was able to get this to work in the html :slight_smile:

            each product in collection.data.products
                h1.product__title= product.products_product.data.title

So I guess the only issue remaining is how can I get the GraphQL explorer working?

Hello @john

Thanks for reaching out to us. To debug the query, I need either of anything:

  1. Paste the Custom Type JSON structure or
  2. Repo URL and name of the custom Type where you add the Content relationship field in the Group.

Thanks,
Priyanka

The url is : https://johngrange.prismic.io/graphql

As you can see in the screenshot, I get an empty response, no error and no documentation on right hand side.

Hello @john

I can reproduce the issue, and it seems the server is not fulfilling the request. I asked my dedicated team to further investigation. I will come back to you as I hear back from them.

Thanks,
Priyanka

Great thank you! looking forward to going forward :smiley:

Yup I am aware, was exploring the GraphQL to try and get a better understand on how the data was represented. I did eventually figure out my problem but it would still be helpful to get the GraphQL working so I can explore as I continue development.

Thank you,
John

Of course. We'll keep you updated. As soon as there's an available fix, we'll let you know.
Thanks