GraphQL Tutorial Help?

Can anyone currently follow the k6 + GraphQL docs?

I am new to k6 and just downloaded it. I am trying to test a locally running GQL API and in that documentation linked above there is no mention of command to run, where to put your file, etc. Based on some searching it looks like I should run k6 run <path/to/file> (I didn’t realize I couldn’t run it with node for example). When I follow the steps in the documentation and use k6 run myfile.js I get Making http requests in the init context is not supported

Something obvious I am missing? Excuse my novice, just seems a little tricky for very beginners to follow

Hi @k6dude Welcome to k6 community, Can you share sample code and which environment load generator (Linux/Window/Mac)?

1 Like

Hi @Elibarick thanks for the response. I am on Windows (I know, boo).

Sample code is modified to run vs a local API that doesn’t require auth headers and has a very simple schema that returns a floating point number between 0 and 10 that is randomly generated.

This was my original code in query.js:

const query = `
 query RandomNumZeroThroughTen {
    randNumber
 }`;


const res = http.post('http://localhost:4000/graphql', JSON.stringify({ query: query }));

This returned a ReferenceError: http is not defined error. Poking around the docs a little bit I updated to:

import http from 'k6/http';


const query = `
 query RandomNumZeroThroughTen {
    randNumber
 }`;


const res = http.post('http://localhost:4000/graphql', JSON.stringify({ query: query }));

This returns a GoError: Making http requests in the init context is not supported error. Both were run using k6 run.

Maybe my modifications of the original documentation is the problem, I do think it would be helpful in that doc to mention how to run the examples though. Thank you for your help

1 Like

Thanks @Elibarick & @k6dude

We’ll review the blog post to see if we can improve the instructions and get back to you here.

Cheers!

1 Like