Youtube Resource:
- create content fragment: https://www.youtube.com/watch?v=7SFYjGjSveQ&t=9s&ab_channel=TechTalkwithRitesh
- create content fragment: https://www.youtube.com/watch?v=l9AIjvL_n8A&t=867s
- expose fragment via rest api: https://www.youtube.com/watch?v=92s3GwRISZQ&ab_channel=SankhamMarTechChannel
AEM Graphql package:
Note - If you are looking for content fragment creation in 6.5 classic, pls check: https://www.youtube.com/watch?v=sftCl5y4GN4&ab_channel=AdobeExperienceManagerUserGroups
Content fragment structure is defined by Content fragment model. So first we should create the model and then actual content fragment. For that:
- Create an aem app using mvn command. Login to aem dashboard. This should load the start page. An aem app should have permission to create the content fragment
- so to provide this permission, navigate to tools => general => configuration manager => => select => properties => check content fragment models and graphic => save.
- Post this we should create the content fragment model. For that, navigate to tools => general => content fragment models
- Select and click create
- Enter model title and save
- Once successfully saved, click on open button.
- Select JSON Object type and enter the title of that json object and save the model. This model will define the structure of the upcoming content fragment
- Once done, go to /aem/start.html
- Select Assets => Files =>
- Click on create button and choose Content Fragment from the options
- Select previously generated content fragment model and click on next
- Enter title and description for this new content fragment and click on save.
- Once successfully saved, click on open button.
- Here we should see the structure of JSON object that we defined in content model. Populate your data as json and click on save. This will create the new content fragment.
- Once saved, click on preview button on left side navbar to view the saved content fragment data. copy the
_path
attribute which we need to query via graphql.

Inorder to consume content fragment, we need to:
- create a configuation for our app and then
- create the graphql endpoint using that configuration.
- create persisted queries in graphiql editor to expose them as actual rest endpoints
- navigate to /aem/start.html.
- click on tools => General => Configuration Browser
- Select the app, and click create.
- Enter title and name of that configuration and also select Graphql persisted queries & content fragment models from the options.
- Click on create to create the configuration
- navigate to /aem/start.html.
- click on tools => General => Graphql
- click on create
- This should display a modal dialogue to enter the endpoint name. Choose the configuration that we created from above steps.
- Save and publish the endpoint.
- navigate to /aem/graphiql.html and choose the endpoint that we created
- write a graphql query to call the content fragment by path (this is where the copied
_path
comes handy) as below:
// example path looks like this: /content/dam/aem-cloud-app/landing-page
{
<your-content-model-name>ByPath(_path: "<your-copied-path-of-content-fragment>") {
item {
<your-json-object-name-provided-in-content-fragment-model>
}
}
}
- executing above query should return the data that we saved in provided content fragment
- copy the url of saved query and test it using postman as shown below:
So either pass basic authentication or whitelist the api /graphql/execute.json/*
in aem dispatcher