An example Web Component that highlights Adobe Experience Manager's GraphQL APIs usage for AEM Headless use cases.
A reusable <person-info>
custom element encapsulates the code that renders the Person Info by calling the persisted GraphQL query.
Highlights
-
In
.../src/assets/aem-headless.html
HTML file<person-info>
custom element is used, like<person-info host="https://publish-p65804-e666805.adobeaemcloud.com" query-param-value="John Doe"> </person-info>
-
The
.../src/person.js
registers the<person-info>
custom element andPersonInfo
class object defines the behavior of the element.// Create a Class for our Custom Element (person-info) class PersonInfo extends HTMLElement { // define behavior via lifecycle callback, invoke GraphQL API } ... // Define the person-info element customElements.define("person-info", PersonInfo);
Reusable <person-info>
web component on a page
-
On the target AEM environment install and replicate the
tutorial-solution-content.zip
from the Solution Files using Package Manager. -
Update the headless service variable values to point to your target AEM instance and add authentication (if needed)
-
Update the CORS -Cross Origin Resource Sharing configs
-
Start the app from the command line:
$ cd aem-guides-wknd-graphql/web-component $ npm install $ npm start
AEM as a Cloud Service | AEM 6.5 | Sample Content | Node | npm |
---|---|---|---|---|
Continual | 6.5.13+ | Solution Files | 10+ | 6+ |
There are few headless service variables are used by this example to connect to an AEM environment. If you wish to change this behavior update the person.js
file accordingly:
In aemHeadlessService
object,
aemHost=https://publish-p65804-e666805.adobeaemcloud.com
- AEM target hostgraphqlAPIEndpoint=graphql/execute.json
- GraphQL endpoint pathprojectName=my-project
- Project name (config)persistedQueryName=person-by-name
- Persisted query namequeryParamName=name
- Query parameter name for above persisted query
In aemCredentials
object,
username=admin
- basic auth user credentials to use if connecting to an AEM Author environment (for development only). If connecting to a Publish environment, this setting is not necessary.password=admin
- basic auth password used for connecting to an AEM Author environment (for development only). If connecting to a Publish environment, this setting is not necessary.
Several CORS configurations must be set on the target AEM environment:
-
OSGi CORS Configuration - A configuration can be deployed as part of an AEM project. Example OSGi Config
-
Dispatcher headers - The AEM dispatcher must also be enabled to pass through the following client headers:
"Origin" "Access-Control-Request-Method" "Access-Control-Request-Headers"
This is a sample CORS config for local Author environment