@avantstay/graphql-ts-client 12.2.0 → 12.3.1

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/dist/endpoint.js CHANGED
@@ -472,7 +472,7 @@ function graphqlRequest(_) {
472
472
  }
473
473
  function _graphqlRequest() {
474
474
  _graphqlRequest = _asyncToGenerator(function(param) {
475
- var _param_shouldRetry, shouldRetry, _param_axios, axios, queryName, client, query, _param_requestHeaders, requestHeaders, variables, failureMode, errorsParser, _lastResponse_errors, lastResponse, maxRetrials, trial, _client_retryConfig, infoParams, _ref, tmp, responseData, headers, status, data, errors, warnings, _client_retryConfig1;
475
+ var _param_shouldRetry, shouldRetry, _param_axios, axios, queryName, client, query, _param_requestHeaders, requestHeaders, variables, failureMode, errorsParser, _lastResponse_errors, lastResponse, maxRetrials, trial, _responseData_extensions, _client_retryConfig, infoParams, _ref, tmp, responseData, headers, status, data, errors, _responseData_extensions_warnings, warnings, _client_retryConfig1;
476
476
  return __generator(this, function(_state) {
477
477
  switch(_state.label){
478
478
  case 0:
@@ -508,7 +508,8 @@ function _graphqlRequest() {
508
508
  ];
509
509
  case 2:
510
510
  _ref = _state.sent(), tmp = _ref.data, responseData = tmp === void 0 ? {} : tmp, headers = _ref.headers, status = _ref.status;
511
- data = responseData.data, errors = responseData.errors, warnings = responseData.warnings;
511
+ data = responseData.data, errors = responseData.errors;
512
+ warnings = (_responseData_extensions_warnings = (_responseData_extensions = responseData.extensions) === null || _responseData_extensions === void 0 ? void 0 : _responseData_extensions.warnings) !== null && _responseData_extensions_warnings !== void 0 ? _responseData_extensions_warnings : responseData.warnings;
512
513
  if (status >= 400 && !(errors === null || errors === void 0 ? void 0 : errors.length)) {
513
514
  errors = [
514
515
  {
package/dist/endpoint.mjs CHANGED
@@ -45,7 +45,8 @@ async function graphqlRequest({
45
45
  validateStatus: () => true
46
46
  }
47
47
  );
48
- let { data, errors, warnings } = responseData;
48
+ let { data, errors } = responseData;
49
+ const warnings = responseData.extensions?.warnings ?? responseData.warnings;
49
50
  if (status >= 400 && !errors?.length) {
50
51
  errors = [{ message: `Request "${queryName}" failed with status ${status}` }];
51
52
  }
package/dist/index.js CHANGED
@@ -487,7 +487,7 @@ var prettier = __toESM(require("prettier"));
487
487
  // package.json
488
488
  var package_default = {
489
489
  name: "@avantstay/graphql-ts-client",
490
- version: "12.2.0",
490
+ version: "12.3.1",
491
491
  description: "GraphQL Typescript Client Generator",
492
492
  homepage: "https://github.com/avantstay/graphql-ts-client",
493
493
  bugs: {
@@ -508,6 +508,16 @@ var package_default = {
508
508
  require: "./dist/index.js",
509
509
  types: "./dist/index.d.ts"
510
510
  },
511
+ "./endpoint": {
512
+ import: "./dist/endpoint.mjs",
513
+ require: "./dist/endpoint.js",
514
+ types: "./dist/endpoint.d.ts"
515
+ },
516
+ "./dist": {
517
+ import: "./dist/index.mjs",
518
+ require: "./dist/index.js",
519
+ types: "./dist/index.d.ts"
520
+ },
511
521
  "./dist/endpoint": {
512
522
  import: "./dist/endpoint.mjs",
513
523
  require: "./dist/endpoint.js",
@@ -581,7 +591,7 @@ var package_default = {
581
591
  };
582
592
  // src/generateTypescriptClient.ts
583
593
  var tempDir = fs.realpathSync(import_os.default.tmpdir());
584
- var graphqlTsClientPath = process.env.GQL_CLIENT_DIST_PATH || "@avantstay/graphql-ts-client/dist";
594
+ var graphqlTsClientPath = process.env.GQL_CLIENT_DIST_PATH || "@avantstay/graphql-ts-client";
585
595
  function gqlScalarToTypescript(gqlType) {
586
596
  if (/(int|long|double|decimal|float)/i.test(gqlType)) return "number";
587
597
  if (/boolean/i.test(gqlType)) return "boolean";
package/dist/index.mjs CHANGED
@@ -24,7 +24,7 @@ import * as prettier from "prettier";
24
24
  // package.json
25
25
  var package_default = {
26
26
  name: "@avantstay/graphql-ts-client",
27
- version: "12.2.0",
27
+ version: "12.3.1",
28
28
  description: "GraphQL Typescript Client Generator",
29
29
  homepage: "https://github.com/avantstay/graphql-ts-client",
30
30
  bugs: {
@@ -45,6 +45,16 @@ var package_default = {
45
45
  require: "./dist/index.js",
46
46
  types: "./dist/index.d.ts"
47
47
  },
48
+ "./endpoint": {
49
+ import: "./dist/endpoint.mjs",
50
+ require: "./dist/endpoint.js",
51
+ types: "./dist/endpoint.d.ts"
52
+ },
53
+ "./dist": {
54
+ import: "./dist/index.mjs",
55
+ require: "./dist/index.js",
56
+ types: "./dist/index.d.ts"
57
+ },
48
58
  "./dist/endpoint": {
49
59
  import: "./dist/endpoint.mjs",
50
60
  require: "./dist/endpoint.js",
@@ -119,7 +129,7 @@ var package_default = {
119
129
 
120
130
  // src/generateTypescriptClient.ts
121
131
  var tempDir = fs.realpathSync(os.tmpdir());
122
- var graphqlTsClientPath = process.env.GQL_CLIENT_DIST_PATH || "@avantstay/graphql-ts-client/dist";
132
+ var graphqlTsClientPath = process.env.GQL_CLIENT_DIST_PATH || "@avantstay/graphql-ts-client";
123
133
  function gqlScalarToTypescript(gqlType) {
124
134
  if (/(int|long|double|decimal|float)/i.test(gqlType))
125
135
  return "number";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avantstay/graphql-ts-client",
3
- "version": "12.2.0",
3
+ "version": "12.3.1",
4
4
  "description": "GraphQL Typescript Client Generator",
5
5
  "homepage": "https://github.com/avantstay/graphql-ts-client",
6
6
  "bugs": {
@@ -21,6 +21,16 @@
21
21
  "require": "./dist/index.js",
22
22
  "types": "./dist/index.d.ts"
23
23
  },
24
+ "./endpoint": {
25
+ "import": "./dist/endpoint.mjs",
26
+ "require": "./dist/endpoint.js",
27
+ "types": "./dist/endpoint.d.ts"
28
+ },
29
+ "./dist": {
30
+ "import": "./dist/index.mjs",
31
+ "require": "./dist/index.js",
32
+ "types": "./dist/index.d.ts"
33
+ },
24
34
  "./dist/endpoint": {
25
35
  "import": "./dist/endpoint.mjs",
26
36
  "require": "./dist/endpoint.js",
@@ -91,4 +101,4 @@
91
101
  "limit": "10 KB"
92
102
  }
93
103
  ]
94
- }
104
+ }
@@ -28,7 +28,7 @@ import { TypescriptClientOutput } from './types'
28
28
 
29
29
  const tempDir = fs.realpathSync(os.tmpdir())
30
30
 
31
- const graphqlTsClientPath = process.env.GQL_CLIENT_DIST_PATH || '@avantstay/graphql-ts-client/dist'
31
+ const graphqlTsClientPath = process.env.GQL_CLIENT_DIST_PATH || '@avantstay/graphql-ts-client'
32
32
 
33
33
  function gqlScalarToTypescript(gqlType: string) {
34
34
  if (/(int|long|double|decimal|float)/i.test(gqlType)) return 'number'
@@ -55,7 +55,8 @@ export async function graphqlRequest({
55
55
  }
56
56
  )
57
57
 
58
- let { data, errors, warnings } = responseData
58
+ let { data, errors } = responseData
59
+ const warnings = responseData.extensions?.warnings ?? responseData.warnings
59
60
 
60
61
  if (status >= 400 && !errors?.length) {
61
62
  errors = [{ message: `Request "${queryName}" failed with status ${status}` }]
@@ -0,0 +1,39 @@
1
+ import axios from 'axios'
2
+ import { getApiEndpointCreator } from './endpoint'
3
+
4
+ describe('Endpoint warning compatibility', () => {
5
+ afterEach(() => jest.restoreAllMocks())
6
+
7
+ it.each(['legacy', 'extensions', 'both'])('keeps %s warnings on raw results and response listeners', async shape => {
8
+ const warnings = [{ message: 'Cannot modify booking' }]
9
+ const errors = [{ message: 'Booking alteration failed', extensions: { code: 'SERVICE_DEFINED' } }]
10
+ const listener = jest.fn()
11
+ jest.spyOn(axios, 'post').mockResolvedValue({
12
+ status: 200,
13
+ headers: {},
14
+ data: {
15
+ data: { alterBooking: { changed: null } },
16
+ errors,
17
+ ...(shape !== 'extensions' ? { warnings } : {}),
18
+ ...(shape !== 'legacy' ? { extensions: { warnings } } : {}),
19
+ },
20
+ })
21
+ const endpoint = getApiEndpointCreator({
22
+ getClient: () => ({ url: 'https://example.invalid/graphql', headers: {}, retryConfig: { max: 0, before: () => undefined } }),
23
+ requestListeners: [],
24
+ responseListeners: [listener],
25
+ typesTree: {},
26
+ maxAge: 0,
27
+ verbose: false,
28
+ formatGraphQL: (query: string) => query,
29
+ })('mutation', 'booking')
30
+
31
+ const response = await endpoint.raw({ __alias: 'alterBooking' })
32
+ await new Promise(resolve => setTimeout(resolve, 0))
33
+
34
+ expect(response).toMatchObject({ data: { changed: null }, errors, warnings })
35
+ expect(response.warnings).toHaveLength(1)
36
+ expect(listener).toHaveBeenCalledWith(expect.objectContaining({ response: expect.objectContaining({ warnings, errors }) }))
37
+ expect(axios.post).toHaveBeenCalledTimes(1)
38
+ })
39
+ })
@@ -0,0 +1,78 @@
1
+ import { graphqlRequest } from './graphqlRequest'
2
+ import { GraphQLClientError } from './types'
3
+
4
+ const legacyWarnings = [{ message: 'Legacy warning' }]
5
+ const extensionWarnings = [{ message: 'Extension warning' }]
6
+ const data = { booking: null }
7
+ const errors = [{ message: 'Cannot modify booking', extensions: { code: 'SERVICE_DEFINED', requestId: 'request-1' } }]
8
+
9
+ const requestOptions = {
10
+ shouldRetry: false,
11
+ queryName: 'booking',
12
+ query: 'mutation booking { booking }',
13
+ variables: {},
14
+ client: { url: 'https://example.invalid/graphql', headers: {}, retryConfig: { max: 0, before: () => undefined } },
15
+ }
16
+
17
+ describe('GraphQL warning envelopes', () => {
18
+ it.each([
19
+ { name: 'legacy warnings', body: { warnings: legacyWarnings }, warnings: legacyWarnings },
20
+ { name: 'extension warnings', body: { extensions: { warnings: extensionWarnings } }, warnings: extensionWarnings },
21
+ {
22
+ name: 'extensions take precedence without duplicating warnings',
23
+ body: { warnings: legacyWarnings, extensions: { warnings: extensionWarnings } },
24
+ warnings: extensionWarnings,
25
+ },
26
+ {
27
+ name: 'empty extension warnings take precedence',
28
+ body: { warnings: legacyWarnings, extensions: { warnings: [] } },
29
+ warnings: [],
30
+ },
31
+ {
32
+ name: 'null extension warnings fall back',
33
+ body: { warnings: legacyWarnings, extensions: { warnings: null } },
34
+ warnings: legacyWarnings,
35
+ },
36
+ {
37
+ name: 'unrelated extensions fall back',
38
+ body: { warnings: legacyWarnings, extensions: { tracing: {} } },
39
+ warnings: legacyWarnings,
40
+ },
41
+ { name: 'null extensions fall back', body: { warnings: legacyWarnings, extensions: null }, warnings: legacyWarnings },
42
+ { name: 'absent warnings stay absent', body: {}, warnings: undefined },
43
+ ])('$name', async ({ body, warnings }) => {
44
+ const responseData = { data, errors, ...body }
45
+ const response = await graphqlRequest({
46
+ ...requestOptions,
47
+ failureMode: 'silent',
48
+ axios: { post: jest.fn().mockResolvedValue({ data: responseData, status: 200, headers: {} }) } as any,
49
+ })
50
+
51
+ expect(response.warnings).toEqual(warnings)
52
+ expect(response.data).toBe(data)
53
+ expect(response.errors).toBe(errors)
54
+ expect(response.status).toBe(200)
55
+ })
56
+
57
+ it('retains extension warnings on a thrown GraphQLClientError', async () => {
58
+ const response = graphqlRequest({
59
+ ...requestOptions,
60
+ failureMode: 'loud',
61
+ axios: {
62
+ post: jest.fn().mockResolvedValue({ data: { data, errors, extensions: { warnings: extensionWarnings } }, status: 200 }),
63
+ } as any,
64
+ })
65
+
66
+ await expect(response).rejects.toBeInstanceOf(GraphQLClientError)
67
+ await expect(response).rejects.toMatchObject({ response: { data, errors, warnings: extensionWarnings } })
68
+ })
69
+
70
+ it('does not turn warning-only responses into errors or retries', async () => {
71
+ const post = jest.fn().mockResolvedValue({ data: { data, extensions: { warnings: extensionWarnings } }, status: 200 })
72
+ const response = await graphqlRequest({ ...requestOptions, failureMode: 'loud', axios: { post } as any })
73
+
74
+ expect(response.warnings).toEqual(extensionWarnings)
75
+ expect(response.errors).toBeUndefined()
76
+ expect(post).toHaveBeenCalledTimes(1)
77
+ })
78
+ })
@@ -1,75 +0,0 @@
1
- type Maybe<T> = null | undefined | T;
2
- type Defined<T> = Exclude<T, undefined>;
3
- type ResponseData = {
4
- data: any;
5
- warnings: any;
6
- headers: any;
7
- status?: number;
8
- errors: {
9
- message: string;
10
- }[];
11
- };
12
- type ResponseListenerInfo = {
13
- queryName: string;
14
- query: string;
15
- variables: any;
16
- response: ResponseData;
17
- };
18
- type IResponseListener = (info: ResponseListenerInfo) => void | Promise<void>;
19
- type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
20
- type Primitive = Date | string | number | boolean | null | undefined;
21
- type Projection<Selection, Base, E = never> = Base extends Array<any> ? ArrayElement<Base> extends Primitive | E ? ArrayElement<Base>[] : Projection<Defined<Selection>, ArrayElement<Base>, E>[] : Base extends Primitive | E ? Selection extends undefined ? Base | undefined : Base : {
22
- [k in keyof Selection & keyof Base]: Selection[k] extends boolean ? Base[k] : Base[k] extends Array<infer A> ? Projection<Defined<Selection[k]>, A, E>[] : Projection<Defined<Selection[k]>, Base[k], E>;
23
- };
24
- type Unpacked<T> = T extends (infer U)[] ? U : T extends (...args: any[]) => infer U ? U : T extends Promise<infer U> ? U : T;
25
- type Replacement<M extends [any, any], T> = M extends any ? ([T] extends [M[0]] ? M[1] : never) : never;
26
- type DeepReplace<T, Ignore, M extends [any, any]> = {
27
- [P in keyof T]: T[P] extends M[0] ? T[P] extends Ignore ? T[P] extends object ? DeepReplace<T[P], Ignore, M> : T[P] : Replacement<M, T[P]> : T[P] extends object ? DeepReplace<T[P], Ignore, M> : T[P];
28
- };
29
- type RawEndpoint<I, O, E> = <S extends I>(jsonQuery?: S) => Promise<{
30
- data: Projection<S, O, E>;
31
- errors: any[];
32
- warnings: any[];
33
- headers: any;
34
- status: any;
35
- }>;
36
- type JsonOutput<O, ToBeIgnored> = DeepReplace<O, ToBeIgnored, [string | Date, string]>;
37
- type Endpoint<I, O, E> = (<S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>) & {
38
- memo: <S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>;
39
- memoRaw: RawEndpoint<I, JsonOutput<O, E>, E>;
40
- raw: RawEndpoint<I, JsonOutput<O, E>, E>;
41
- };
42
- type ClientConfig = {
43
- url: string;
44
- headers: {
45
- [key: string]: string;
46
- };
47
- retryConfig: {
48
- max: number;
49
- waitBeforeRetry?: number;
50
- before: IResponseListener;
51
- };
52
- };
53
- type LogInfo = {
54
- query: string;
55
- variables: any;
56
- formatGraphQL: any;
57
- kind: string;
58
- queryName: string;
59
- response?: any;
60
- error?: Error;
61
- duration: number;
62
- };
63
- type TypescriptClientOutput = {
64
- js: string;
65
- mjs: string;
66
- typings: string;
67
- };
68
- declare class GraphQLClientError extends Error {
69
- responseData: ResponseData;
70
- constructor(responseData: ResponseData);
71
- get message(): string;
72
- get response(): ResponseData;
73
- }
74
-
75
- export { ClientConfig as C, Defined as D, Endpoint as E, GraphQLClientError as G, IResponseListener as I, JsonOutput as J, LogInfo as L, Maybe as M, Projection as P, ResponseData as R, TypescriptClientOutput as T, Unpacked as U, ResponseListenerInfo as a, Replacement as b, DeepReplace as c, RawEndpoint as d };
@@ -1,81 +0,0 @@
1
- type Maybe<T> = null | undefined | T;
2
- type Defined<T> = Exclude<T, undefined>;
3
- type ResponseData = {
4
- data: any;
5
- warnings: any;
6
- headers: any;
7
- status?: number;
8
- errors: {
9
- message: string;
10
- }[];
11
- };
12
- type RequestListenerInfo = {
13
- queryName: string;
14
- query: string;
15
- variables: any;
16
- };
17
- type IRequestListener = (info: RequestListenerInfo) => void | Promise<void>;
18
- type ResponseListenerInfo = {
19
- queryName: string;
20
- query: string;
21
- variables: any;
22
- response: ResponseData;
23
- };
24
- type IResponseListener = (info: ResponseListenerInfo) => void | Promise<void>;
25
- type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
26
- type Primitive = Date | string | number | boolean | null | undefined;
27
- type Projection<Selection, Base, E = never> = Base extends Array<any> ? ArrayElement<Base> extends Primitive | E ? ArrayElement<Base>[] : Projection<Defined<Selection>, ArrayElement<Base>, E>[] : Base extends Primitive | E ? Selection extends undefined ? Base | undefined : Base : {
28
- [k in keyof Selection & keyof Base]: Selection[k] extends boolean ? Base[k] : Base[k] extends Array<infer A> ? Projection<Defined<Selection[k]>, A, E>[] : Projection<Defined<Selection[k]>, Base[k], E>;
29
- };
30
- type Unpacked<T> = T extends (infer U)[] ? U : T extends (...args: any[]) => infer U ? U : T extends Promise<infer U> ? U : T;
31
- type Replacement<M extends [any, any], T> = M extends any ? ([T] extends [M[0]] ? M[1] : never) : never;
32
- type DeepReplace<T, Ignore, M extends [any, any]> = {
33
- [P in keyof T]: T[P] extends M[0] ? T[P] extends Ignore ? T[P] extends object ? DeepReplace<T[P], Ignore, M> : T[P] : Replacement<M, T[P]> : T[P] extends object ? DeepReplace<T[P], Ignore, M> : T[P];
34
- };
35
- type RawEndpoint<I, O, E> = <S extends I>(jsonQuery?: S) => Promise<{
36
- data: Projection<S, O, E>;
37
- errors: any[];
38
- warnings: any[];
39
- headers: any;
40
- status: any;
41
- }>;
42
- type JsonOutput<O, ToBeIgnored> = DeepReplace<O, ToBeIgnored, [string | Date, string]>;
43
- type Endpoint<I, O, E> = (<S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>) & {
44
- memo: <S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>;
45
- memoRaw: RawEndpoint<I, JsonOutput<O, E>, E>;
46
- raw: RawEndpoint<I, JsonOutput<O, E>, E>;
47
- };
48
- type ClientConfig = {
49
- url: string;
50
- headers: {
51
- [key: string]: string;
52
- };
53
- retryConfig: {
54
- max: number;
55
- waitBeforeRetry?: number;
56
- before: IResponseListener;
57
- };
58
- };
59
- type LogInfo = {
60
- query: string;
61
- variables: any;
62
- formatGraphQL: any;
63
- kind: string;
64
- queryName: string;
65
- response?: any;
66
- error?: Error;
67
- duration: number;
68
- };
69
- type TypescriptClientOutput = {
70
- js: string;
71
- mjs: string;
72
- typings: string;
73
- };
74
- declare class GraphQLClientError extends Error {
75
- responseData: ResponseData;
76
- constructor(responseData: ResponseData);
77
- get message(): string;
78
- get response(): ResponseData;
79
- }
80
-
81
- export { ClientConfig as C, Defined as D, Endpoint as E, GraphQLClientError as G, IRequestListener as I, JsonOutput as J, LogInfo as L, Maybe as M, Projection as P, ResponseData as R, TypescriptClientOutput as T, Unpacked as U, RequestListenerInfo as a, ResponseListenerInfo as b, IResponseListener as c, Replacement as d, DeepReplace as e, RawEndpoint as f };
@@ -1,85 +0,0 @@
1
- type Maybe<T> = null | undefined | T;
2
- type Defined<T> = Exclude<T, undefined>;
3
- type ResponseData = {
4
- data: any;
5
- warnings: any;
6
- headers: any;
7
- status?: number;
8
- errors: {
9
- message: string;
10
- }[];
11
- };
12
- type RequestListenerInfo = {
13
- url: string;
14
- queryName: string;
15
- query: string;
16
- variables: any;
17
- headers: {
18
- [key: string]: string;
19
- };
20
- };
21
- type IRequestListener = (info: RequestListenerInfo) => void | Promise<void>;
22
- type ResponseListenerInfo = {
23
- queryName: string;
24
- query: string;
25
- variables: any;
26
- response: ResponseData;
27
- };
28
- type IResponseListener = (info: ResponseListenerInfo) => void | Promise<void>;
29
- type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
30
- type Primitive = Date | string | number | boolean | null | undefined;
31
- type Projection<Selection, Base, E = never> = Base extends Array<any> ? ArrayElement<Base> extends Primitive | E ? ArrayElement<Base>[] : Projection<Defined<Selection>, ArrayElement<Base>, E>[] : Base extends Primitive | E ? Selection extends undefined ? Base | undefined : Base : {
32
- [k in keyof Selection & keyof Base]: Selection[k] extends boolean ? Base[k] : Base[k] extends Array<infer A> ? Projection<Defined<Selection[k]>, A, E>[] : Projection<Defined<Selection[k]>, Base[k], E>;
33
- };
34
- type Unpacked<T> = T extends (infer U)[] ? U : T extends (...args: any[]) => infer U ? U : T extends Promise<infer U> ? U : T;
35
- type Replacement<M extends [any, any], T> = M extends any ? ([T] extends [M[0]] ? M[1] : never) : never;
36
- type DeepReplace<T, Ignore, M extends [any, any]> = {
37
- [P in keyof T]: T[P] extends M[0] ? T[P] extends Ignore ? T[P] extends object ? DeepReplace<T[P], Ignore, M> : T[P] : Replacement<M, T[P]> : T[P] extends object ? DeepReplace<T[P], Ignore, M> : T[P];
38
- };
39
- type RawEndpoint<I, O, E> = <S extends I>(jsonQuery?: S) => Promise<{
40
- data: Projection<S, O, E>;
41
- errors: any[];
42
- warnings: any[];
43
- headers: any;
44
- status: any;
45
- }>;
46
- type JsonOutput<O, ToBeIgnored> = DeepReplace<O, ToBeIgnored, [string | Date, string]>;
47
- type Endpoint<I, O, E> = (<S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>) & {
48
- memo: <S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>;
49
- memoRaw: RawEndpoint<I, JsonOutput<O, E>, E>;
50
- raw: RawEndpoint<I, JsonOutput<O, E>, E>;
51
- };
52
- type ClientConfig = {
53
- url: string;
54
- headers: {
55
- [key: string]: string;
56
- };
57
- retryConfig: {
58
- max: number;
59
- waitBeforeRetry?: number;
60
- before: IResponseListener;
61
- };
62
- };
63
- type LogInfo = {
64
- query: string;
65
- variables: any;
66
- formatGraphQL: any;
67
- kind: string;
68
- queryName: string;
69
- response?: any;
70
- error?: Error;
71
- duration: number;
72
- };
73
- type TypescriptClientOutput = {
74
- js: string;
75
- mjs: string;
76
- typings: string;
77
- };
78
- declare class GraphQLClientError extends Error {
79
- responseData: ResponseData;
80
- constructor(responseData: ResponseData);
81
- get message(): string;
82
- get response(): ResponseData;
83
- }
84
-
85
- export { ClientConfig as C, Defined as D, Endpoint as E, GraphQLClientError as G, IRequestListener as I, JsonOutput as J, LogInfo as L, Maybe as M, Projection as P, ResponseData as R, TypescriptClientOutput as T, Unpacked as U, RequestListenerInfo as a, ResponseListenerInfo as b, IResponseListener as c, Replacement as d, DeepReplace as e, RawEndpoint as f };
@@ -1,160 +0,0 @@
1
- // noinspection TypeScriptUnresolvedVariable, ES6UnusedImports, JSUnusedLocalSymbols, TypeScriptCheckImport
2
- import { DeepRequired } from "ts-essentials"
3
- import {
4
- Maybe,
5
- IRequestListener,
6
- IResponseListener,
7
- Endpoint,
8
- } from "@avantstay/graphql-ts-client/dist"
9
-
10
- // Scalars
11
- export type IDate = string | Date
12
- export declare type ISODate = IDate
13
-
14
- // Enums
15
-
16
- export declare enum BookType {
17
- dolor = "DOLOR",
18
- ipsum = "IPSUM",
19
- sit = "SIT",
20
- }
21
-
22
- type AllEnums = BookType
23
-
24
- // Args
25
- export interface BooksWithoutParamsArgs {}
26
- export interface BooksWithOptionalParamsArgs {
27
- params?: BookSearchParamsAllOptional
28
- }
29
- export interface BooksWithRequiredParamsArgs {
30
- params: BookSearchParamsSomeRequired
31
- }
32
- export interface FailingQueryArgs {
33
- id: string
34
- }
35
-
36
- // Input/Output Types
37
-
38
- /**
39
- * @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
40
- */
41
-
42
- export interface Book {
43
- title?: string
44
- author?: string
45
- type?: BookType
46
- dateCreated?: ISODate
47
- }
48
-
49
- /**
50
- * @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
51
- */
52
-
53
- export interface BookSearchParamsAllOptional {
54
- title?: string
55
- author?: string
56
- createdAfter?: ISODate
57
- }
58
-
59
- /**
60
- * @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
61
- */
62
-
63
- export interface BookSearchParamsSomeRequired {
64
- title: string
65
- author?: string
66
- }
67
-
68
- /**
69
- * @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
70
- */
71
-
72
- export interface Query {
73
- booksWithoutParams?: Book[]
74
- booksWithOptionalParams?: Book[]
75
- booksWithRequiredParams?: Book[]
76
- failingQuery?: string
77
- }
78
-
79
- // Selection Types
80
-
81
- export interface BookSelection {
82
- title?: boolean
83
- author?: boolean
84
- type?: boolean
85
- dateCreated?: boolean
86
- }
87
-
88
- export interface BookSearchParamsAllOptionalSelection {
89
- title?: boolean
90
- author?: boolean
91
- createdAfter?: boolean
92
- }
93
-
94
- export interface BookSearchParamsSomeRequiredSelection {
95
- title?: boolean
96
- author?: boolean
97
- }
98
-
99
- export declare const myApiClient: {
100
- addRequestListener: (listener: IRequestListener) => () => void
101
- removeRequestListener: (listener: IRequestListener) => void
102
- addResponseListener: (listener: IResponseListener) => () => void
103
- removeResponseListener: (listener: IResponseListener) => void
104
- setHeader: (key: string, value: string) => void
105
- setHeaders: (newHeaders: { [k: string]: string }) => void
106
- setUrl: (url: string) => void
107
- setRetryConfig: (options: {
108
- max: number
109
- waitBeforeRetry?: number
110
- before?: IResponseListener
111
- }) => void
112
- queries: {
113
- booksWithoutParams: Endpoint<
114
- {
115
- __headers?: { [key: string]: string }
116
- __retry?: boolean
117
- __alias?: string
118
- __url?: string
119
- } & BookSelection,
120
- Book[],
121
- AllEnums
122
- >
123
- booksWithOptionalParams: Endpoint<
124
- {
125
- __headers?: { [key: string]: string }
126
- __retry?: boolean
127
- __alias?: string
128
- __url?: string
129
- __args?: BooksWithOptionalParamsArgs
130
- } & BookSelection,
131
- Book[],
132
- AllEnums
133
- >
134
- booksWithRequiredParams: Endpoint<
135
- {
136
- __headers?: { [key: string]: string }
137
- __retry?: boolean
138
- __alias?: string
139
- __url?: string
140
- __args: BooksWithRequiredParamsArgs
141
- } & BookSelection,
142
- Book[],
143
- AllEnums
144
- >
145
- failingQuery: Endpoint<
146
- {
147
- __headers?: { [key: string]: string }
148
- __retry?: boolean
149
- __alias?: string
150
- __url?: string
151
- __args: FailingQueryArgs
152
- },
153
- string,
154
- AllEnums
155
- >
156
- }
157
- mutations: {}
158
- }
159
-
160
- export default myApiClient
@@ -1,137 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- __markAsModule(target);
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __reExport = (target, module2, desc) => {
14
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
15
- for (let key of __getOwnPropNames(module2))
16
- if (!__hasOwnProp.call(target, key) && key !== "default")
17
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
18
- }
19
- return target;
20
- };
21
- var __toModule = (module2) => {
22
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
23
- };
24
- __export(exports, {
25
- BookType: () => BookType,
26
- default: () => stdin_default,
27
- myApiClient: () => myApiClient
28
- });
29
- var import_endpoint = __toModule(require("@avantstay/graphql-ts-client/dist/endpoint"));
30
- var import_standalone = __toModule(require("prettier/standalone"));
31
- var import_parser_graphql = __toModule(require("prettier/parser-graphql"));
32
- const formatGraphQL = (query) => (0, import_standalone.format)(query, { parser: "graphql", plugins: [import_parser_graphql.default] });
33
- const BookType = {
34
- dolor: "DOLOR",
35
- ipsum: "IPSUM",
36
- sit: "SIT"
37
- };
38
- const typesTree = {
39
- Query: {
40
- get booksWithOptionalParams() {
41
- return {
42
- __args: {
43
- params: "BookSearchParamsAllOptional!"
44
- }
45
- };
46
- },
47
- get booksWithRequiredParams() {
48
- return {
49
- __args: {
50
- params: "BookSearchParamsSomeRequired!"
51
- }
52
- };
53
- },
54
- get failingQuery() {
55
- return {
56
- __args: {
57
- id: "String!"
58
- }
59
- };
60
- },
61
- booksWithoutParams: {}
62
- }
63
- };
64
- let verbose = false;
65
- let headers = {};
66
- let url = "http://localhost:4123/graphql";
67
- let retryConfig = {
68
- max: 0,
69
- before: void 0,
70
- waitBeforeRetry: 0
71
- };
72
- let requestListeners = [];
73
- let responseListeners = [];
74
- let errorsParser = void 0;
75
- let apiEndpoint = (0, import_endpoint.getApiEndpointCreator)({
76
- getClient: () => ({ url, headers, retryConfig }),
77
- requestListeners,
78
- responseListeners,
79
- maxAge: 3e4,
80
- verbose,
81
- typesTree,
82
- formatGraphQL,
83
- errorsParser
84
- });
85
- const myApiClient = {
86
- addRequestListener: (listener) => {
87
- requestListeners.push(listener);
88
- return () => {
89
- const index = requestListeners.indexOf(listener);
90
- if (index > -1)
91
- requestListeners.splice(index, 1);
92
- };
93
- },
94
- removeRequestListener: (listener) => {
95
- const index = requestListeners.indexOf(listener);
96
- if (index > -1)
97
- requestListeners.splice(index, 1);
98
- },
99
- addResponseListener: (listener) => {
100
- responseListeners.push(listener);
101
- return () => {
102
- const index = responseListeners.indexOf(listener);
103
- if (index > -1)
104
- responseListeners.splice(index, 1);
105
- };
106
- },
107
- removeResponseListener: (listener) => {
108
- const index = responseListeners.indexOf(listener);
109
- if (index > -1)
110
- responseListeners.splice(index, 1);
111
- },
112
- setHeader: (key, value) => {
113
- headers[key] = value;
114
- },
115
- setHeaders: (newHeaders) => {
116
- headers = newHeaders;
117
- },
118
- setRetryConfig: (options) => {
119
- if (!Number.isInteger(options.max) || options.max < 0) {
120
- throw new Error("retryOptions.max should be a non-negative integer");
121
- }
122
- retryConfig = {
123
- max: options.max,
124
- waitBeforeRetry: options.waitBeforeRetry,
125
- before: options.before
126
- };
127
- },
128
- setUrl: (_url) => url = _url,
129
- queries: {
130
- booksWithoutParams: apiEndpoint("query", "booksWithoutParams"),
131
- booksWithOptionalParams: apiEndpoint("query", "booksWithOptionalParams"),
132
- booksWithRequiredParams: apiEndpoint("query", "booksWithRequiredParams"),
133
- failingQuery: apiEndpoint("query", "failingQuery")
134
- },
135
- mutations: {}
136
- };
137
- var stdin_default = myApiClient;