내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
해결됨

Pass asset metadata from GraphQL Query

Avatar

Level 9
While creating the content fragment, I have added tags. That is saved here.
 
From GraphQl API, I can expose the content as shown below
 _metadata {
      stringArrayMetadata {
           name
           value
     }
}  
 
Similary, I have added tags to asset. That is present here: /content/dam/test.png/jcr:content/metadata
cq:tags
value: test:abc
 
How to expose this tags from GraphQL API from an asset?
I know about this one to get asset metatags
 
But, from GraphQL only, I need to pass the tags, metatags details. Is it possible?
Note: I am using AEM AMS 6.5.23 version application.

 

cc @arunpatidar @giuseppebag  @SantoshSai @HrishikeshKagne 

Thanks in advance

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Community Advisor

@Mahesh_Gunaje 

 Your Content Fragment Model’s “content reference” field (Logo) is returning a GraphQL type of ImageRef, and in AEM, that type does not include _metadata or metadata fields.

Only Content Fragments have a _metadata property exposed through GraphQL.
Assets (images, PDFs, etc.) referenced via a content-reference or media field in a fragment are not treated as GraphQL nodes, just lightweight objects with:

  • _path

  • mimeType

  • width

  • height

  • altText

That’s why your query:

metadata {
  stringArrayMetadata {
    name
    value
  }
}

throws a validation error - because metadata isn’t part of ImageRef schema.

 

If you really want the asset’s cq:tags available through GraphQL:

  1. Create a custom Sling Model that extends your fragment output.

  2. Inject the referenced asset’s Resource (from the content-reference field).

  3. Read cq:tags from /jcr:content/metadata.

  4. Add a new getter, eg getAssetTags().

  5. Annotate with @GraphQLField and register it via the GraphQL extensions bundle.

That will let you query:

Logo {
  _path
  width
  height
  assetTags
}

This requires OSGi bundle + code deployment but works cleanly without changing GraphQL schema manually.


Santosh Sai

AEM BlogsLinkedIn


원본 게시물의 솔루션 보기

4 답변 개

Avatar

Level 10

hi @Mahesh_Gunaje,

GraphQL API is primarily designed for Content Fragments, not standalone DAM assets. Direct asset metadata (including tags from /jcr:content/metadata/cq:tags) cannot be queried via GraphQL unless the asset is referenced through a Content Fragment. 

First, create a Content Fragment model with a "Content Reference" field type that points to assets, i.e. it accepts only images as type.​ Then, execute a query to retrieve asset metadata from the referenced asset (here CF field name is assetReference):

{
  myContentFragmentList {
    items {
      assetReference {
        ... on ImageRef {
          _path
          _authorUrl
          _publishUrl
          _metadata {
            stringArrayMetadata {
              name
              value
            }
          }
        }
      }
    }
  }
}

 

Avatar

Community Advisor

Hi @Mahesh_Gunaje,

The GraphQL capabilities are limited to Content Fragments, not Assets.
That’s why you’re able to expose metadata and tags for a Content Fragment but not directly for a DAM asset.

Ideally, when you create a GraphQL endpoint, it only exposes:

  • Content Fragment fields (and references),

  • Metadata you’ve modeled in the fragment model, and

  • Related assets referenced by those fragments (via reference or media type fields).

I would, Expose asset data via Content Fragment reference

  • Add a field in your fragment model to reference an asset.

  • Add a custom Sling Model or servlet that reads the asset’s metadata (like cq:tags) and exposes it as a computed field.

  • Example: Create a custom GraphQL schema extension that adds a tags property by reading asset.getMetadata("cq:tags").


Santosh Sai

AEM BlogsLinkedIn


Avatar

Level 9

Hi @SantoshSai   @giuseppebag 

Forgot to give you more contexts. My bad.

Note: My CF model has content reference field, there I have selected a DAM image(which has tags assigned to) path.

Now, when I write below mentioned query, getting error: Field '_metadata' in type 'ImageRef' is undefined",

GraphQL-Query.jpg

 

Thanks

Mahesh

Avatar

정확한 답변 작성자:
Community Advisor

@Mahesh_Gunaje 

 Your Content Fragment Model’s “content reference” field (Logo) is returning a GraphQL type of ImageRef, and in AEM, that type does not include _metadata or metadata fields.

Only Content Fragments have a _metadata property exposed through GraphQL.
Assets (images, PDFs, etc.) referenced via a content-reference or media field in a fragment are not treated as GraphQL nodes, just lightweight objects with:

  • _path

  • mimeType

  • width

  • height

  • altText

That’s why your query:

metadata {
  stringArrayMetadata {
    name
    value
  }
}

throws a validation error - because metadata isn’t part of ImageRef schema.

 

If you really want the asset’s cq:tags available through GraphQL:

  1. Create a custom Sling Model that extends your fragment output.

  2. Inject the referenced asset’s Resource (from the content-reference field).

  3. Read cq:tags from /jcr:content/metadata.

  4. Add a new getter, eg getAssetTags().

  5. Annotate with @GraphQLField and register it via the GraphQL extensions bundle.

That will let you query:

Logo {
  _path
  width
  height
  assetTags
}

This requires OSGi bundle + code deployment but works cleanly without changing GraphQL schema manually.


Santosh Sai

AEM BlogsLinkedIn