graphql-clientgen
[Work in progress]
Generate typescript client script with batch queries for graphql projects.
One client-side method is generated for each query/mutation, with a default and customizable fragment
.
Basic usage
1 ) npm install --save graphql-clientgen
or yarn add graphql-clientgen
2 ) Generate the client code:
Insert this script in the scripts
section in your package.json
"scripts":
then run: npm run get-client
- Using the generated code
; ; // assuming there is a query called findUser, the generated code will accept// arguments for the corresponding input typemethods.findUser; // Promise<Maybe<User>> methods.posts; // Promise<Post[]> // one default query is generated for each query/mutation,// but we can pass a custom fragment.methods.posts, ; // Promise<(Partial<Post>)[]>
cli:
$ get-client http://localhost:3777/graphql
$ get-client --help
api
// from schema;;; // Or from endpoint;;x fs.writeFile__dirname + '/client.ts', client;
Complete generated code example
antoniopresto.github.io/graphql-clientgen/
TODO
- generate typescript client
- generate typed query methods
- generate typed mutation methods
- generate default fragments
- batch queries
- generate from endpoint
- print schema
- print query
- improve docs
- generate pure javascript version of the client