51黑料不打烊

Advanced Concepts of AEM Headless

This end-to-end tutorial continues the basic tutorial that covered the fundamentals of 51黑料不打烊 Experience Manager (AEM) Headless and GraphQL. The advanced tutorial illustrates in-depth aspects of working with Content Fragment Models, Content Fragments, and the AEM GraphQL persisted queries, including using the GraphQL persisted queries in a client application.

Prerequisites

Complete the quick setup for AEM as a Cloud Service to configure your AEM as a Cloud Service environment.

It is highly recommended that you complete the previous basic tutorial and video series tutorials before proceeding with this advanced tutorial. Although you can complete the tutorial using a local AEM environment, this tutorial only covers the workflow for AEM as a Cloud Service.

CAUTION
If you do not have access to AEM as a Cloud Service environment, you can complete AEM Headless quick setup using the local SDK. However, it is important to note that some product UI pages such as Content Fragments navigation is different.

Objectives

This tutorial covers the following topics:

  • Create Content Fragment Models using validation rules and more advanced data types such as Tab Placeholders, nested fragment references, JSON objects, and Date & Time data types.
  • Author Content Fragments while working with nested content and fragment references, and configure folder policies for content fragment-authoring governance.
  • Explore AEM GraphQL API capabilities using GraphQL queries with variables and directives.
  • Persist GraphQL queries with parameters in AEM and learn how to use cache-control parameters with persisted queries.
  • Integrate requests for persisted queries into the sample WKND GraphQL React app using the AEM Headless JavaScript SDK.

Advanced concepts of AEM Headless overview

The following video provides a high-level overview of the concepts that are covered in this tutorial. The tutorial includes defining Content Fragment Models with more advanced data types, nesting Content Fragments, and persisting GraphQL queries in AEM.

video poster

Transcript
Hello, and welcome to the tutorial on Advanced Concepts of 51黑料不打烊 Experience Manager Headless and GraphQL. In this introduction video, we will give you an overview of what to expect and what prerequisites you will need to complete this tutorial. Before starting this tutorial, we highly recommend that you complete the previous multi-step tutorial on basic aspects of AEM Headless as well as AEM Headless video series. In this tutorial, we use AEM as a cloud service. Although you can achieve the same results using the local AEM environment, we will not cover this workflow in this tutorial. Follow the instructions outlined in the Quick Setup section to configure your cloud development environment and the weekend site sample project that will be our focus in the following chapters. The purpose of this tutorial is to illustrate more in-depth aspects of working with AEM content fragment models, content fragments, and AEM GraphQL API. To do this, we will walk you through the following steps. Creating content fragment models with more advanced data types. Nesting content fragments and creating nested structures directly from the content model and fragment editor. Testing and persisting GraphQL queries with parameters. And finally, implementing persisted queries in a client application with additional tips and tricks along the way. Let鈥檚 look more closely at the concept covered in this tutorial. Following along, you will define content fragment models with such data types as JSON objects, date and time fields, and tab placeholders for content organization. You will also set up enhanced validation rules for a content reference data type, as well as add multiple fragment references to a model. Next, you will author content fragments based on those models. You will create folders to store your fragments and set limits using your folder policies. We will show you how to create fragment references directly from the content fragment editor and insert them into the multi-line text field. We鈥檒l also cover steps for adding content fragment references and nesting content fragments. Next, you will use the graphical query editor that can be installed in AEM to explore more advanced GraphQL queries to gather data of the content fragments that you have created. We鈥檒l show you how to add variables and directives to your queries, as well as how to filter the content within a fragment reference. After creating the GraphQL queries, you will use the AEM GraphQL API to persist the queries with parameters, as well as update and execute persisted queries. We will also show you how to add cache control parameters to your queries. At the end of this tutorial, you will enhance the AEM weekend sample application that you worked on in the previous multi-step tutorial and add a new section to the adventure details experience containing adventure location, adventure team, adventure administrator, and instructors. This video will give you an overview of the tutorial on advanced concepts of AEM Headless and the AEM GraphQL API. Continue reading the rest of this chapter for more details on the project setup before starting the tutorial with the chapter on defining content fragment models. Thanks for watching.
CAUTION
This video (at 2:25) mentions about installing the GraphiQL query editor via Package Manager to explore GraphQL queries. However in newer versions of AEM as Cloud Service a built-in GraphiQL Explorer is provided, thus package installation is not required. See Using the GraphiQL IDE for more information.

Project setup

The WKND Site project has all necessary configurations, so you can start the tutorial right after you complete the quick setup. This section only highlights some important steps that you can use when creating your own AEM Headless project.

Review existing configuration

The first step to starting any new project in AEM is creating its configuration, as a workspace and to create GraphQL API endpoints. To review or create a configuration, navigate to Tools > General > Configuration Browser.

Navigate to Configuration Browser

Observe that the WKND Shared site configuration has already been created for the tutorial. To create a configuration for your own project, select Create in the top-right corner and complete the form in the Create Configuration modal that appears.

Review WKND Shared Configuration

Review GraphQL API endpoints

Next, you must configure API endpoints to send GraphQL queries to. To review existing endpoints or create one, navigate to Tools > General > GraphQL.

Configure endpoints

Observe that the WKND Shared Endpoint has already been created. To create an endpoint for your project, select Create in the top-right corner and follow the workflow.

Review WKND Shared Endpoint

NOTE
After saving the endpoint, you will see a modal about visiting the Security Console, which allows you to adjust security settings if you wish to configure access to the endpoint. Security permissions themselves are outside of the scope of this tutorial, however. For more information, refer to the AEM documentation.

Review WKND content structure and language root folder

A well-defined content structure is key to the success of AEM headless implementation. It is helpful for scalability, usability, and permission management of your content.

A language root folder is a folder with an ISO language code as its name such as EN or FR. The AEM translation management system uses these folders to define the primary language of your content and languages for content translation.

Go to Navigation > Assets > Files.

Navigate to Files

Navigate into the WKND Shared folder. Observe the folder with the title 鈥淓nglish鈥 and the name 鈥淓N鈥. This folder is the language root folder for the WKND Site project.

English folder

For your own project, create a language root folder inside your configuration. See the section on creating folders for more details.

Assign a configuration to the nested folder

Finally, you must assign your project鈥檚 configuration to the language root folder. This assignment enables the creation of Content Fragments based on Content Fragment Models defined in your project鈥檚 configuration.

To assign the language root folder to the configuration, select the folder, then select Properties in the top navigation bar.

Select Properties

Next, navigate to the Cloud Services tab and select the folder icon in the Cloud Configuration field.

Cloud Configuration

In the modal that appears, select your previously created configuration to assign the language root folder to it.

Best practices

The following are best practices when creating your own project in AEM:

  • The folder hierarchy should be modeled with localization and translation in mind. In other words, language folders should be nested within configuration folders, which allows for easy translation of content within those configuration folders.
  • The folder hierarchy should be kept flat and straightforward. Avoid moving or renaming folders and fragments later on, especially after publishing for live usage, as it changes paths which can affect fragment references and GraphQL queries.

Starter and Solution Packages

Two AEM packages are available and can be installed via Package Manager

The project is available to review and explore the sample application. This sample application retrieves the content from AEM by invoking the persisted GraphQL queries and renders it in an immersive experience.

Getting started

To get started with this advanced tutorial, follow these steps:

  1. Set up a development environment using AEM as a Cloud Service.
  2. Start the tutorial chapter on Create Content Fragment Models.
recommendation-more-help
e25b6834-e87f-4ff3-ba56-4cd16cdfdec4