@avantstay/graphql-ts-client 10.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -0
- package/dist/endpoint.d.ts +13 -0
- package/dist/endpoint.js +836 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +985 -0
- package/dist/types-4ecbabdf.d.ts +69 -0
- package/package.json +85 -0
- package/src/__snapshots__/graphqlRequest.test.ts.snap +24 -0
- package/src/__testClient.d.ts +148 -0
- package/src/__testClient.js +118 -0
- package/src/endpoint.ts +117 -0
- package/src/generateTypescriptClient.test.ts +127 -0
- package/src/generateTypescriptClient.ts +547 -0
- package/src/graphqlRequest.test.ts +103 -0
- package/src/graphqlRequest.ts +95 -0
- package/src/index.ts +3 -0
- package/src/jsonToGraphQLQuery.test.ts +66 -0
- package/src/jsonToGraphQLQuery.ts +88 -0
- package/src/logging.ts +33 -0
- package/src/testServer.ts +71 -0
- package/src/types.ts +114 -0
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# GraphQL TS Client
|
|
2
|
+
|
|
3
|
+
Generate fully typed Typescript clients for your GraphQL APIs.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
yarn add graphql-ts-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Generate the client
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { generateTypescriptClient } from 'graphql-ts-client'
|
|
17
|
+
|
|
18
|
+
generateTypescriptClient({
|
|
19
|
+
output: './myAwesomeApi.ts',
|
|
20
|
+
endpoint: 'https://my.awesome-api.com/graphql',
|
|
21
|
+
verbose: process.env.NODE_ENV === 'development', // when true, log requests to the console
|
|
22
|
+
headers: {
|
|
23
|
+
Authorization: 'Bearer 1234567890987654321',
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Using the generated client
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { myAwesomeApi, AssetType, Granularity, OnBoardingStage } from './myAwesomeApi'
|
|
32
|
+
|
|
33
|
+
async function somewhereOverTheRainbow() {
|
|
34
|
+
// Set an specific header if needed
|
|
35
|
+
myAwesomeApi.setHeader('Authorization', 'Bearer 010101010101')
|
|
36
|
+
|
|
37
|
+
// You can also change the API url
|
|
38
|
+
myAwesomeApi.setUrl('https://my-runtime-url.com/graphql')
|
|
39
|
+
|
|
40
|
+
// And configure how retrials should work
|
|
41
|
+
myAwesomeApi.setRetryConfig({
|
|
42
|
+
max: 3,
|
|
43
|
+
before: ({ queryName, query, variables, response }) => {
|
|
44
|
+
// do something before retrying
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
// Adding response listeners is also possible
|
|
49
|
+
myAwesomeApi.addResponseListener(({ queryName, query, variables, response }) => {
|
|
50
|
+
// do something whenever a request is responded
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const response = await myAwesomeApi.queries.globalIndicators({
|
|
54
|
+
// Optionally you can define an alias for this request
|
|
55
|
+
__alias: 'myCustomGlobalIndicators',
|
|
56
|
+
__args: {
|
|
57
|
+
liveStatus: OnBoardingStage.COMPLETED,
|
|
58
|
+
assetType: AssetType.LEASED,
|
|
59
|
+
granularity: Granularity.DAILY,
|
|
60
|
+
},
|
|
61
|
+
customerExperience: {
|
|
62
|
+
avgRating: {
|
|
63
|
+
__args: {
|
|
64
|
+
from: '2020-01-01',
|
|
65
|
+
to: '2020-02-01',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
lorem: true, // selected field
|
|
70
|
+
ipsum: true, // selected field
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
console.log(response.customerExperience.avgRating)
|
|
74
|
+
console.log(response.lorem)
|
|
75
|
+
console.log(response.ipsum)
|
|
76
|
+
console.log(response.dolor) // compilation time error
|
|
77
|
+
}
|
|
78
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { C as ClientConfig, I as IResponseListener, E as Endpoint } from './types-4ecbabdf.js';
|
|
2
|
+
|
|
3
|
+
declare const getApiEndpointCreator: (apiConfig: {
|
|
4
|
+
getClient: () => ClientConfig;
|
|
5
|
+
responseListeners: IResponseListener[];
|
|
6
|
+
typesTree: any;
|
|
7
|
+
maxAge: number;
|
|
8
|
+
verbose: boolean;
|
|
9
|
+
formatGraphQL: any;
|
|
10
|
+
errorsParser?: ((errors: any[]) => any) | undefined;
|
|
11
|
+
}) => <I = any, O = any, E = any>(kind: 'mutation' | 'query', queryName: string) => Endpoint<I, O, E>;
|
|
12
|
+
|
|
13
|
+
export { getApiEndpointCreator };
|