Pix81
Pix81

Reputation: 677

Can't send a Jmeter request with graphql, 400 response using valid URL

From what I've read on https://graphql.org/learn/serving-over-http/ and Performance test for graphQL API, I can send a graphQL request over jmeter.

In the stack overflow example, a graphQL server was built with Apollo and then queried via Jmeter. I am just trying to do load testing and not build schemas or data sets, so I don't have Apollo on my local machine, and I'm also not sure that I would be testing the QA environment if I did try to do this all locally.

I can access our graphQL at https://proprietary-website/graphql/gql and if I run the following query, it returns the expected results:

query currentUserProfile {
  currentUserProfile {
    id
  }
}

Now, I try to apply that to jmeter

  1. I create a HTTP Request in my thread group with protocol: https, server name: proprietary-website, method: GET, path: /graphql/gql
  2. I create an HTTP Header Manager and include the required Bearer Token and Content-Type headers
  3. I create a listener to View Results Tree

Then I run a jmeter load test with 500 threads

I see the valid URL passed in the request body:

GET https://proprietary-website/graphql/gql

GET data:
{"query":{"currentUserProfile {id}"}}

[no cookies]

but I get back:

HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Content-Length: 1555
Date: Thu, 12 Dec 2019 16:40:26 GMT

I am new to graphql, am I not allowed to send Jmeter requests to the URL my dev gave me and do I have to use the apollo server? If so, can someone point me to some examples?

I am on Windows 10

I also tried:

  1. k6, but this requires docker and i have no admin rights on my computer
  2. easygraphql-lt but when I ran a test script with @easygraphql-lt, I got dependency errors that I don't quite understand how to fix
  3. I looked at easygraphql-load-tester, but this would require me to have access to the project but all i have is the website. I don't have a graphQL.js or an index.js to reference

UPDATE: I just saw that I can copy the query as a curl request so I pasted that request in command line and it gave me extra headers that I put in my jmeter HTTP Header manager:

$ curl 'https://proprietary-website/graphql/gql' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Origin: https://proprietary-website' -H 'Authorization: Bearer redacted' --data-binary '{"query":" query currentUserProfile { currentUserProfile { id }}"}'

But I still get a 400 back, so I think I need to send the query differently as it is showing appended as a --data-binary (not sure what that means). I tried some other SO suggestions, no luck so far

I also tried against an app out of the O'Reilly graphql book, snowtooth.herokuapp.com. This was simpler, so the curl request was simpler, and the information I pasted into jmeter was less, but I still got the error: GET query missing using Protocol: HTTP, server name: snowtooth.herokuapp.com, method: GET and Body Data: {"query":"query { allLifts { name}}"}, plus all the requisite headers in the Header Manager

Upvotes: 0

Views: 2375

Answers (1)

Dmitri T
Dmitri T

Reputation: 168147

Not sure what your proprietary website implementation is, however this http://snowtooth.herokuapp.com/ can be tested like:

  1. HTTP GET request:

    enter image description here

  2. HTTP POST request:

    enter image description here


Also be aware that since JMeter 5.1 it's possible to create a JMeter test plan from CURL command, this http://snowtooth.herokuapp.com/ gives me the following CURL command:

curl 'http://snowtooth.herokuapp.com/' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Origin: http://snowtooth.herokuapp.com' --data-binary '{"query":"{allLifts{name}}"}' --compressed

And when I import it to JMeter I can execute the requests successfully:

enter image description here

Upvotes: 2

Related Questions