How to query unique request by graphql

export scenario1 fundefault () {

mutation {
client(
id: “${id}”
)
}
};

I want to run a scenario with 10vus, 10iterations.
by first send id=1
and second send id=2

10th send id=10

please recommend me thank you!

Hi @Pamorn,

Right now it sounds to me like you might find execution API useful: to set id in mutation equal to VU’s index, execution.vu.idInTest. In case it is something else, could you please add what k6 script you tried and what exactly didn’t work? :slightly_smiling_face:

1 Like

thank you for your reply.
you’ve got a point. but I can’t apply execution.vu.idInTest to my code could you pls take a look for me

type or paste code here
import { sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { vu } from 'k6/execution';


const users = new SharedArray('Operators', function () {
  return JSON.parse(open('user2.json'));
});

export const options = {
    scenarios: {
      login: {
        executor: 'per-vu-iterations',
        vus: users.length,
        iterations: 2,
      },
    },
};



export default function  () {
  console.log(`InsertOperation: ${users[vu.idInTest - 1].name}`);
  sleep(1);
    const InsertOperation = `
    mutation {
        InsertOperation(
          OperationName: "a"${users[vu.idInTest - 1].name}"!"
        }
      }`
}

result here

 scenarios: (100.00%) 1 scenario, 10 max VUs, 10m30s max duration (incl. graceful stop):
           * login: 2 iterations for each of 10 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] InsertOperation: undefined                    source=console
INFO[0000] InsertOperation: undefined                    source=console
INFO[0000] InsertOperation: undefined                    source=console
INFO[0000] InsertOperation: undefined                    source=console
INFO[0000] InsertOperation: undefined                    source=console
INFO[0000] InsertOperation: undefined                    source=console
INFO[0000] InsertOperation: undefined                    source=console
INFO[0000] InsertOperation: undefined                    source=console
INFO[0000] InsertOperation: undefined                    source=console
INFO[0000] InsertOperation: undefined                    source=console
INFO[0001] InsertOperation: undefined                    source=console
INFO[0001] InsertOperation: undefined                    source=console
INFO[0001] InsertOperation: undefined                    source=console
INFO[0001] InsertOperation: undefined                    source=console
INFO[0001] InsertOperation: undefined                    source=console
INFO[0001] InsertOperation: undefined                    source=console
INFO[0001] InsertOperation: undefined                    source=console
INFO[0001] InsertOperation: undefined                    source=console
INFO[0001] InsertOperation: undefined                    source=console
INFO[0001] InsertOperation: undefined                    source=console                                                                                                                                                               

running (00m02.0s), 00/10 VUs, 20 complete and 0 interrupted iterations
login ✓ [======================================] 10 VUs  00m02.0s/10m0s  20/20 iters, 2 per VU

     data_received........: 0 B 0 B/s
     data_sent............: 0 B 0 B/s
     iteration_duration...: avg=1.01s min=1s med=1.01s max=1.02s p(90)=1.02s p(95)=1.02s
     iterations...........: 20  9.826967/s
     vus..................: 10  min=10     max=10
     vus_max..............: 10  min=10     max=10

my user2.json file

[
    { "OperationName": "a01!" }, 
    { "OperationName": "a02!" },
    { "OperationName": "a03!" },
    { "OperationName": "a04!" },
    { "OperationName": "a05!" },
    { "OperationName": "a06!" },
    { "OperationName": "a07!" },
    { "OperationName": "a08!" },
    { "OperationName": "a09!" },
    { "OperationName": "a10!" }
]

I try to cut “${users[vu.idInTest - 1].name}” from “OperationName”${users[vu.idInTest - 1].name}“!” it’s work but that what I try to do.please point my error. :sweat_smile:

@Pamorn, with this JSON file, users would contain Objects with the key OperationName, not name. So using the following:

console.log(`InsertOperation: ${users[vu.idInTest - 1].OperationName}`);

should print a defined and expected result, e.g.:

INFO[0000] InsertOperation: a09!                         source=console
INFO[0000] InsertOperation: a04!                         source=console
INFO[0000] InsertOperation: a02!                         source=console
INFO[0000] InsertOperation: a03!                         source=console
INFO[0000] InsertOperation: a06!                         source=console
INFO[0000] InsertOperation: a01!                         source=console
INFO[0000] InsertOperation: a05!                         source=console
INFO[0000] InsertOperation: a08!                         source=console
INFO[0000] InsertOperation: a07!                         source=console
INFO[0000] InsertOperation: a10!                         source=console

I also think that InsertOperation can be a bit simplified, down to:

const InsertOperation = `
    mutation {
        InsertOperation(
          OperationName: ${users[vu.idInTest - 1].OperationName}
        }
      }`

Would these changes be sufficient for your use case?

1 Like

yes! it works thank you!

1 Like