Graphql query with query variable | Community
Skip to main content
Level 5
November 27, 2024
Question

Graphql query with query variable

  • November 27, 2024
  • 1 reply
  • 662 views

Dear Members,

 

I am writing graphql query on content fragment, I need to pass 'variation' query variable to get the content from particular variation of the content fragment. 

The query is working fine on Graphql Query Editor in AEM cloud SDK. However when I copy the url and hit using the browser it is not working, it need variation as query parameter in URL below. 

http://localhost:4502/graphql/execute.json/wknd/Employee%20Pradeep;variation=

http://localhost:4502/graphql/execute.json/wknd/Employee%20Pradeep;variation=pradeep_new_variation

http://localhost:4502/graphql/execute.json/wknd/Employee%20Pradeep?variation=pradeep_new_variation

http://localhost:4502/graphql/execute.json/wknd/Employee%20Pradeep;variation:pradeep_new_variation

 

I have tried all possible combination and passed query parameter using ? or colon in url, nothing worked.

 

Any advise/solution around this is highly appreciated!!

 

Thanks,

Pradeep

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

1 reply

Nikhil-Kumar
Community Advisor
Community Advisor
November 27, 2024
  1. Use Query Parameters Properly
    Ensure that the query parameter is correctly appended to the URL using ? for the first parameter and & for subsequent ones. For your variation parameter, it should follow the proper query string format.

    Example:

  2. Avoid Using Semicolons in URLs
    Using a semicolon (;) instead of a query string format (? or &) might not be recognized by AEM as a valid delimiter for query parameters.

    Example:
    Avoid this:

  3. Check URL Encoding
    Ensure all special characters in your content fragment name (e.g., spaces in Employee Pradeep) are URL-encoded. Spaces should be %20 or +.

    Correctly encoded:

Debugging the Issue

  1. Verify Endpoint and Query Parameters
    Double-check the AEM documentation or your project-specific API configuration to confirm the expected query parameter format for variations.

  2. Test in Browser Developer Tools
    Use the browser's developer tools to inspect the network request made by the GraphQL Query Editor in AEM. Look at the exact request URL and parameters sent.

  3. Inspect Server Logs
    Check the AEM server logs (error.log or request.log) for any errors or clues about why the request isn't being interpreted correctly.

Level 5
November 27, 2024

All these things are taken care, I am using SDK verison 

Adobe Experience Manager 2024.8.17465.20240813T175259Z-240800

 

How should the publisher/dispatcher URL look like for a graphql query which has query variable in it.

 

This is something less explored/discussed topic on community forum it seems. 

 

Thanks,

Pradeep