I'd like to query a content relationship that's part of a slice and cannot figure out how to do it. I have two objects in my repo - Publications and Subjects. I am trying to get all publications that have a particular Subject, but can't. Here is the query:
query MyQuery {
allSubjects(uid: "education") {
edges {
node {
_meta {
uid
}
}
}
}
allPublications{
edges {
node {
title
body {
...on PublicationBodyPublication_subjects {
fields {
subject {
...on Subject {
_meta {
uid
}
}
}
}
}
}
}
}
}
}
I want to be able to pass the UID of the Subject down to the allPublications query and filter where the uid of the Subject in the slice is equal to the uid of the subject I have chose (here, I've hard-coded 'education' as an example, but I would use a variable in the future).
I have tried restructuring the data model to have a group in which folks choose a content relationship, instead of a slice, and I can't get that to work either.
Our users want/need a controlled vocabulary for the Subject object, so we cannot use tags here. They need to be able to add/edit the subjects, but also assign Subjects to a Publication.
I am using Gatsby with the gatsby-source-prismic-graphql plugin to generate pages. I can generate a page for each Publication and a page for each Subject just fine, but I want to list all Publications of a particular subject on the Subject page and cannot figure out a way to do this.
Hi Danielle, unfortunately it isn’t possible to query/filter by a Content Relationship field which is inside of a Group or a Slice. In order for this to work, the Content Relationship field needs to be at the top level of the Custom Type.
The other thing is that you can’t use the UID value for this. It only works with the document ID of the linked document (the linked subject in your case).
I just wanted to chime in and mention that I ran into this same issue/limitation and would love to be able to query relationships within groups/slices via graphQL