All other slices using GraphQuery

Hello there!

Looking for another help:

Using the GraphQuery to query the Slices with relationship, for example:

page {
  ...pageFields
  body {
    ...on someSlice {
        non-repeat {
          ...non-repeatFields
        }
    } 
  }
}

But now I'm only getting the someSlice slice. How can I query all the others?
Should I continue to specify one by one? ...on anotherSlice
Is there any option to query all the rest?

1 Like

Hello @deki

Thanks for reaching out to us.

Are you trying to fetch the slice content with the Content relationship filed? In that case, you need to specify the Content Relationship field in your GraphQuery. Here is the documentation for this .

page {
  ...pageFields
  body {
    ...on someSlice {
        non-repeat {
          ...non-repeatFields
          content_relationship_field_name {
           ... on type_of_linked_doc {
             ...linked_doc_type_Fields
          }
        }
     } 
   }
}

Give this a try and let me know.

Thanks,

Priyanka

Thanks a lot @Priyanka! All of our nested relationships are working now.

But like in this example above, now I'm getting only the "someSlice" slice.
How do I get all the rest slices? Should I specify one by one?

1 Like

Hello Hideki, yes, you need to specify each slice to get the content.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Is it planned to improve this in the future? Having a rather generic Page custom type with many different slices and variations, listing every slice is not really a viable solution. I'd imagine something similar to the ...rest keyword, when destructuring objects in JS.

2 Likes

Hi @j0nezz,

Welcome to the community!

While this is not something that is planned right now, it is logged as a feature request. I can see how something like a ...rest keyword like this would make developing GraphQueries much faster.

If/when anything changes for this one the team will update everyone here.

Thanks.

1 Like

Any news on this feature? Having a way to query all other slices would be a much better solution than having to specify each one

1 Like

At the moment we still have no news. You can visit our progress page, where you can learn about all the new features we are currently working on.

Thank you

Hi! I'm facing the same issue here.
Just to try to understand:
I have a Custom Type called "pages".
Under this one, I have at least 30 slices with repeatable and non-repeatable fields.
I need to get the data from a content relationship (list) from one of those slices (slice01), so, my query should be something like this?

pages {
    ...pagesFields
    slices {
      ...on slice01 {
        variation {
          ...on default {
            primary {
              ...primaryFields
            }
            items {
                ...itemsFields
                list {
                  ...on list {
                    ...listFields
                  }
                }
            }
          }
        }
      }
      ...on slice02 {
        variation {
          ...on default {
            primary {
              ...primaryFields
            }
            items {
                ...itemsFields
            }
          }
        }
      }
      ...on slice03 {
        variation {
          ...on default {
            primary {
              ...primaryFields
            }
            items {
                ...itemsFields
            }
          }
        }
      }
      ...on slice04 {
        variation {
          ...on default {
            primary {
              ...primaryFields
            }
            items {
                ...itemsFields
            }
          }
        }
      }
      ...on slice05{
        variation {
          ...on default {
            primary {
              ...primaryFields
            }
            items {
                ...itemsFields
            }
          }
        }
      }
      ...on slice06 {
        variation {
          ...on default {
            primary {
              ...primaryFields
            }
            items {
                ...itemsFields
            }
          }
        }
      }
      ...on slice07 {
        variation {
          ...on default {
            primary {
              ...primaryFields
            }
            items {
                ...itemsFields
            }
          }
        }
      }
      ...on slice08 {
        variation {
          ...on default {
            primary {
              ...primaryFields
            }
            items {
                ...itemsFields
            }
          }
        }
      }
      ...on slice09 {
        variation {
          ...on default {
            primary {
              ...primaryFields
            }
            items {
                ...itemsFields
            }
          }
        }
      }
[repeating.....]
      ...on slice30 {
        variation {
          ...on default {
            primary {
              ...primaryFields
            }
            items {
                ...itemsFields
            }
          }
        }
      }
    }
  }

It does not work for me, because if I send this kind of query, I receive a 413 error...

Please, tell me that I'm doing something very wrong, and we have a better way to do that!
Thanks! :slight_smile:

1 Like

Hey @albertojr, what's the API ID of the Content relationship field in the repeatable zone of the slice01?

If your query is accurate, the field is called list and links to documents of the type list as well.

Hey @Pau! Thanks for your time!

I'm able to get the data from this slice without any problems, even though it's a content relationship. My problem is the other slices that I have to request one by one. Is this correct? In this case, it's just a slice that I have to get the data from this type of content.

If you wanna retrieve all the Slices from the linked document, you could first get the ID of the linked doc using GraphQuery and then do a query by ID

Like many other devs in this thread, I would really appreciate an option to have an operator like ...slicesFields that would get all the slices, which don't need a specific deeper query.

In the case of a page custom type that includes numerous slices, it's very laborious and error prone to specify all other slices including their variations...

3 Likes

Hi @Pau,

Phil mentioned that his was logged as a feature request, where can we support it ?
On any document type, having a graphQuery to fetch linked data effectively makes adding new slices types to the page a 2 step process, time consuming and error prone. ...slicesFields may not look like much but it would be a game changer.

Currently it seems the easiest way to fetch links without going into list-all-slices-type-in-your-graph-query hell is to make multiple API calls, which is bad for everyone.

2 Likes

I understand and agree that this would be a great feature. You can add feature requests from this page:

Add your use case there as well as any other feature requests you might have.

1 Like