@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 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 };