Files
bruno/packages/bruno-tests/collection/graphql/variable-interpolation.bru
Sanjai Kumar 836c2b9ace fix: graphQL variables interpolation consistency (UI and CLI) (#7049)
* feat: enhance GraphQL request handling with variable interpolation
2026-02-12 13:48:35 +05:30

55 lines
981 B
Plaintext

meta {
name: variables interpolation
type: graphql
seq: 3
}
post {
url: {{host}}/api/echo/json
body: graphql
auth: none
}
body:graphql {
query { __typename }
}
body:graphql:vars {
{
"my_json": "{{my_json}}"
}
}
assert {
res.status: eq 200
}
script:pre-request {
const testData = {
a: [1,2,3],
b: {
c: "test",
d: "another value"
}
};
// Single escaping
let cv = JSON.stringify(testData).replace(/"/g, '\\"');
bru.setVar("my_json", cv)
}
script:post-response {
bru.deleteVar("my_json")
}
tests {
test("GraphQL variables with nested object and array are interpolated then sent as parsed object", function() {
const body = res.getBody();
expect(body).to.have.property("variables");
expect(body.variables).to.be.an("object");
expect(body.variables).to.have.property("my_json");
expect(body.variables.my_json).to.eql("{\"a\":[1,2,3],\"b\":{\"c\":\"test\",\"d\":\"another value\"}}");
});
}