Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

is there a way to integrate graphql with Assets using a JSON file instead of a content fragment?

Avatar

Level 2

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

1. Programmatically Create Content Fragments per Asset (Automated CF generation)
  • 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.

2. Use a Shared "Global Asset Index" CF (Your JSON idea)

You can create one large Content Fragment with a model like this:

GlobalAssetIndex CFM:

{
  "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
      }
    }
  }
}
3. Create a Custom Servlet for JSON Access (outside GraphQL)

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.

Best Approach Recommendation

If GraphQL access is mandatory, then:

  1. Create a global “index” CF (option 2 above)

  2. Auto-generate its JSON using a scheduled job or manual script

  3. Or - if you need fine granularity, auto-create CFs for each asset and link them

Hope that helps!


Santosh Sai

AEM BlogsLinkedIn


View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

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

1. Programmatically Create Content Fragments per Asset (Automated CF generation)
  • 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.

2. Use a Shared "Global Asset Index" CF (Your JSON idea)

You can create one large Content Fragment with a model like this:

GlobalAssetIndex CFM:

{
  "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
      }
    }
  }
}
3. Create a Custom Servlet for JSON Access (outside GraphQL)

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.

Best Approach Recommendation

If GraphQL access is mandatory, then:

  1. Create a global “index” CF (option 2 above)

  2. Auto-generate its JSON using a scheduled job or manual script

  3. Or - if you need fine granularity, auto-create CFs for each asset and link them

Hope that helps!


Santosh Sai

AEM BlogsLinkedIn


Avatar

Level 2

Thank you, I will try the second approach.

Avatar

Community Advisor

@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

Avatar

Level 2

I'm using AEM Cloud, thanks I will review the link.