I want to use Gatling with GraphQL but can't find suitable methods to work with GraphQL queries. Can Gatling support reading directly from files into Gatling EL variables?
Below is an example which I want to achieve - the value of JSON field query
is read from the file init-query.graphql
.
http("getInit")
.post("/api/graphql")
.body(StringBody(
"""
|{
| "query": "${init-query.graphql}",
| "variables": null
|}
""".stripMargin))
.asJson
I've also tried different feeders but none of them can just put file's content into a Gatling EL variable (or rather I couldn't do it) so it can be used just as a variable like ${init-query-content}
Okay, figured out how to do that:
.exec(session => {
val bodyExpr = ElFileBody("init-query.graphql")
val bodyStr = bodyExpr(session).toOption.get.filter(_ >= ' ') // remove control characters
session.set("queryContent", bodyStr)
})
.exec(http("getInit")
.post("/api/graphql")
.body(StringBody(
"""
|{
| "query": "${queryContent}",
| "variables": null
|}
""".stripMargin))
.asJson
)