Not able to query slice-machine slices with graphQuery

So I noticed a couple of things:

  1. I realise this is not documented and I will get the team on this today. You are trying to do this with Slice Machine Slices which require 2 things:
    a. That you specify the variation that you want to query like so variation{ ...ondefault-slice{
    b. You use primary and item keys instead of non-repeat and repeat keys.

  2. Your GraphQuery is more complicated than your imagining because you're trying to get the data from a Slice in a linked document from a link in a Slice of the parent document. So you need to go deeper. You full query should look like so:

{
  page{
    ...pageFields
    slices{
      ...on form_section{
        variation{
          ...on default-slice{
            primary{
              formLink{
                ...on form{
                  slices{
                    ...on form_input{
                      variation{
                        ...on default-slice{
                          primary{
                            ...primaryFields
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

and that's only one Slice from the linked document.

I was able to test this query in your API browser.
https://smallbydesign.prismic.io/api/v2/documents/search?ref=YedLOREAACoA6f28&q=[[at(my.page.uid%2C+"contact-us")]]&graphQuery={ page{ ...pageFields slices{ ...onform_section{ variation{ ...ondefault-slice{ primary{ formLink{ ...onform{ slices{ ...onform_input{ variation{ ...ondefault-slice{ primary{ ...primaryFields } } } } } } } } } } } } } }#format=json

There's better error reporting in the API Browser, I agree there could be better error messaging in the Client, I've made a feature request for this. To do this you need to encode your GraphQuery before adding it to the URL:
https://meyerweb.com/eric/tools/dencoder/

Your GraphQuery would go here:

https://smallbydesign.prismic.io/api/v2/documents/search?ref=YedLOREAACoA6f28&q=%5B%5Bat(my.page.uid%2C+%22contact-us%22)%5D%5D&graphQuery=[THIS IS WHERE YOUR QUERY GOES]#format=json

What is your use case for pulling contact forms in like this? Maybe there could be a better solution.

Thanks.

2 Likes