0

// I tried sending mutation as json

val testAPIScenario = scenario("Sample test")
            .exec(http("graph ql sample test")
                .post("https://demo.com/")
                .body(RawFileBody("./src/gatling/resources/graphql/sample.json")).asJson
                .header("content-type",value = "application/json")
                .check(status.is(200))
            )

val testAPIScenario = scenario("Sample test")
            .exec(http("graph ql sample test")
                .post("https://demo.com/")
                .body(StringBody("\"query\":\""+getMutation()+"\",\"variables\":"+getVariables()+"}")).asJson
                .header("content-type",value = "application/json")
                .check(status.is(200))
            )

Also tried sending it using an ElFileBody, keeping mutation in a text file.

Just need to know if there is any way I can send graphQl mutation in gatling body

I checked in logs, Request is properly going on graphql but it is giving me 400, I think there is some format issue please guide me

  • not familiar with gatling but 2 things, 1 double check your endpoint, most graphql servers use '/graphql' 2, use curl or postman to get the graphql introspection schema https://hasura.io/learn/graphql/intro-graphql/introspection/ to double check the deployed schema matches your request – Nigel Savage Aug 24 '21 at 11:25
  • I added a dummy endpoint here, in actual endpoints are different. – sourabh.gangoli Aug 24 '21 at 11:57
  • then I would suggest next step is to get the graphql schema via introspection, that way you know your endpoint is correct and you can see the shape of the mutation that the backend expects, see https://stackoverflow.com/questions/37397886/get-graphql-whole-schema-query – Nigel Savage Aug 24 '21 at 12:00

1 Answers1

1

Several things wrong in your code.

  1. body path

RawFileBody("./src/gatling/resources/graphql/sample.json") is very brittle as it depends on where you launch the process and would break if you don't have an exploded project on the filesystem (for example with Gatling Enterprise).

Prefer RawFileBody("graphql/sample.json")

  1. value parameter instead of function parameter

From the documentation, StringBody takes an Expression, meaning that you can pass a value, or a function.

In your code, you're passing the former, so getMutation() and getVariables() get only called once when passing the value.

Instead, you want to pass a function so they get called every time a virtual user tries to build and send this request:

StringBody(session => "\"query\":\""+getMutation()+"\",\"variables\":"+getVariables()+"}")
Stéphane LANDELLE
  • 6,076
  • 2
  • 10
  • 12