I am trying to integrate Assets with graphql on AEM, but I need to create a content fragment for each asset. I am wondering if I can create like a global json file and integrate that with graphql on AEM.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @FranciscoMu1,
Not directly, but GraphQL only supports querying Content Fragments, because:
GraphQL schema is generated only from Content Fragment Models (CFMs)
Assets (binary files in DAM) are not part of the GraphQL schema unless wrapped inside a CF
If CFs are required, write a one-time job/script that loops through assets in a folder and creates CFs for each.
You can even associate the asset via a contentReference
field in the CF.
Adobe provides APIs for CF creation:
ContentFragment cf = contentFragmentManager.create("/path/to/model", "cf-name", "/target/path", properties);
This gives you GraphQL capability without manual effort.
You can create one large Content Fragment with a model like this:
{
"assets": [
{
"title": "Asset 1",
"path": "/content/dam/assets/asset1.jpg",
"tags": ["product", "promo"]
},
{
"title": "Asset 2",
"path": "/content/dam/assets/asset2.jpg",
"tags": ["banner"]
}
]
}
Then expose this single CF via GraphQL and query it like:
{
globalAssetIndexByPath(_path: "/content/dam/global-index") {
item {
assets {
title
path
tags
}
}
}
}
If GraphQL is not mandatory, you can:
Build a servlet at /bin/assets-index.json
It fetches and returns JSON listing all assets in a folder (with metadata)
But this won’t be usable via GraphQL APIs - it’s a REST endpoint, not GraphQL.
If GraphQL access is mandatory, then:
Create a global “index” CF (option 2 above)
Auto-generate its JSON using a scheduled job or manual script
Or - if you need fine granularity, auto-create CFs for each asset and link them
Hope that helps!
Hi @FranciscoMu1,
Not directly, but GraphQL only supports querying Content Fragments, because:
GraphQL schema is generated only from Content Fragment Models (CFMs)
Assets (binary files in DAM) are not part of the GraphQL schema unless wrapped inside a CF
If CFs are required, write a one-time job/script that loops through assets in a folder and creates CFs for each.
You can even associate the asset via a contentReference
field in the CF.
Adobe provides APIs for CF creation:
ContentFragment cf = contentFragmentManager.create("/path/to/model", "cf-name", "/target/path", properties);
This gives you GraphQL capability without manual effort.
You can create one large Content Fragment with a model like this:
{
"assets": [
{
"title": "Asset 1",
"path": "/content/dam/assets/asset1.jpg",
"tags": ["product", "promo"]
},
{
"title": "Asset 2",
"path": "/content/dam/assets/asset2.jpg",
"tags": ["banner"]
}
]
}
Then expose this single CF via GraphQL and query it like:
{
globalAssetIndexByPath(_path: "/content/dam/global-index") {
item {
assets {
title
path
tags
}
}
}
}
If GraphQL is not mandatory, you can:
Build a servlet at /bin/assets-index.json
It fetches and returns JSON listing all assets in a folder (with metadata)
But this won’t be usable via GraphQL APIs - it’s a REST endpoint, not GraphQL.
If GraphQL access is mandatory, then:
Create a global “index” CF (option 2 above)
Auto-generate its JSON using a scheduled job or manual script
Or - if you need fine granularity, auto-create CFs for each asset and link them
Hope that helps!
Thank you, I will try the second approach.
Views
Replies
Total Likes
@FranciscoMu1 are you using AEM 6.5 or AEM Cloud. You can use newly released feature of aem asset delivery apis if it is aem cloud.
https://adobe-aem-assets-delivery.redoc.ly/#operation/search
I'm using AEM Cloud, thanks I will review the link.
Views
Replies
Total Likes
Views
Likes
Replies