In this post we will learn AEM content fragment creation with graph ql. In the step by step process we can create an AEM content fragment from scratch and then explore the authored content as an endpoint using GraphQL.
1. Go to AEM start > Tools > General > configuration browser
2. Create a config under the folder project folder where you want to create configurations.
Add the title and select teh following checkboxes.
You have done setting your configuration folder.
3. Now, go AEM > tools > Assets > Content fragment model
4. Select your configuration folder, and craete a content fragment model. Open the model and add the elements and set the respective data type. We have created a model here that have one field with data type JSON.
Save the changes. You have done with the creation of CF model.5. Now, create content fragment in Assets. for that;
Goto AEM > Assets > and now select the folder where you want to create model. Here we are creating under We.Retail > en > cf directory.
6. We have created a content fragment with name 032025. Open this and add your data. As you an see here we have added a json object here.
Save the content fragment.
7. Now lets expose this content fragmnet in GraphQL. For that we will required create a graph QL endpoint. Go to AEM > Tools > Aseets> graph ql
Here give a name of your endpoint and select the project folder as path.
8. Now go to graphql editor to query this CF content. For that go to AEM start > Tools > General > GraphQL query editor or browse http://localhost:4502/aem/graphiql.html
Note: If you are using AEM 6.5 then, this option will not visible to you, and you need to install a package "content fragment with graphql". this package you can download frm software distribution portal.
9. In GraphQL explorer, write a query and select the endpoint in top-right dropdown. This is the same endpoint which we have created in above step 7.Query
{
sdgList { #content fragment name with List
items {
sdgdata #field name from content fragment model
}
}
}
No comments:
Post a Comment