Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
gql-generator
Advanced tools
Generate queries from graphql schema, used for writing api test.
# Sample schema
type Query {
user(id: Int!): User!
}
type User {
id: Int!
username: String!
email: String!
createdAt: String!
}
# Sample query generated
query user($id: Int!) {
user(id: $id){
id
username
email
createdAt
}
}
# Install
npm install gql-generator -g
# see the usage
gqlg --help
# Generate sample queries from schema file
gqlg --schemaFilePath ./example/sampleTypeDef.graphql --destDirPath ./example/output --depthLimit 5
Now the queries generated from the sampleTypeDef.graphql
can be found in the destDir: ./example/output
.
This tool generate 3 folders holding the queries: mutations, queries and subscriptions. And also index.js
files to export the queries in each folder.
You can require the queries like this:
// require all the queries
const queries = require('./example/output');
// require mutations only
const mutations = require('./example/output/mutations');
// sample content
console.log(queries.mutations.signup);
console.log(mutations.signup);
/*
mutation signup($username: String!, email: String!, password: String!){
signup(username: $username, email: $email, password: $password){
token
user {
id
username
email
createdAt
}
}
}
*/
The tool will automatically exclude any @deprecated
schema fields (see more on schema directives here). To change this behavior to include deprecated fields you can use the includeDeprecatedFields
flag when running the tool, e.g. gqlg --includeDeprecatedFields
.
Alternatively, you can run gql-generator
directly from your scripts:
const gqlg = require('gql-generator')
gqlg({ schemaFilePath: './example/sampleTypeDef.graphql', destDirPath: './example/output', depthLimit: 5 })
Say you have a graphql schema like this:
type Mutation {
signup(
email: String!
username: String!
password: String!
): UserToken!
}
type UserToken {
token: String!
user: User!
}
type User {
id: Int!
username: String!
email: String!
createdAt: String!
}
Before this tool, you write graphql api test like this:
const { GraphQLClient } = require('graphql-request');
require('should');
const host = 'http://localhost:8080/graphql';
test('signup', async () => {
const gql = new GraphQLClient(host);
const query = `mutation signup($username: String!, email: String!, password: String!){
signup(username: $username, email: $email, password: $password){
token
user {
id
username
email
createdAt
}
}
}`;
const data = await gql.request(query, {
username: 'tim',
email: 'timqian92@qq.com',
password: 'samplepass',
});
(typeof data.signup.token).should.equal('string');
);
As gqlg
generated the queries for you, you don't need to write the query yourself, so your test will becomes:
const { GraphQLClient } = require('graphql-request');
require('should');
const mutations = require('./example/output/mutations');
const host = 'http://localhost:8080/graphql';
test('signup', async () => {
const gql = new GraphQLClient(host);
const data = await gql.request(mutations.signup, {
username: 'tim',
email: 'timqian92@qq.com',
password: 'samplepass',
});
(typeof data.signup.token).should.equal('string');
);
gqlg
ignores the types which have been added in the parent queries already by default. This can be disabled using the --includeCrossReferences
argument.region(language: $language1)
.2.0.0 - 2024-01-08
There are no interface changes in this release, but the minimum required Node.js version is now 18.
commander
, graphql
to latestdel
, instead rimraf
is now used.FAQs
Generate queries from graphql schema, used for writing api test.
The npm package gql-generator receives a total of 6,582 weekly downloads. As such, gql-generator popularity was classified as popular.
We found that gql-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
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.