@avantstay/graphql-ts-client 12.3.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 +3 -2
- package/dist/endpoint.mjs +2 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/src/graphqlRequest.ts +2 -1
- package/src/graphqlWarnings.endpoint.test.ts +39 -0
- package/src/graphqlWarnings.test.ts +78 -0
- package/dist/chunk-I4QOADOI.mjs +0 -27
- package/dist/types-23d2d6aa.d.ts +0 -75
- package/dist/types-4ecbabdf.d.ts +0 -69
- package/src/__testClient.d.ts +0 -152
- package/src/__testClient.js +0 -110
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
|
|
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
|
|
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.3.
|
|
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: {
|
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.3.
|
|
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: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avantstay/graphql-ts-client",
|
|
3
|
-
"version": "12.3.
|
|
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": {
|
|
@@ -101,4 +101,4 @@
|
|
|
101
101
|
"limit": "10 KB"
|
|
102
102
|
}
|
|
103
103
|
]
|
|
104
|
-
}
|
|
104
|
+
}
|
package/src/graphqlRequest.ts
CHANGED
|
@@ -55,7 +55,8 @@ export async function graphqlRequest({
|
|
|
55
55
|
}
|
|
56
56
|
)
|
|
57
57
|
|
|
58
|
-
let { data, errors
|
|
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
|
+
})
|
package/dist/chunk-I4QOADOI.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
// src/types.ts
|
|
10
|
-
var GraphQLClientError = class extends Error {
|
|
11
|
-
constructor(responseData) {
|
|
12
|
-
super();
|
|
13
|
-
this.responseData = responseData;
|
|
14
|
-
Object.setPrototypeOf(this, GraphQLClientError.prototype);
|
|
15
|
-
}
|
|
16
|
-
get message() {
|
|
17
|
-
return this.response.errors.map((it) => it.message).join(";\n");
|
|
18
|
-
}
|
|
19
|
-
get response() {
|
|
20
|
-
return this.responseData;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
__require,
|
|
26
|
-
GraphQLClientError
|
|
27
|
-
};
|
package/dist/types-23d2d6aa.d.ts
DELETED
|
@@ -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 };
|
package/dist/types-4ecbabdf.d.ts
DELETED
|
@@ -1,69 +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 Projection<Selection, Base, E = never> = Base extends Array<any> ? ArrayElement<Base> extends Date | string | number | boolean | null | undefined | E ? ArrayElement<Base>[] : Projection<Defined<Selection>, ArrayElement<Base>, E>[] : Base extends Date | string | number | boolean | null | E ? Selection extends undefined ? Base | undefined : Base : {
|
|
21
|
-
[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>;
|
|
22
|
-
};
|
|
23
|
-
type Unpacked<T> = T extends (infer U)[] ? U : T extends (...args: any[]) => infer U ? U : T extends Promise<infer U> ? U : T;
|
|
24
|
-
type Replacement<M extends [any, any], T> = M extends any ? ([T] extends [M[0]] ? M[1] : never) : never;
|
|
25
|
-
type DeepReplace<T, Ignore, M extends [any, any]> = {
|
|
26
|
-
[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];
|
|
27
|
-
};
|
|
28
|
-
type RawEndpoint<I, O, E> = <S extends I>(jsonQuery?: S) => Promise<{
|
|
29
|
-
data: Projection<S, O, E>;
|
|
30
|
-
errors: any[];
|
|
31
|
-
warnings: any[];
|
|
32
|
-
headers: any;
|
|
33
|
-
status: any;
|
|
34
|
-
}>;
|
|
35
|
-
type JsonOutput<O, ToBeIgnored> = DeepReplace<O, ToBeIgnored, [string | Date, string]>;
|
|
36
|
-
type Endpoint<I, O, E> = (<S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>) & {
|
|
37
|
-
memo: <S extends I>(jsonQuery?: S) => Promise<Projection<S, JsonOutput<O, E>, E>>;
|
|
38
|
-
memoRaw: RawEndpoint<I, JsonOutput<O, E>, E>;
|
|
39
|
-
raw: RawEndpoint<I, JsonOutput<O, E>, E>;
|
|
40
|
-
};
|
|
41
|
-
type ClientConfig = {
|
|
42
|
-
url: string;
|
|
43
|
-
headers: {
|
|
44
|
-
[key: string]: string;
|
|
45
|
-
};
|
|
46
|
-
retryConfig: {
|
|
47
|
-
max: number;
|
|
48
|
-
waitBeforeRetry?: number;
|
|
49
|
-
before: IResponseListener;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
type LogInfo = {
|
|
53
|
-
query: string;
|
|
54
|
-
variables: any;
|
|
55
|
-
formatGraphQL: any;
|
|
56
|
-
kind: string;
|
|
57
|
-
queryName: string;
|
|
58
|
-
response?: any;
|
|
59
|
-
error?: Error;
|
|
60
|
-
duration: number;
|
|
61
|
-
};
|
|
62
|
-
declare class GraphQLClientError extends Error {
|
|
63
|
-
responseData: ResponseData;
|
|
64
|
-
constructor(responseData: ResponseData);
|
|
65
|
-
get message(): string;
|
|
66
|
-
get response(): ResponseData;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
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, Unpacked as U, ResponseListenerInfo as a, Replacement as b, DeepReplace as c, RawEndpoint as d };
|
package/src/__testClient.d.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
// noinspection TypeScriptUnresolvedVariable, ES6UnusedImports, JSUnusedLocalSymbols, TypeScriptCheckImport
|
|
2
|
-
import { DeepRequired } from "ts-essentials"
|
|
3
|
-
import { Maybe, IResponseListener, Endpoint } from "."
|
|
4
|
-
|
|
5
|
-
// Scalars
|
|
6
|
-
export type IDate = string | Date
|
|
7
|
-
export declare type ISODate = IDate
|
|
8
|
-
|
|
9
|
-
// Enums
|
|
10
|
-
|
|
11
|
-
export declare enum BookType {
|
|
12
|
-
dolor = "DOLOR",
|
|
13
|
-
ipsum = "IPSUM",
|
|
14
|
-
sit = "SIT",
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type AllEnums = BookType
|
|
18
|
-
|
|
19
|
-
// Args
|
|
20
|
-
export interface BooksWithoutParamsArgs {}
|
|
21
|
-
export interface BooksWithOptionalParamsArgs {
|
|
22
|
-
params?: BookSearchParamsAllOptional
|
|
23
|
-
}
|
|
24
|
-
export interface BooksWithRequiredParamsArgs {
|
|
25
|
-
params: BookSearchParamsSomeRequired
|
|
26
|
-
}
|
|
27
|
-
export interface FailingQueryArgs {
|
|
28
|
-
id: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Input/Output Types
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
export interface Book {
|
|
38
|
-
title?: string
|
|
39
|
-
author?: string
|
|
40
|
-
type?: BookType
|
|
41
|
-
dateCreated?: ISODate
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
export interface BookSearchParamsAllOptional {
|
|
49
|
-
title?: string
|
|
50
|
-
author?: string
|
|
51
|
-
createdAfter?: ISODate
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
export interface BookSearchParamsSomeRequired {
|
|
59
|
-
title: string
|
|
60
|
-
author?: string
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @deprecated Avoid directly using this interface. Instead, create a type alias based on the query/mutation return type.
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
export interface Query {
|
|
68
|
-
booksWithoutParams?: Book[]
|
|
69
|
-
booksWithOptionalParams?: Book[]
|
|
70
|
-
booksWithRequiredParams?: Book[]
|
|
71
|
-
failingQuery?: string
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Selection Types
|
|
75
|
-
|
|
76
|
-
export interface BookSelection {
|
|
77
|
-
title?: boolean
|
|
78
|
-
author?: boolean
|
|
79
|
-
type?: boolean
|
|
80
|
-
dateCreated?: boolean
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export interface BookSearchParamsAllOptionalSelection {
|
|
84
|
-
title?: boolean
|
|
85
|
-
author?: boolean
|
|
86
|
-
createdAfter?: boolean
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface BookSearchParamsSomeRequiredSelection {
|
|
90
|
-
title?: boolean
|
|
91
|
-
author?: boolean
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export declare const myApiClient: {
|
|
95
|
-
addResponseListener: (listener: IResponseListener) => void
|
|
96
|
-
setHeader: (key: string, value: string) => void
|
|
97
|
-
setHeaders: (newHeaders: { [k: string]: string }) => void
|
|
98
|
-
setUrl: (url: string) => void
|
|
99
|
-
setRetryConfig: (options: {
|
|
100
|
-
max: number
|
|
101
|
-
waitBeforeRetry?: number
|
|
102
|
-
before?: IResponseListener
|
|
103
|
-
}) => void
|
|
104
|
-
queries: {
|
|
105
|
-
booksWithoutParams: Endpoint<
|
|
106
|
-
{
|
|
107
|
-
__headers?: { [key: string]: string }
|
|
108
|
-
__retry?: boolean
|
|
109
|
-
__alias?: string
|
|
110
|
-
__url?: string
|
|
111
|
-
} & BookSelection,
|
|
112
|
-
Book[],
|
|
113
|
-
AllEnums
|
|
114
|
-
>
|
|
115
|
-
booksWithOptionalParams: Endpoint<
|
|
116
|
-
{
|
|
117
|
-
__headers?: { [key: string]: string }
|
|
118
|
-
__retry?: boolean
|
|
119
|
-
__alias?: string
|
|
120
|
-
__url?: string
|
|
121
|
-
__args?: BooksWithOptionalParamsArgs
|
|
122
|
-
} & BookSelection,
|
|
123
|
-
Book[],
|
|
124
|
-
AllEnums
|
|
125
|
-
>
|
|
126
|
-
booksWithRequiredParams: Endpoint<
|
|
127
|
-
{
|
|
128
|
-
__headers?: { [key: string]: string }
|
|
129
|
-
__retry?: boolean
|
|
130
|
-
__alias?: string
|
|
131
|
-
__url?: string
|
|
132
|
-
__args: BooksWithRequiredParamsArgs
|
|
133
|
-
} & BookSelection,
|
|
134
|
-
Book[],
|
|
135
|
-
AllEnums
|
|
136
|
-
>
|
|
137
|
-
failingQuery: Endpoint<
|
|
138
|
-
{
|
|
139
|
-
__headers?: { [key: string]: string }
|
|
140
|
-
__retry?: boolean
|
|
141
|
-
__alias?: string
|
|
142
|
-
__url?: string
|
|
143
|
-
__args: FailingQueryArgs
|
|
144
|
-
},
|
|
145
|
-
string,
|
|
146
|
-
AllEnums
|
|
147
|
-
>
|
|
148
|
-
}
|
|
149
|
-
mutations: {}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export default myApiClient
|
package/src/__testClient.js
DELETED
|
@@ -1,110 +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("./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 responseListeners = [];
|
|
73
|
-
let errorsParser = void 0;
|
|
74
|
-
let apiEndpoint = (0, import_endpoint.getApiEndpointCreator)({
|
|
75
|
-
getClient: () => ({ url, headers, retryConfig }),
|
|
76
|
-
responseListeners,
|
|
77
|
-
maxAge: 3e4,
|
|
78
|
-
verbose,
|
|
79
|
-
typesTree,
|
|
80
|
-
formatGraphQL,
|
|
81
|
-
errorsParser
|
|
82
|
-
});
|
|
83
|
-
const myApiClient = {
|
|
84
|
-
addResponseListener: (listener) => responseListeners.push(listener),
|
|
85
|
-
setHeader: (key, value) => {
|
|
86
|
-
headers[key] = value;
|
|
87
|
-
},
|
|
88
|
-
setHeaders: (newHeaders) => {
|
|
89
|
-
headers = newHeaders;
|
|
90
|
-
},
|
|
91
|
-
setRetryConfig: (options) => {
|
|
92
|
-
if (!Number.isInteger(options.max) || options.max < 0) {
|
|
93
|
-
throw new Error("retryOptions.max should be a non-negative integer");
|
|
94
|
-
}
|
|
95
|
-
retryConfig = {
|
|
96
|
-
max: options.max,
|
|
97
|
-
waitBeforeRetry: options.waitBeforeRetry,
|
|
98
|
-
before: options.before
|
|
99
|
-
};
|
|
100
|
-
},
|
|
101
|
-
setUrl: (_url) => url = _url,
|
|
102
|
-
queries: {
|
|
103
|
-
booksWithoutParams: apiEndpoint("query", "booksWithoutParams"),
|
|
104
|
-
booksWithOptionalParams: apiEndpoint("query", "booksWithOptionalParams"),
|
|
105
|
-
booksWithRequiredParams: apiEndpoint("query", "booksWithRequiredParams"),
|
|
106
|
-
failingQuery: apiEndpoint("query", "failingQuery")
|
|
107
|
-
},
|
|
108
|
-
mutations: {}
|
|
109
|
-
};
|
|
110
|
-
var stdin_default = myApiClient;
|