Query by a Content Relationship/Link field

This page shows you how to query your results by a Content Relationship/linked document field.

❗️It must be a top-level field

When using the Content Relationship or Link field as arguments, they have to be at the top level of a Custom Type and not inside a Group field or a Slice.

The where argument

In order to query by a field such as a Content Relationship field, you can use the where argument. It takes this form:

where: { category: "field" }

The where argument can also be used with Key text, Select, and Number fields.

Example query

In the following example you can see that we are querying every post where the Content Relationship field called link contains an id field with the value XECf-BAAACEACaD9. This value is the ID of the linked document.

You must use the document ID

When querying by a Content relationship field, the value passed to the argument can only be the ID of a given document. If you use a different value, for example: a UID field, the query won't work.

query {
  allPosts(where : {link: "XECf-BAAACEACaD9"}) {
    edges {
      node {
        link {
          ... on Author {
            _meta {

NOTE: If your content relationship field API ID has an underscore, for example linked_field, this can cause the query to break.