aem-headless-client-js icon indicating copy to clipboard operation
aem-headless-client-js copied to clipboard

runPersistedQuery is not being able to handle multiple variables - missing semicolon after last param

Open colinscz opened this issue 3 months ago • 1 comments

This is a ticket related to #28

Expected Behaviour

runPersistedQuery should be able to handle multiple variables as per API documentation https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-api/content-fragments.html?lang=en#web-optimized-image-delivery-request-url

Actual Behaviour

When running a persisted query with more the one variable in an HTTP GET method, the resulting variablesString in the actual code causes a ServletError

Reproduce Scenario (including but not limited to)

Use the aem-headless-client-js or the aem-headless-node-js

Root cause seems to be here: https://github.com/adobe/aem-headless-client-js/blob/main/src/index.js#L108 With multiple queries there is no ending semicolon set for the last parameter. As per the documentation this is a must as otherwise any request will fail since AEM will not know where the last param ends.

The warning message in the docs says: The trailing ; is mandatory to cleanly terminate the list of parameters.

Steps to Reproduce

Run a persisted query which requires multiple query parameters f.e. slug and locale or a search query with multiple filter/search parameters

Platform and Version

NPM Version 3.3.0 of aem-headless-client-js

Sample Code that illustrates the problem

https://github.com/adobe/aem-guides-wknd-graphql/blob/main/advanced-tutorial/src/api/usePersistedQueries.js#L31

There should be in minimum a test that passes more then one parameter, unfortunately I couldn't find one where two or more parameters are being sent. So as of now I cannot definitely verify that multiple parameters work with this package. But they work with the GraphiQL Editor inside AEM.

I suggest to also extend the example project: https://github.com/adobe/aem-guides-wknd-graphql To have at least one use case where two parameters have to be passed in order to thoroughly test this multi-parameter functionality. That way an error for this could not so easily slip.

Logs taken while reproducing problem

colinscz avatar Mar 06 '24 10:03 colinscz