gql-fragment-generator
Generate fragments from graphql schema
Example
# Sample schematype Query { user(id: Int!): User!} type User { id: Int! username: String! email: String! createdAt: String!}
# Sample query generatedquery user($id: Int!) { user(id: $id){ id username email createdAt }}
Usage
# Install npm install gql-fragment-generator -g # see the usage gqlgfrag --help # Generate sample queries from schema file gqlgfrag --schemaFilePath ./example/sampleTypeDef.graphql --destDirPath ./example/output
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 queriesconst queries = ;// require mutations onlyconst mutations = ; // sample contentconsole;console;/*mutation signup($username: String!, email: String!, password: String!){ signup(username: $username, email: $email, password: $password){ token user { id username email createdAt } }}*/