Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Consuming GraphlQL endpoint AEM internally (backend)

Avatar

Level 1

Hey community!

 

I´m currently playing around with the GraphQL functionality based on content fragment models and persistent queries. I understand the external use cases to consume this data in an AEM frontend or any other system / third party application. 

 

I have a scenario where I want to use the existing content fragment data in the AEM backend and provide it to e.g. a component model via an OSGi service. The most obvious option was to create a service and make REST calls against the GraphQL endpoint of the current instance and use the persistent queries function. That looks quite nice (and works in a development environment), but in the end I have to deal with the following circumstances:

 

1. On which environment is my code running? Which is the domain I need to query?

2. If I want to query the author instances, I need to authenticate my request, because the OSGi service does not know anything about a users request or any other authenticated resource.

 

At the moment we need custom code to fetch data from the content fragment area and care about transforming, filtering and so on. With the flexible GraphQL queries and the ability to just map the results to objects it would be pretty easy and flexible to work with that data.

 

Is that a use case that was considered for headless? I can imagine that this is covered with the logic implemented for the CIF framework, but since we are not yet using this functionality it is not available in our environment.

 

Any help or input is highly appreciated!

 

Thanks and best

Alex

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @alex-muc 

 

I am just wondering why you want to go long route. You can write a common OSGI Service or piece of Java code which can read Content Fragments elements and nested Content Fragment levels and reuse it in any model.

 

Let me know if you want to know more details about the same.

We implement same in our headless implementation.

 

Hope this helps!!

View solution in original post

4 Replies

Avatar

Administrator

@partyush @Shivanandh @B_Sravan @ksh_ingole7 @Pawan-Gupta 

Seeking your guidance on this AEM question. Your expertise is greatly appreciated.



Kautuk Sahni

Avatar

Correct answer by
Community Advisor

Hello @alex-muc 

 

I am just wondering why you want to go long route. You can write a common OSGI Service or piece of Java code which can read Content Fragments elements and nested Content Fragment levels and reuse it in any model.

 

Let me know if you want to know more details about the same.

We implement same in our headless implementation.

 

Hope this helps!!

Avatar

Level 1

Hey @iamnjain ,

 

sry I did not update the thread.

 

From my perspective it is not the long road using graphQL to query the content fragments. The queries are very easy to read, performant and can be exposed to other endpoints very quick.

 

You can directly work with the service from AEM which is doing the trick in the backend (

org.apache.sling.graphql.api.engine.QueryExecutor

This can be easily used to execute a graphQL persistent query in your backend and consume the data.

 

Best

Alex

Avatar

Level 7

Hi @alex-muc 

 

I have same question as how to execute gql queries on backend osgi services? 

Is there any authentication needed (any authentication token etc or service user etc) or just mention URL end point, query, variables to get response?

 

How is this done? given content fragment data, queries present on both author , publish instances.

 

Also, if someone accessing this from a react or angular application , how does this react or angular application gets authenticated?