Expand my Community achievements bar.

AEM6.5 SP13 | Graphql Not working

Avatar

Level 6

Hi All,

 

I am using AEM6.5 SP13. I need to export content fragment headless content using graphql to external systems.

Every time I am running query on 

http://localhost:4502/content/graphiql.html

 

Getting below error.

 

{
"errors": [
{
"message": "Failed to execute 'text' on 'Response': body stream already read",
"stack": "TypeError: Failed to execute 'text' on 'Response': body stream already read\n at http://localhost:4502/content/graphiql.html:81:33\n at async https://unpkg.com/graphiql/graphiql.min.js:29:224769"
}
]
}

 

Could anyone suggest what am I missing here?

In tools --> general I could not see graphql query editor option.

 

Any help is highly appreciated.

 

Thanks,

Pradeep

12 Replies

Avatar

Employee Advisor

Hi @pradeepdubey82 ,

 

Please exclude the endpoints in Adobe Granite CSRF Filter configuration.

 

milind_bachani_0-1671027631713.png

 

Thanks,

Milind

Avatar

Employee Advisor

@pradeepdubey82 

Can you please share the screen shot of the query you are trying and resultant error.

 

Also, have you also installed following essential packages :

  1. Graph QL OAK Index (cfm-graphql-index-def-1.0.0.zip)
  2. GraphiQL Developer tool (graphiql-0.0.6.zip)

 

Also, please follow step by step process below, this should resolve any installation issues:

https://kiransg.com/2021/12/04/aem-content-fragments-with-graphql-getting-started-with-graphql/#:~:t...

Avatar

Level 6

Hello Krati,

 

CF preview

 

pradeepdubey82_0-1671085321575.png

 

Query editor

pradeepdubey82_1-1671085396588.png

 

I have installed graphiql-0.0.6.zip but not cfm-graphql-index-def-1.0.0.zip, is this needed to run the graphql query?

 

Avatar

Employee Advisor

@pradeepdubey82 

cfm-graphql-index-def.1.0.0.zip may not resolve the above issue, but it is an essential package from Query Performance perspective. 

 

Coming back to the issue, this is essentially a CSRF issue, as pointed by others. Please check below link :

https://www.albinsblog.com/2021/10/how-to-deliver-headless-content-through-graphql-api-and-content-f...

 

Also, validate that the Global Endpoint that you have defined is being correctly set in CSRF config.
If you think, all the values you have entered into CSRF config is correct, then please restart the bundle, or restart the local aem set up you are using:

Bundle:

krati_garg_0-1671366485083.png

 

Avatar

Level 6

Graphql is working fine once I added global endpoint in CSRF filter

/content/cq:graphql/global/endpoint

 

Not sure why this is needed as I have added all CF to custom site. 

Avatar

Employee Advisor

Glad that it worked. 

Not sure why this is needed as I have added all CF to custom site. 

@pradeepdubey82 Does the above mean, that you have defined a custom Endpoint instead of OOTB Global Endpoint? If that is so, custom Global Endpoint will work perfectly with External System, it is only the graphiQL interface that is bound to global endpoint especially for AEM On Prem. On AEMaaCS, we have the option to select EndPoints for GraphiQL interface. Look into below highlighted link
https://www.albinsblog.com/2021/10/how-to-deliver-headless-content-through-graphql-api-and-content-f....

 

AEMaaCS:

krati_garg_0-1671448185013.png

 

 

Avatar

Level 6

Yes I defined site specific endpoint instead of global. I think AEM6.5 works for global endpoint, and there is no provision to select endpoint while running the query in graphiql-0.0.6.zip(http://localhost:4502/content/graphiql.html). Also persist query doesn't support OOTB in AEM 6.5

 

So I would need to exclude global endpoint in CSRF filter instead of custom endpoint. 

 

Next challenge is how these endpoint can be accessible by external systems? For now I am using basic authentication (user/password) with read/write permission to the user. 

Is there any way like token authentication for accessing graphql query/endpoint by external system?

 

Appreciate your help Krati.

 

Thanks,

Pradeep

Avatar

Employee Advisor

@pradeepdubey82 Please follow below blog for step by step process. This will answer all your queries:

https://www.albinsblog.com/2021/10/how-to-deliver-headless-content-through-graphql-api-and-content-f...

 

Let me know, if you face any issue, in following these steps. It also explains how to query via external applications using curl command

 

 

Avatar

Level 6

Yes, since few days I am going through this article, in this article Albin has explained through basic authentication only, token based may be supporting in AEMAaCS not sure if it is there in AEM6.5

 

Using basic authentication and postman I am able to run all the requests GET,POST,PUT,DELETE on AEM6.5

 

-Best,

Pradeep

Avatar

Level 1

Hi @pradeepdubey82 and @krati_garg ,

I added entries in CSRF excluded path filter as below but still have same issue.

sat05_0-1676443697916.png

 

Error:

 

{
"errors": [
{
"message": "Failed to execute 'text' on 'Response': body stream already read",
"stack": "TypeError: Failed to execute 'text' on 'Response': body stream already read\n at http://localhost:4502/content/graphiql.html:81:33\n at async https://unpkg.com/graphiql/graphiql.min.js:29:224769"
}
]
}