Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

GraphQL Persisted Query with Path Parameter on Dispatcher

Avatar

Level 2

We have following persisted query:

 

http://localhost:4502/graphql/execute.json/test-project/get-articles-by-path%3BstartsWith%3D%2Fconte...

 

The GraphQL query has the parameter "startsWith" which takes a path like this:

 

 

query getArticlesByPath($startsWith: ID!) {
  articleCfmList(filter: {
      _path: {
        _expressions: [
        {
          value: $startsWith
         _operator: STARTS_WITH
        }]
       }
    }) {
    items {
...

 

 

 

It works perfectly fine on author and publisher but when sending the same request to the dispatcher it will not send the request correctly to the publisher because the encoded path is not correctly transmitted.

We have tried it with directive

 

AllowEncodedSlashes NoDecode

but it didn't help. What is the correct dispatcher setting for these kind of parameters?

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi, 

 

Please check this documentation: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-ap... In short, the encoding should happen before hitting the dispatcher, in other words, the URL should reach the dispatcher already encoded, if you use the AEM headless client SDK, this will encode the URL for you. The dispatcher should not change this encode unless you have intentionally indicated the opposite.

 

The AllowEncodedSlashes directive is used to control whether encoded slashes (%2F or %2f) in URLs are allowed or not. By default, Apache does not allow encoded slashes in URLs due to security concerns.

 

Hope this helps.



Esteban Bustamante

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi, 

 

Please check this documentation: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-ap... In short, the encoding should happen before hitting the dispatcher, in other words, the URL should reach the dispatcher already encoded, if you use the AEM headless client SDK, this will encode the URL for you. The dispatcher should not change this encode unless you have intentionally indicated the opposite.

 

The AllowEncodedSlashes directive is used to control whether encoded slashes (%2F or %2f) in URLs are allowed or not. By default, Apache does not allow encoded slashes in URLs due to security concerns.

 

Hope this helps.



Esteban Bustamante

Avatar

Level 2

Hi @EstebanBustamante ,

sorry for the late reply and thank you for the hints. I could solve the problem with it.

 

The problem was that this request

  • /graphql/execute.json/test-project/get-articles-by-path%3BstartsWith%3D%2Fcontent%2Ftest

became this

  • /graphql/execute.json/test-project/get-articles-by-path%3bstartsWith=%252Fcontent%252Ftest

So the dispatcher encoded the already encoded slash (%2F) again (%252F). I had a look into the Cloud SDK dispatcher and found this peace of code:

# SITES-3659 Prevent re-encodes of URLs sent to GraphQL Persisted Queries API endpoint
<LocationMatch "/graphql/execute.json/.*">
    ProxyPassMatch http://${AEM_HOST}:${AEM_PORT} nocanon
</LocationMatch>

I've adjusted it for my dispatcher and now it works.

Avatar

Administrator

@12nalk123 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni