Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

How can I provide a GraphQL endpoint via my ui.content package?

Avatar

Level 4

I created a file .content.xml at src/main/content/jcr_root/content/cq:graphql with the following code. 

 

 

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root
        xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
        xmlns:rep="internal"
        xmlns:jcr="http://www.jcp.org/jcr/1.0"
        xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
        xmlns:cq="http://www.day.com/jcr/cq/1.0"
        jcr:primaryType="nt:folder"
        jcr:mixinTypes="[rep:AccessControllable]">
    <my-endpoint
            jcr:primaryType="sling:Folder">
        <endpoint
                jcr:primaryType="nt:unstructured"
                jcr:title="My Endpoint"
                sling:resourceType="graphql/sites/components/endpoint"/>
    </my-endpoint>
</jcr:root>

 

 

And my filter.xml defines

 

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">  
    <filter root="/content/cq:graphql" mode="update"/>
</workspaceFilter>

 

 

But it does not install the desired nodes at installation.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @jeremylanssiers

You can follow these steps to install /content/cq:graphql:

1. The cq:graphql filename is okay, although you can use _cq_graphql as well. Need to add attribute "xmlns:cq="http://www.day.com/jcr/cq/1.0" to the jcr:root element. Maybe a typo, Correct it such as changing </retailers> to </my-endpoint>. 

<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
  xmlns:cq="http://www.day.com/jcr/cq/1.0" <!-- Add -->
  xmlns:jcr="http://www.jcp.org/jcr/1.0"
  xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
  jcr:mixinTypes="[rep:AccessControllable]"
  jcr:primaryType="nt:folder">
  <my-endpoint jcr:primaryType="sling:Folder">
    <endpoint jcr:primaryType="nt:unstructured"
      jcr:title="My GraphQL Endpoint"
      sling:resourceType="graphql/sites/components/endpoint"/>
  </my-endpoint>
</jcr:root>

2. Check if the cq:graphql filter is added to the ui.content filter. If not, add it like this: 

<filter root="/content/cq:graphql/my-endpoint" />

3. In the ui.content pom.xml file, include /content/cq:graphql as a valid root:

<validRoots>/conf,/content,...,/content/cq:graphql</validRoots>

 

 

 

 

 

 

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @jeremylanssiers

You can follow these steps to install /content/cq:graphql:

1. The cq:graphql filename is okay, although you can use _cq_graphql as well. Need to add attribute "xmlns:cq="http://www.day.com/jcr/cq/1.0" to the jcr:root element. Maybe a typo, Correct it such as changing </retailers> to </my-endpoint>. 

<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
  xmlns:cq="http://www.day.com/jcr/cq/1.0" <!-- Add -->
  xmlns:jcr="http://www.jcp.org/jcr/1.0"
  xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
  jcr:mixinTypes="[rep:AccessControllable]"
  jcr:primaryType="nt:folder">
  <my-endpoint jcr:primaryType="sling:Folder">
    <endpoint jcr:primaryType="nt:unstructured"
      jcr:title="My GraphQL Endpoint"
      sling:resourceType="graphql/sites/components/endpoint"/>
  </my-endpoint>
</jcr:root>

2. Check if the cq:graphql filter is added to the ui.content filter. If not, add it like this: 

<filter root="/content/cq:graphql/my-endpoint" />

3. In the ui.content pom.xml file, include /content/cq:graphql as a valid root:

<validRoots>/conf,/content,...,/content/cq:graphql</validRoots>

 

 

 

 

 

 

Avatar

Level 4

"retailers" was indeed a typo, when posting the code here. I am not using validRoots validation. And I am using the filter.xml path as well, but without the "/my-endpoint" you suggested. But still, no luck. Updating my original post with latest changes.

Avatar

Level 4

For whom is interested in setting up GraphQL endpoints via code, I wrote a blogpost where I create a slightly different setup, compatible with the WKND project. Read it at https://medium.com/@jlanssie/setup-headless-content-delivery-and-content-creation-in-aem-cb03e08cc4d...