Created
March 4, 2020 14:32
-
-
Save odykyi/0e0191a771aae7e5ee62b595622426ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http from 'k6/http'; | |
// import { sleep } from 'k6'; | |
// const http = require('k6/http') | |
// const { sleep } = require('k6') | |
import * as fs from 'fs' | |
// const fs = require('fs') | |
const queries = JSON.parse(fs.readFileSync('./easygraphql-load-tester-queries.json')) | |
// const familySchema = fs.readFileSync(path.join(__dirname, 'api/public/schema.graphql'), 'utf8') | |
module.exports = function () { | |
for (const query of queries) { | |
const url = 'https://zwjy4r7gvfg4zieaxvormcrxmu.appsync-api.us-east-1.amazonaws.com/graphql' | |
const payload = JSON.stringify({ | |
query: query.query, | |
variables: query.variables, | |
}) | |
const params = { headers: { 'Content-Type': 'application/json' } } | |
http.post(url, payload, params) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
console.log('start perf') | |
const fs = require('fs') | |
const path = require('path') | |
const LoadTesting = require('easygraphql-load-tester') | |
const familySchema = fs.readFileSync(path.join(__dirname, 'api/public/schema.graphql'), 'utf8') | |
console.log('familySchema perf', familySchema) | |
const args = { | |
listStates: { | |
isLocal: true, | |
test: ['a', 'b'], | |
age: 10, | |
name: 'test', | |
}, | |
searchUser: { | |
name: 'demo', | |
}, | |
} | |
const easyGraphQLLoadTester = new LoadTesting(familySchema, args) | |
const queries = [ | |
` | |
query listStates { | |
listStates { | |
items { | |
id | |
name | |
counties { | |
id | |
name | |
townships { | |
name | |
countyId | |
precincts { | |
name | |
} | |
} | |
} | |
} | |
} | |
} | |
`, | |
] | |
easyGraphQLLoadTester.k6('k6.js', { | |
customQueries: queries, | |
selectedQueries: ['listStates', 'searchUser'], | |
vus: 10, | |
duration: '10s', | |
queryFile: true, | |
out: ['json=my_test_result.json'], | |
}) | |
// const http = require('k6/http') | |
// const { sleep } = require('k6') | |
// | |
// function run () { | |
// let query = `query listStates { | |
// listStates { | |
// items { | |
// id | |
// name | |
// counties { | |
// id | |
// name | |
// townships { | |
// name | |
// countyId | |
// precincts { | |
// name | |
// } | |
// } | |
// } | |
// } | |
// } | |
// }` | |
// | |
// let headers = { | |
// // 'Authorization': `Bearer ${accessToken}`, | |
// 'Content-Type': 'application/json' | |
// } | |
// | |
// let res = http.post('http://localhost:3001/graphql', | |
// JSON.stringify({ query: query }), | |
// { headers: headers } | |
// ) | |
// | |
// console.log('res', res) | |
// sleep(0.3) | |
// } | |
// | |
// run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment