Delivering structured Content Fragments via AEM GraphQL APIs for headless applications.
Content Fragments & GraphQL
0) Tóm tắt
- Content Fragment (CF) = structured content (data) trong DAM, không gắn layout.
- GraphQL = API tự sinh từ Content Fragment Models.
- Prod: persisted queries (GET) + cache (Dispatcher/CDN).
1) Content Fragments vs Pages
2) Content Fragment Models (schema)
2.1 Tạo model
Tools → General → Content Fragment Models
- chọn config folder (
/conf/<site>) - Create → name (vd
Article) - Open → add fields
2.2 Field types hay dùng
Ghi chú: “JSON Object field” phụ thuộc version/setup; on-prem 6.5 thường không đặt làm mặc định như Cloud. Nếu cần kiểu JSON, ưu tiên modelling bằng fields hoặc store text + parse.
2.3 Model mẫu: Article
2.4 Model mẫu: Author
3) Tạo Content Fragments
Assets → Files:
- folder (vd
/content/dam/<site>/articles) - Create → Content Fragment
- chọn model (vd
Article) - đặt name + fill fields
3.1 Variations
4) GraphQL API
4.1 Endpoint (pattern)
Endpoint thường gắn theo configuration:
Notes:
- path cụ thể có thể khác theo setup/SP → verify trong UI GraphQL tooling.
- dùng GraphiQL để xem schema + thử query.
4.2 Field name mapping
- label field trong model → GraphQL field camelCase
- case-sensitive
- debug bằng schema explorer trong GraphiQL
5) Query patterns (copy/paste)
5.1 List articles
5.2 Get by path
5.3 Filtering
5.4 Sorting + pagination
5.5 Rich text formats (tuỳ version/setup)
5.6 Fragment references (nested)
6) Persisted queries (prod default)
6.1 Execute (ví dụ)
Naming:
- versioned name:
article-list-v1 - giữ response shape tối thiểu
7) Production hardening checklist (headless)
8) Headless delivery flow (frontend)
9) Render CF “truyền thống” trên Page
Content Fragment Core Component:
- add component lên page
- select fragment
- chọn fields render
- chọn variation (optional)
Use case:
- hybrid: page-based layout + structured CF data