adobe / aem-headless-client-js

AEM Headless Client for JavaScript
Apache License 2.0
25 stars 12 forks source link

Using variables in runQuery #37

Closed yousiftouma closed 1 year ago

yousiftouma commented 2 years ago

Expected Behaviour

I can send variables property in a GQL query that has parameters

Actual Behaviour

I can not use variables in GQL queries

Reproduce Scenario (including but not limited to)

Try to use runQuery with variables

Steps to Reproduce

Try to use runQuery with variables

Platform and Version

Sample Code that illustrates the problem

Pseudo code in the context of AdobeIO

let body;
if (params.variables) {
 body = { query: params.query, variables: params.variables };
} else {
 body = params.query
}
... runQuery(body);

Logs taken while reproducing problem

I'm not sure if it is possible, if it is how would one use variables in a query?

yousiftouma commented 2 years ago

Corresponding feature is explicitly available in the java client: https://github.com/adobe/aem-headless-client-java/blob/main/README.md#running-queries

Any input? @easingthemes @bdelacretaz (sorry for pings, but don't know if this repo is watched)

easingthemes commented 1 year ago

PR opened,

@param {string} query - the query string

Changed to

@param {string|object} body - the query string or an object with query (and optionally variables) as a property

in

runQuery (body,  ...)

This way it's backward compatible.

Usage

# new
runQuery({
  query: queryString
  variables: {
    var1: val1,
    ...
  }
})
# or old
runQuery(queryString);
yousiftouma commented 1 year ago

Cool, thanks! Hope to see it merged soon @easingthemes