You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让AEM GraphQL返回jcr:lastModified日期作为内容片段元数据?

How to Include jcr:lastModified in AEM GraphQL Responses for Content Fragments

Great question—this is a common gotcha with AEM's Content Fragment GraphQL integration. Let me break down why this is happening and walk you through two reliable solutions to get jcr:lastModified (or any other JCR property from jcr:content) into your GraphQL response.

Why jcr:lastModified Isn't Returned by Default

AEM's Content Fragment GraphQL provider is configured to:

  • Expose all metadata stored under jcr:content/metadata (the standard metadata node for assets/content fragments)
  • Automatically include a few special fields from jcr:content: jcr:title and jcr:description (these are hardcoded exceptions)
  • Ignore other properties directly under jcr:content (like jcr:lastModified, jcr:created, etc.) unless explicitly configured to include them.

Solution 1: Add jcr:lastModified as a Custom Field in Your Content Fragment Model

This is the most straightforward no-code approach if you have access to the Content Fragment Model editor:

  1. Navigate to your Content Fragment Model

    • Go to Tools > Assets > Content Fragment Models in AEM.
    • Find the model used by your rahjang-benifit content fragment and open it for editing.
  2. Add the custom property to the model

    • Switch to the GraphQL tab in the editor.
    • Scroll to the Additional Properties section, then click Add Property.
    • Fill in the details:
      • Name: jcrLastModified (or any name you prefer—GraphQL uses camelCase)
      • Type: Calendar (since jcr:lastModified is a date-time value)
      • Path: ./jcr:content/jcr:lastModified (this points directly to the JCR property)
    • Save the model.
  3. Update your GraphQL query
    Now you can query the field directly under the item object:

    { benefitProgramByPath(_path: "/content/dam/rahjang-cf/rahjang-benifit") { 
        item { 
            _metadata { 
                stringMetadata { name, value, __typename }
                # Keep your existing metadata fields
            }
            jcrLastModified # New field mapped to jcr:lastModified
        } 
      } 
    }
    

Solution 2: Configure the GraphQL Provider to Include Additional Metadata

If you want jcr:lastModified to appear within the _metadata structure (like the other metadata fields), you can adjust the OSGi configuration for the Content Fragment GraphQL provider:

  1. Access the OSGi Configuration Console

    • Go to http://<your-aem-instance>:<port>/system/console/configMgr
    • Search for org.apache.sling.graphql.content.fragments.impl.ContentFragmentGraphQLProvider
  2. Add jcr:lastModified to Additional Properties

    • Find the Additional Properties field (a multi-value text input)
    • Add an entry: jcr:lastModified=calendarMetadata
    • This tells the provider to map the jcr:lastModified property to the calendarMetadata array in your _metadata response.
  3. Test your existing query
    After saving the configuration, your original query will now include jcr:lastModified in the calendarMetadata array:

    {
      "data": {
        "benefitProgramByPath": {
          "item": {
            "_metadata": {
              "stringMetadata": [...],
              "calendarMetadata": [
                {
                  "name": "jcr:lastModified",
                  "value": "2024-05-20T14:30:00.000Z",
                  "__typename": "CalendarMetadata"
                }
              ]
            }
          }
        }
      }
    }
    

Notes

  • For jcr:created, you can use the exact same steps—just replace jcr:lastModified with jcr:created in the path/configuration.
  • If you're using AEM as a Cloud Service, you'll need to deploy the OSGi configuration via your codebase (as a .config file in ui.config/src/main/content/jcr_root/apps/<your-project>/config) instead of using the console directly.

内容的提问来源于stack exchange,提问作者rahul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 20:59:06