Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
graphql-query-generator
Advanced tools
Generates queries from the GraphQL endpoint via schema introspection.
GraphQL Query Generator is a library/tool that helps you easily test your GraphQL endpoints using introspection!
So you want to test your GraphQL endpoint. This tool will generate all the queries that your GraphQL endpoint will have. However, for queries that require parameters, this tool will need annotations. So please follow the steps below to get started.
Create example queries that you want tested in the comments!
type Query {
# RollDice has four examples
#
# Examples:
# rollDice(numDice: 4, numSides: 2)
# rollDice( numDice : 40 , numSides:2)
# rollDice ( numDice: 2, numSides: 299 )
# rollDice (
# numDice:4,
# numSides: 2342
# )
rollDice(numDice: Int!, numSides: Int): RandomDie
}
You can use either the CLI or the library to get started!
Execute following commands to get this tool running.
NOTE: Whenever there are parameters required you need to provide them in Graphql schema by following our Examples notation. You can find it in Usage section.
npm i -g graphql-query-generator
gql-test http://<your-server-address>:<your-server-port>
gql-test --help # for more information
If you want more control over the queries that are generated via this tool. Please see the following example:
const QueryGenerator = require('graphql-query-generator');
const request = require('request');
const assert = require('assert');
describe('Query generation', function() {
const serverUrl = 'http://<your-server-address>:<your-server-port>/graphql';
let queries = null;
before(() => {
const queryGenerator = new QueryGenerator(serverUrl);
queries = queryGenerator.run();
});
it('Generates multiple queries', function() {
this.timeout = 50000;
return queries
.then(queries => Promise.all(queries.map(query => requestToGraphQL(serverUrl, query))))
.then(results => assert.equal(results.filter(x => x.statusCode !== 200).length, 0));
});
});
function requestToGraphQL(serverUrl, query) {
return new Promise((resolve, reject) => {
request(serverUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body:JSON.stringify({
"query": query,
"variables": "{}",
"operationName": null
})
}, function (err, result) {
if (err) return reject(err);
resolve(result)
});
});
}
This is an example of a test that will just check that it returns HTTP status code 200! It would be also good to check if, say, the body contains an error section. However, it's all up to you!
When annotating, if you add +NOFOLLOW
in examples will prevent this path from being followed when creating queries
type RandomDie {
numSides: Int!
rollOnce: Int!
statistics(page: Int!): RandomnessStatistics!
# A description for ignored field with parameters
#
# Examples:
# ignoredWithExamples(parameter: 42)
# +NOFOLLOW
ignoredWithExamples(parameter: Int!): IgnoredSubtype
# +NOFOLLOW
ignoredNoParameters: IgnoredSubtype
}
We welcome feedback! Please create an issue for feedback or issues. If you would like to contribute, open a PR and let's start talking!
FAQs
Generates queries from the GraphQL endpoint via schema introspection.
The npm package graphql-query-generator receives a total of 3 weekly downloads. As such, graphql-query-generator popularity was classified as not popular.
We found that graphql-query-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.