September 24, 2026

Working with GraphQL in AEM

GraphQL is a query language for APIs, originally developed at Facebook. In AEM it gives developers a flexible, efficient way to fetch content, which makes it easier to build applications on top of AEM. This post covers the basics.

What is GraphQL?

Unlike REST, which uses a fixed structure for requesting and returning data, GraphQL lets developers specify exactly the data they want in a single query. Applications fetch only what they need, which reduces the data transferred over the network and improves performance.

AEM with GraphQL

Advantages of GraphQL in AEM

  • Flexibility and control. Developers specify exactly what to fetch, so queries can be optimized and unnecessary data avoided.
  • Performance. Less data over the network and optimized queries make AEM-based applications faster.
  • A strongly typed schema. The schema defines the types that can be queried, so invalid queries are rejected with clear errors before any data is returned, which makes debugging easier.
  • Easy integration. GraphQL returns JSON, so AEM content plugs easily into other technologies and platforms.

How GraphQL works in AEM

AEM's GraphQL API delivers Content Fragments headlessly. The schema is generated from your Content Fragment Models: each model becomes a type, and its fields become the fields you can query. Enable GraphQL for the configuration folder that holds your models, then create a GraphQL endpoint for it in Tools > General > GraphQL.

Clients send queries to the endpoint and receive the requested content as JSON, ready to use in single-page applications, mobile apps and other channels. The AEM GraphQL API is for reading content: it supports queries, not mutations. For production use, persisted queries — stored on AEM and called by name — are recommended, because they can be cached by the dispatcher and CDN.

Testing GraphQL in AEM

AEM includes the GraphiQL IDE, a browser-based tool for writing and testing queries, available from the Tools console. Write and run a query in its editor and see the result in the right-hand panel; the built-in documentation explorer shows the available schema, which helps when writing queries.

Queries can also be tested with other tools, such as Postman or Apollo Client, before they go into an application.

Conclusion

GraphQL makes fetching AEM content more flexible and efficient, and improves the performance and reliability of AEM-based applications. Whether you are building a new application on AEM or improving an existing one, it is well worth considering.

Before GraphQL, AEM delivered fragments as JSON through the Sling Model exporter — see AEM 6.4 Content Fragment output as JSON and Content Services endpoints.