1 | <div align='center'>
|
2 | <br/>
|
3 | <br/>
|
4 | <img src='https://gqlts.vercel.app/banner.jpg' width='420px'>
|
5 | <br/>
|
6 | <br/>
|
7 | <h3>Type safe Graphql query builder</h3>
|
8 | <h4>Write Graphql queries with type validation and auto-completion with batteries included</h4>
|
9 | <br/>
|
10 | <br/>
|
11 | </div>
|
12 |
|
13 | [![CI](https://github.com/meabed/gqlts/actions/workflows/ci.yml/badge.svg)](https://github.com/meabed/gqlts/actions/workflows/ci.yml)
|
14 | [![RELEASE](https://github.com/meabed/gqlts/actions/workflows/release.yml/badge.svg)](https://github.com/meabed/gqlts/actions/workflows/release.yml)
|
15 | ### @gqlts/cli
|
16 | [![Stable NPM version](https://img.shields.io/badge/NPM-v3.2.20-beta.228-179BD7.svg)](https://www.npmjs.com/package/@gqlts/cli/v/3.2.20-beta.228)
|
17 | [![Develop NPM version](https://img.shields.io/npm/v/@gqlts/cli.svg)](https://www.npmjs.com/package/@gqlts/cli)
|
18 | [![Downloads](https://img.shields.io/npm/dm/@gqlts/cli.svg)](https://www.npmjs.com/package/@gqlts/cli)
|
19 | [![UNPKG](https://img.shields.io/badge/UNPKG-CLI%20Files-179BD7.svg)](https://unpkg.com/browse/@gqlts/cli@latest/)
|
20 | ### @gqlts/runtime
|
21 | [![Stable NPM version](https://img.shields.io/badge/NPM-v3.2.20-beta.228-179BD7.svg)](https://www.npmjs.com/package/@gqlts/runtime/v/3.2.20-beta.228)
|
22 | [![Develop NPM version](https://img.shields.io/npm/v/@gqlts/runtime.svg)](https://www.npmjs.com/package/@gqlts/runtime)
|
23 | [![Downloads](https://img.shields.io/npm/dm/@gqlts/runtime.svg)](https://www.npmjs.com/package/@gqlts/runtime)
|
24 | [![UNPKG](https://img.shields.io/badge/UNPKG-RUNTIME%20Files-179BD7.svg)](https://unpkg.com/browse/@gqlts/runtime@latest/)
|
25 |
|
26 | > This package is forked version from [genql](https://github.com/remorses/genql/)
|
27 | >
|
28 | > It has been updated, fixed few bugs, actively adding features and updated dependencies and codebase to the latest packages
|
29 |
|
30 | Read the [quick start guide](https://gqlts.vercel.app/docs) to generate a client locally
|
31 |
|
32 | ## **Features**
|
33 |
|
34 | - Type completion
|
35 | - Type validation
|
36 | - Easily fetch all fields in a type
|
37 | - Support subscription ( ws, graphql-ws, observable, etc )
|
38 | - Built in file upload support
|
39 | - Graphql Client built in
|
40 | - Works with any client
|
41 | - Works in node and the browser
|
42 | - Built in Axios Client, and exported to extend with interceptors.
|
43 | - Client Operation support for Axios configuration, such as headers, timeout, cancelToken, abortSignal, etc.
|
44 | - Support batching queries
|
45 | - Consistent response format { data, errors, extensions }
|
46 |
|
47 | > Find more server-client examples in the [examples repo](https://github.com/meabed/graphql-examples)
|
48 | > You will find multiple examples with different tools of building schema, query, mutation, websocket subscriptions and more.
|
49 |
|
50 | ## Example usage
|
51 |
|
52 | First generate your client executing
|
53 |
|
54 | ```sh
|
55 | npm i -D @gqlts/cli # cli to generate the client code
|
56 | npm i @gqlts/runtime graphql # runtime dependencies
|
57 | gqlts --schema ./schema.graphql --output ./generated
|
58 | ```
|
59 |
|
60 | Then you can use your client as follows
|
61 |
|
62 | ```js
|
63 | import { createClient, everything } from './generated'
|
64 | const client = createClient()
|
65 |
|
66 | client
|
67 | .query({
|
68 | countries: {
|
69 | name: true,
|
70 | code: true,
|
71 | nestedField: {
|
72 | ...everything, // same as __scalar: true
|
73 | },
|
74 | },
|
75 | })
|
76 | .then(console.log)
|
77 | ```
|
78 |
|
79 | The code above will fetch the graphql query below
|
80 |
|
81 | ```graphql
|
82 | query {
|
83 | countries {
|
84 | name
|
85 | code
|
86 | nestedField {
|
87 | scalarField1
|
88 | scalarField2
|
89 | }
|
90 | }
|
91 | }
|
92 | ```
|
93 |
|
94 | ---
|
95 |
|
96 | ## License
|
97 |
|
98 | This is licensed under an MIT License. [See details](LICENSE)
|