gql-generator-raw
v1.0.17
Published
Generate queries from graphql schema, used for writing api test.
Readme
gql-generator
Generate queries from graphql schema, used for writing api test.
Example
# 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
}
}Usage
# 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 5Now the queries generated from the sampleTypeDef.graphql can be found in the destDir: ./example/output.
Notes
- As this tool is used for tests, it expands all of the fields in a query. There might be recursive fields in the query, so
gqlgignores the types which have been added in the parent queries already by default. This can be disabled using the--includeCrossReferencesargument. - Variable names are derived from argument names, so variables generated from multiple occurrences of the same argument name must be deduped. An index is appended to any duplicates e.g.
region(language: $language1).
