Filter results by a Content Relationship/Link field

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

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:

Copy
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.

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

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