From 8361f741cb6e1fd43d652fa1d192a33cc8342c64 Mon Sep 17 00:00:00 2001 From: Udhay-Adithya Date: Tue, 24 Jun 2025 23:53:05 +0530 Subject: [PATCH] docs: add ad.request.query method user guide --- doc/user_guide/scripting_user_guide.md | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/doc/user_guide/scripting_user_guide.md b/doc/user_guide/scripting_user_guide.md index 66dd85ce..844a50bf 100644 --- a/doc/user_guide/scripting_user_guide.md +++ b/doc/user_guide/scripting_user_guide.md @@ -175,6 +175,53 @@ Access or modify the request body. let xmlString = "Test"; ad.request.body.set(xmlString, "application/xml"); ``` +### `ad.request.query` + + * Access or modify the GraphQL query string. This applies specifically to GraphQL requests, where the body typically includes a `query`, `variables`, and optionally `operationName`. + +* **`ad.request.query.get(): string`** + + * Returns the current GraphQL query string (query, mutation, or subscription). If not set, returns an empty string. + * Example: + + ```javascript + let gqlQuery = ad.request.query.get(); + ad.console.log("Current GraphQL query:", gqlQuery); + ``` + +* **`ad.request.query.set(newQuery: string)`** + + * Sets the GraphQL query string. + * Automatically sets the `Content-Type` header to `application/json` unless it's already set, ensuring correct handling by GraphQL servers. + * Does **not** set the entire request body, it is up to the user to include the full GraphQL payload inside the query. (e.g., `{ query, variables, operationName }`). + * Example: + + ```javascript + let newQuery = ` + query { + user(id: 1) { + id + username + email + address { + geo { + lat + lng + } + } + } + }`; + ad.request.query.set(newQuery); + ``` + +* **`ad.request.query.clear()`** + + * Clears the current GraphQL query string by setting it to an empty string. + * Example: + + ```javascript + ad.request.query.clear(); + ``` ### `ad.request.method`