Reference Fields in GraphQL

We're excited to offer robust reference field capabilities within our GraphQL API, designed to streamline content relationships and enhance your development experience.

Single Reference Fields: Effortless Data Retrieval with Filtering

When a field in your content type references a single related content type, you'll find accessing that data to be incredibly straightforward. You can directly query the referenced content type, and even apply filters to refine your results.

Multiple Reference Fields: Seamless Connection Handling with Filtering and Ordered Results

For fields that reference multiple related content types, our API intelligently generates a connection. This enables you to query paginated results using the all<FieldSlug>(first: <number>) { edges { node { ... } } } pattern.

Importantly, the order of the items in the connection is determined by the order of the values within the CMS entry itself, providing you with fine-grained control over the display sequence. Additionally, you can apply filters directly to these connections, using the same structured format mentioned above, such as all<FieldSlug>(first: 10, <contentTypeSlug>Filter: { title: { contains: "GraphQL" } }) { edges { node { ... } } }. This combination of ordered results and filtering capabilities allows you to efficiently manage and retrieve collections of related data. Sorting within the connection is not supported, ensuring that the order you define in your content is preserved.

Polymorphic Relationships: Leveraging Fragment Spreads for Flexibility

Recognizing that a single reference field might point to different content types, we've incorporated the use of GraphQL fragment spreads. This powerful feature allows you to adapt your queries to the specific type of referenced content type, ensuring that you can access the appropriate fields with ease.

Example Query:

query {
  allPost(first: 99) {
    edges {
      node {
        author( authorFilter: { name: { contains: "John" } } ) {
          ... on Author {
            name
          }
        }
        allComments(
            first: 10,
            commentFilter: {
                content: {
                    contains: "important"
                }
            }
        ) {
            edges {
                node {
                  ... on Comment {
                    content
                  }
                }
            }
        }
      }
    }
  }
}