How can I provide a GraphQL endpoint via my ui.content package? | Community
Skip to main content
Level 3
September 4, 2023
Solved

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

  • September 4, 2023
  • 1 reply
  • 1197 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Mahedi_Sabuj

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>

 

 

 

 

 

 

1 reply

Mahedi_Sabuj
Community Advisor
Mahedi_SabujCommunity AdvisorAccepted solution
Community Advisor
September 4, 2023

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>

 

 

 

 

 

 

Mahedi Sabuj
Level 3
September 4, 2023

"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.

Level 3
September 12, 2023

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-cb03e08cc4d5