@avantstay/graphql-ts-client 10.5.0 → 10.5.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/README.md +1 -1
- package/dist/endpoint.d.ts +9 -9
- package/dist/endpoint.js +97 -90
- package/dist/index.d.ts +17 -17
- package/dist/index.js +112 -100
- package/dist/types-85e628f6.d.ts +69 -0
- package/package.json +24 -19
- package/src/generateTypescriptClient.ts +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ yarn add graphql-ts-client
|
|
|
13
13
|
### Generate the client
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
|
-
import { generateTypescriptClient } from 'graphql-ts-client'
|
|
16
|
+
import { generateTypescriptClient } from '@avantstay/graphql-ts-client'
|
|
17
17
|
|
|
18
18
|
generateTypescriptClient({
|
|
19
19
|
output: './myAwesomeApi.ts',
|
package/dist/endpoint.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { C as ClientConfig, I as IResponseListener, E as Endpoint } from './types-
|
|
1
|
+
import { C as ClientConfig, I as IResponseListener, E as Endpoint } from './types-85e628f6.js';
|
|
2
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;
|
|
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
11
|
}) => <I = any, O = any, E = any>(kind: 'mutation' | 'query', queryName: string) => Endpoint<I, O, E>;
|
|
12
12
|
|
|
13
13
|
export { getApiEndpointCreator };
|
package/dist/endpoint.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
2
|
+
function _arrayLikeToArray(arr, len) {
|
|
3
3
|
if (len == null || len > arr.length) len = arr.length;
|
|
4
4
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
5
|
return arr2;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function _arrayWithHoles(arr) {
|
|
8
8
|
if (Array.isArray(arr)) return arr;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function _assertThisInitialized(self) {
|
|
11
11
|
if (self === void 0) {
|
|
12
12
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
13
13
|
}
|
|
@@ -27,7 +27,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
27
27
|
Promise.resolve(value).then(_next, _throw);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function _asyncToGenerator(fn) {
|
|
31
31
|
return function() {
|
|
32
32
|
var self = this, args = arguments;
|
|
33
33
|
return new Promise(function(resolve, reject) {
|
|
@@ -42,23 +42,34 @@ function _async_to_generator(fn) {
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function _classCallCheck(instance, Constructor) {
|
|
46
46
|
if (!(instance instanceof Constructor)) {
|
|
47
47
|
throw new TypeError("Cannot call a class as a function");
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
function isNativeReflectConstruct() {
|
|
51
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
52
|
+
if (Reflect.construct.sham) return false;
|
|
53
|
+
if (typeof Proxy === "function") return true;
|
|
54
|
+
try {
|
|
55
|
+
Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
|
|
56
|
+
return true;
|
|
57
|
+
} catch (e) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
50
61
|
function _construct(Parent, args, Class) {
|
|
51
|
-
if (
|
|
62
|
+
if (isNativeReflectConstruct()) {
|
|
52
63
|
_construct = Reflect.construct;
|
|
53
64
|
} else {
|
|
54
|
-
_construct = function
|
|
65
|
+
_construct = function _construct(Parent, args, Class) {
|
|
55
66
|
var a = [
|
|
56
67
|
null
|
|
57
68
|
];
|
|
58
69
|
a.push.apply(a, args);
|
|
59
70
|
var Constructor = Function.bind.apply(Parent, a);
|
|
60
71
|
var instance = new Constructor();
|
|
61
|
-
if (Class)
|
|
72
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
62
73
|
return instance;
|
|
63
74
|
};
|
|
64
75
|
}
|
|
@@ -73,12 +84,12 @@ function _defineProperties(target, props) {
|
|
|
73
84
|
Object.defineProperty(target, descriptor.key, descriptor);
|
|
74
85
|
}
|
|
75
86
|
}
|
|
76
|
-
function
|
|
87
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
77
88
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
78
89
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
79
90
|
return Constructor;
|
|
80
91
|
}
|
|
81
|
-
function
|
|
92
|
+
function _defineProperty(obj, key, value) {
|
|
82
93
|
if (key in obj) {
|
|
83
94
|
Object.defineProperty(obj, key, {
|
|
84
95
|
value: value,
|
|
@@ -91,11 +102,11 @@ function _define_property(obj, key, value) {
|
|
|
91
102
|
}
|
|
92
103
|
return obj;
|
|
93
104
|
}
|
|
94
|
-
function
|
|
95
|
-
|
|
105
|
+
function _getPrototypeOf(o) {
|
|
106
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
96
107
|
return o.__proto__ || Object.getPrototypeOf(o);
|
|
97
108
|
};
|
|
98
|
-
return
|
|
109
|
+
return _getPrototypeOf(o);
|
|
99
110
|
}
|
|
100
111
|
function _inherits(subClass, superClass) {
|
|
101
112
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
@@ -108,12 +119,12 @@ function _inherits(subClass, superClass) {
|
|
|
108
119
|
configurable: true
|
|
109
120
|
}
|
|
110
121
|
});
|
|
111
|
-
if (superClass)
|
|
122
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
112
123
|
}
|
|
113
|
-
function
|
|
124
|
+
function _isNativeFunction(fn) {
|
|
114
125
|
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
115
126
|
}
|
|
116
|
-
function
|
|
127
|
+
function _iterableToArrayLimit(arr, i) {
|
|
117
128
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
118
129
|
if (_i == null) return;
|
|
119
130
|
var _arr = [];
|
|
@@ -137,10 +148,10 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
137
148
|
}
|
|
138
149
|
return _arr;
|
|
139
150
|
}
|
|
140
|
-
function
|
|
151
|
+
function _nonIterableRest() {
|
|
141
152
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
142
153
|
}
|
|
143
|
-
function
|
|
154
|
+
function _objectSpread(target) {
|
|
144
155
|
for(var i = 1; i < arguments.length; i++){
|
|
145
156
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
146
157
|
var ownKeys = Object.keys(source);
|
|
@@ -150,7 +161,7 @@ function _object_spread(target) {
|
|
|
150
161
|
}));
|
|
151
162
|
}
|
|
152
163
|
ownKeys.forEach(function(key) {
|
|
153
|
-
|
|
164
|
+
_defineProperty(target, key, source[key]);
|
|
154
165
|
});
|
|
155
166
|
}
|
|
156
167
|
return target;
|
|
@@ -168,7 +179,7 @@ function ownKeys(object, enumerableOnly) {
|
|
|
168
179
|
}
|
|
169
180
|
return keys;
|
|
170
181
|
}
|
|
171
|
-
function
|
|
182
|
+
function _objectSpreadProps(target, source) {
|
|
172
183
|
source = source != null ? source : {};
|
|
173
184
|
if (Object.getOwnPropertyDescriptors) {
|
|
174
185
|
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
@@ -179,38 +190,38 @@ function _object_spread_props(target, source) {
|
|
|
179
190
|
}
|
|
180
191
|
return target;
|
|
181
192
|
}
|
|
182
|
-
function
|
|
183
|
-
if (call && (
|
|
193
|
+
function _possibleConstructorReturn(self, call) {
|
|
194
|
+
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
184
195
|
return call;
|
|
185
196
|
}
|
|
186
|
-
return
|
|
197
|
+
return _assertThisInitialized(self);
|
|
187
198
|
}
|
|
188
|
-
function
|
|
189
|
-
|
|
199
|
+
function _setPrototypeOf(o, p) {
|
|
200
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
190
201
|
o.__proto__ = p;
|
|
191
202
|
return o;
|
|
192
203
|
};
|
|
193
|
-
return
|
|
204
|
+
return _setPrototypeOf(o, p);
|
|
194
205
|
}
|
|
195
|
-
function
|
|
196
|
-
return
|
|
206
|
+
function _slicedToArray(arr, i) {
|
|
207
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
197
208
|
}
|
|
198
|
-
function
|
|
209
|
+
var _typeof = function(obj) {
|
|
199
210
|
"@swc/helpers - typeof";
|
|
200
211
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
201
|
-
}
|
|
202
|
-
function
|
|
212
|
+
};
|
|
213
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
203
214
|
if (!o) return;
|
|
204
|
-
if (typeof o === "string") return
|
|
215
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
205
216
|
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
206
217
|
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
207
218
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
208
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return
|
|
219
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
209
220
|
}
|
|
210
|
-
function
|
|
221
|
+
function _wrapNativeSuper(Class) {
|
|
211
222
|
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
212
|
-
|
|
213
|
-
if (Class === null || !
|
|
223
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
224
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
214
225
|
if (typeof Class !== "function") {
|
|
215
226
|
throw new TypeError("Super expression must either be null or a function");
|
|
216
227
|
}
|
|
@@ -219,7 +230,7 @@ function _wrap_native_super(Class) {
|
|
|
219
230
|
_cache.set(Class, Wrapper);
|
|
220
231
|
}
|
|
221
232
|
function Wrapper() {
|
|
222
|
-
return _construct(Class, arguments,
|
|
233
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
223
234
|
}
|
|
224
235
|
Wrapper.prototype = Object.create(Class.prototype, {
|
|
225
236
|
constructor: {
|
|
@@ -229,11 +240,11 @@ function _wrap_native_super(Class) {
|
|
|
229
240
|
configurable: true
|
|
230
241
|
}
|
|
231
242
|
});
|
|
232
|
-
return
|
|
243
|
+
return _setPrototypeOf(Wrapper, Class);
|
|
233
244
|
};
|
|
234
|
-
return
|
|
245
|
+
return _wrapNativeSuper(Class);
|
|
235
246
|
}
|
|
236
|
-
function
|
|
247
|
+
function _isNativeReflectConstruct() {
|
|
237
248
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
238
249
|
if (Reflect.construct.sham) return false;
|
|
239
250
|
if (typeof Proxy === "function") return true;
|
|
@@ -244,20 +255,20 @@ function _is_native_reflect_construct() {
|
|
|
244
255
|
return false;
|
|
245
256
|
}
|
|
246
257
|
}
|
|
247
|
-
function
|
|
248
|
-
var hasNativeReflectConstruct =
|
|
258
|
+
function _createSuper(Derived) {
|
|
259
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
249
260
|
return function _createSuperInternal() {
|
|
250
|
-
var Super =
|
|
261
|
+
var Super = _getPrototypeOf(Derived), result;
|
|
251
262
|
if (hasNativeReflectConstruct) {
|
|
252
|
-
var NewTarget =
|
|
263
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
253
264
|
result = Reflect.construct(Super, arguments, NewTarget);
|
|
254
265
|
} else {
|
|
255
266
|
result = Super.apply(this, arguments);
|
|
256
267
|
}
|
|
257
|
-
return
|
|
268
|
+
return _possibleConstructorReturn(this, result);
|
|
258
269
|
};
|
|
259
270
|
}
|
|
260
|
-
function
|
|
271
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
261
272
|
var f, y, t, g, _ = {
|
|
262
273
|
label: 0,
|
|
263
274
|
sent: function() {
|
|
@@ -351,7 +362,7 @@ function _ts_generator(thisArg, body) {
|
|
|
351
362
|
done: true
|
|
352
363
|
};
|
|
353
364
|
}
|
|
354
|
-
}
|
|
365
|
+
};
|
|
355
366
|
var __create = Object.create;
|
|
356
367
|
var __defProp = Object.defineProperty;
|
|
357
368
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -396,11 +407,7 @@ var __copyProps = function(to, from, except, desc) {
|
|
|
396
407
|
return to;
|
|
397
408
|
};
|
|
398
409
|
var __toESM = function(mod, isNodeMode, target) {
|
|
399
|
-
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
400
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
401
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
402
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
403
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
410
|
+
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
404
411
|
value: mod,
|
|
405
412
|
enumerable: true
|
|
406
413
|
}) : target, mod);
|
|
@@ -423,17 +430,17 @@ var import_moize = __toESM(require("moize"));
|
|
|
423
430
|
var import_axios = __toESM(require("axios"));
|
|
424
431
|
// src/types.ts
|
|
425
432
|
var GraphQLClientError = /*#__PURE__*/ function(Error1) {
|
|
426
|
-
_inherits(
|
|
427
|
-
var _super =
|
|
428
|
-
function
|
|
429
|
-
|
|
433
|
+
_inherits(GraphQLClientError1, Error1);
|
|
434
|
+
var _super = _createSuper(GraphQLClientError1);
|
|
435
|
+
function GraphQLClientError1(responseData) {
|
|
436
|
+
_classCallCheck(this, GraphQLClientError1);
|
|
430
437
|
var _this;
|
|
431
438
|
_this = _super.call(this);
|
|
432
439
|
_this.responseData = responseData;
|
|
433
|
-
Object.setPrototypeOf(
|
|
440
|
+
Object.setPrototypeOf(_assertThisInitialized(_this), GraphQLClientError.prototype);
|
|
434
441
|
return _this;
|
|
435
442
|
}
|
|
436
|
-
|
|
443
|
+
_createClass(GraphQLClientError1, [
|
|
437
444
|
{
|
|
438
445
|
key: "message",
|
|
439
446
|
get: function get() {
|
|
@@ -449,8 +456,8 @@ var GraphQLClientError = /*#__PURE__*/ function(Error1) {
|
|
|
449
456
|
}
|
|
450
457
|
}
|
|
451
458
|
]);
|
|
452
|
-
return
|
|
453
|
-
}(
|
|
459
|
+
return GraphQLClientError1;
|
|
460
|
+
}(_wrapNativeSuper(Error));
|
|
454
461
|
// src/graphqlRequest.ts
|
|
455
462
|
var sleep = function() {
|
|
456
463
|
var ms = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
|
|
@@ -464,9 +471,9 @@ function graphqlRequest(_) {
|
|
|
464
471
|
return _graphqlRequest.apply(this, arguments);
|
|
465
472
|
}
|
|
466
473
|
function _graphqlRequest() {
|
|
467
|
-
_graphqlRequest =
|
|
468
|
-
var _param_shouldRetry, shouldRetry, _param_axios, axios, queryName, client, query, _param_requestHeaders, requestHeaders, variables, failureMode, errorsParser, _lastResponse_errors, lastResponse, maxRetrials, trial,
|
|
469
|
-
return
|
|
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;
|
|
476
|
+
return __generator(this, function(_state) {
|
|
470
477
|
switch(_state.label){
|
|
471
478
|
case 0:
|
|
472
479
|
_param_shouldRetry = param.shouldRetry, shouldRetry = _param_shouldRetry === void 0 ? true : _param_shouldRetry, _param_axios = param.axios, axios = _param_axios === void 0 ? import_axios.default : _param_axios, queryName = param.queryName, client = param.client, query = param.query, _param_requestHeaders = param.requestHeaders, requestHeaders = _param_requestHeaders === void 0 ? {} : _param_requestHeaders, variables = param.variables, failureMode = param.failureMode, errorsParser = param.errorsParser;
|
|
@@ -478,7 +485,7 @@ function _graphqlRequest() {
|
|
|
478
485
|
3,
|
|
479
486
|
9
|
|
480
487
|
];
|
|
481
|
-
infoParams =
|
|
488
|
+
infoParams = _objectSpread({
|
|
482
489
|
_q: queryName
|
|
483
490
|
}, trial > 0 ? {
|
|
484
491
|
_retrial: trial + 1
|
|
@@ -491,7 +498,7 @@ function _graphqlRequest() {
|
|
|
491
498
|
operationName: queryName
|
|
492
499
|
}, {
|
|
493
500
|
params: infoParams,
|
|
494
|
-
headers:
|
|
501
|
+
headers: _objectSpread({
|
|
495
502
|
"Content-Type": "application/json"
|
|
496
503
|
}, client.headers, requestHeaders),
|
|
497
504
|
validateStatus: function() {
|
|
@@ -502,7 +509,7 @@ function _graphqlRequest() {
|
|
|
502
509
|
case 2:
|
|
503
510
|
_ref = _state.sent(), tmp = _ref.data, responseData = tmp === void 0 ? {} : tmp, headers = _ref.headers, status = _ref.status;
|
|
504
511
|
data = responseData.data, errors = responseData.errors, warnings = responseData.warnings;
|
|
505
|
-
if (status >= 400 && !(
|
|
512
|
+
if (status >= 400 && !(errors === null || errors === void 0 ? void 0 : errors.length)) {
|
|
506
513
|
errors = [
|
|
507
514
|
{
|
|
508
515
|
message: 'Request "'.concat(queryName, '" failed with status ').concat(status)
|
|
@@ -516,7 +523,7 @@ function _graphqlRequest() {
|
|
|
516
523
|
headers: headers,
|
|
517
524
|
status: status
|
|
518
525
|
};
|
|
519
|
-
if (!!(
|
|
526
|
+
if (!!(errors === null || errors === void 0 ? void 0 : errors.length)) return [
|
|
520
527
|
3,
|
|
521
528
|
3
|
|
522
529
|
];
|
|
@@ -599,17 +606,17 @@ function jsonToGraphQLQuery(param) {
|
|
|
599
606
|
"__headers"
|
|
600
607
|
]));
|
|
601
608
|
extractVariables({
|
|
602
|
-
jsonQuery:
|
|
609
|
+
jsonQuery: _defineProperty({}, queryName, newJsonQuery),
|
|
603
610
|
variables: variablesData,
|
|
604
611
|
parentType: kind === "query" ? typesTree.Query : typesTree.Mutation
|
|
605
612
|
});
|
|
606
613
|
var variablesQuery = Object.keys(variablesData).length ? "(".concat(entries(variablesData).map(function(param) {
|
|
607
|
-
var _param =
|
|
614
|
+
var _param = _slicedToArray(param, 2), queryName2 = _param[0], type = _param[1].type;
|
|
608
615
|
return "$".concat(queryName2, ": ").concat(type);
|
|
609
616
|
}).join(", "), ")") : "";
|
|
610
617
|
var query = "".concat(kind, " ").concat(alias || queryName).concat(variablesQuery, " { ").concat(alias ? "".concat(alias, ":") : "").concat(queryName).concat(toGraphql(newJsonQuery), " }");
|
|
611
618
|
var variables = fromEntries(entries(variablesData).map(function(param) {
|
|
612
|
-
var _param =
|
|
619
|
+
var _param = _slicedToArray(param, 2), k = _param[0], v = _param[1];
|
|
613
620
|
return [
|
|
614
621
|
k,
|
|
615
622
|
v.value
|
|
@@ -648,18 +655,18 @@ function extractVariables(param) {
|
|
|
648
655
|
}
|
|
649
656
|
function toGraphql(jsonQuery) {
|
|
650
657
|
var fields = entries(jsonQuery).filter(function(param) {
|
|
651
|
-
var _param =
|
|
658
|
+
var _param = _slicedToArray(param, 2), k = _param[0], v = _param[1];
|
|
652
659
|
return k !== "__args" && v !== false && v !== void 0;
|
|
653
660
|
}).map(function(param) {
|
|
654
|
-
var _param =
|
|
661
|
+
var _param = _slicedToArray(param, 2), k = _param[0], v = _param[1];
|
|
655
662
|
return typeof v === "object" ? "".concat(k).concat(toGraphql(v)) : k;
|
|
656
663
|
}).join(" ");
|
|
657
664
|
var validArgs = jsonQuery.__args ? entries(jsonQuery.__args).filter(function(param) {
|
|
658
|
-
var _param =
|
|
665
|
+
var _param = _slicedToArray(param, 2), _ = _param[0], v = _param[1];
|
|
659
666
|
return v !== void 0;
|
|
660
667
|
}) : [];
|
|
661
668
|
var argsQuery = validArgs.length ? "(".concat(validArgs.map(function(param) {
|
|
662
|
-
var _param =
|
|
669
|
+
var _param = _slicedToArray(param, 2), k = _param[0], v = _param[1];
|
|
663
670
|
return "".concat(k, ":").concat(v.substr(VAR_PREFIX_LENGTH));
|
|
664
671
|
}).join(","), ")") : "";
|
|
665
672
|
return "".concat(argsQuery, " ").concat(fields ? "{ ".concat(fields, " }") : "");
|
|
@@ -697,21 +704,21 @@ var executeListeners = function(listeners, data) {
|
|
|
697
704
|
var getApiEndpointCreator = function(apiConfig) {
|
|
698
705
|
return function(kind, queryName) {
|
|
699
706
|
var rawEndpoint = function() {
|
|
700
|
-
var _ref =
|
|
701
|
-
var
|
|
702
|
-
return
|
|
707
|
+
var _ref = _asyncToGenerator(function(failureMode, jsonQuery) {
|
|
708
|
+
var _jsonQuery___alias, alias, _jsonQuery___retry, shouldRetry, _jsonQuery___headers, requestHeaders, _jsonToGraphQLQuery, query, variables, start, logOptions, responseListenerData, _ref, data, errors, warnings, headers, status, response, error;
|
|
709
|
+
return __generator(this, function(_state) {
|
|
703
710
|
switch(_state.label){
|
|
704
711
|
case 0:
|
|
705
|
-
alias = (_jsonQuery___alias =
|
|
706
|
-
shouldRetry = (_jsonQuery___retry =
|
|
707
|
-
requestHeaders = (_jsonQuery___headers =
|
|
712
|
+
alias = (_jsonQuery___alias = jsonQuery === null || jsonQuery === void 0 ? void 0 : jsonQuery.__alias) !== null && _jsonQuery___alias !== void 0 ? _jsonQuery___alias : queryName;
|
|
713
|
+
shouldRetry = (_jsonQuery___retry = jsonQuery === null || jsonQuery === void 0 ? void 0 : jsonQuery.__retry) !== null && _jsonQuery___retry !== void 0 ? _jsonQuery___retry : true;
|
|
714
|
+
requestHeaders = (_jsonQuery___headers = jsonQuery === null || jsonQuery === void 0 ? void 0 : jsonQuery.__headers) !== null && _jsonQuery___headers !== void 0 ? _jsonQuery___headers : {};
|
|
708
715
|
_jsonToGraphQLQuery = jsonToGraphQLQuery({
|
|
709
716
|
kind: kind,
|
|
710
717
|
queryName: queryName,
|
|
711
718
|
jsonQuery: jsonQuery,
|
|
712
719
|
typesTree: apiConfig.typesTree
|
|
713
720
|
}), query = _jsonToGraphQLQuery.query, variables = _jsonToGraphQLQuery.variables;
|
|
714
|
-
start =
|
|
721
|
+
start = +new Date();
|
|
715
722
|
logOptions = {
|
|
716
723
|
kind: kind,
|
|
717
724
|
queryName: alias,
|
|
@@ -756,18 +763,18 @@ var getApiEndpointCreator = function(apiConfig) {
|
|
|
756
763
|
errors: errors
|
|
757
764
|
};
|
|
758
765
|
if (apiConfig.verbose && globalThis.document) {
|
|
759
|
-
logRequest(
|
|
766
|
+
logRequest(_objectSpreadProps(_objectSpread({}, logOptions), {
|
|
760
767
|
response: response,
|
|
761
|
-
duration:
|
|
768
|
+
duration: +new Date() - start
|
|
762
769
|
}));
|
|
763
770
|
}
|
|
764
|
-
executeListeners(apiConfig.responseListeners,
|
|
771
|
+
executeListeners(apiConfig.responseListeners, _objectSpreadProps(_objectSpread({}, responseListenerData), {
|
|
765
772
|
response: response
|
|
766
773
|
}));
|
|
767
774
|
return [
|
|
768
775
|
2,
|
|
769
776
|
{
|
|
770
|
-
data:
|
|
777
|
+
data: data === null || data === void 0 ? void 0 : data[alias],
|
|
771
778
|
errors: errors,
|
|
772
779
|
warnings: warnings,
|
|
773
780
|
headers: headers,
|
|
@@ -777,12 +784,12 @@ var getApiEndpointCreator = function(apiConfig) {
|
|
|
777
784
|
case 3:
|
|
778
785
|
error = _state.sent();
|
|
779
786
|
if (apiConfig.verbose && globalThis.document) {
|
|
780
|
-
logRequest(
|
|
787
|
+
logRequest(_objectSpreadProps(_objectSpread({}, logOptions), {
|
|
781
788
|
error: error,
|
|
782
|
-
duration:
|
|
789
|
+
duration: +new Date() - start
|
|
783
790
|
}));
|
|
784
791
|
}
|
|
785
|
-
executeListeners(apiConfig.responseListeners,
|
|
792
|
+
executeListeners(apiConfig.responseListeners, _objectSpreadProps(_objectSpread({}, responseListenerData), {
|
|
786
793
|
response: error.response
|
|
787
794
|
}));
|
|
788
795
|
throw error;
|
|
@@ -798,9 +805,9 @@ var getApiEndpointCreator = function(apiConfig) {
|
|
|
798
805
|
};
|
|
799
806
|
}();
|
|
800
807
|
var endpoint = function() {
|
|
801
|
-
var _ref =
|
|
808
|
+
var _ref = _asyncToGenerator(function(jsonQuery) {
|
|
802
809
|
var data;
|
|
803
|
-
return
|
|
810
|
+
return __generator(this, function(_state) {
|
|
804
811
|
switch(_state.label){
|
|
805
812
|
case 0:
|
|
806
813
|
return [
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { PathLike } from 'fs';
|
|
2
|
-
export { C as ClientConfig, c as DeepReplace, D as Defined, E as Endpoint, G as GraphQLClientError, I as IResponseListener, J as JsonOutput, L as LogInfo, M as Maybe, P as Projection, d as RawEndpoint, b as Replacement, R as ResponseData, a as ResponseListenerInfo, U as Unpacked } from './types-
|
|
2
|
+
export { C as ClientConfig, c as DeepReplace, D as Defined, E as Endpoint, G as GraphQLClientError, I as IResponseListener, J as JsonOutput, L as LogInfo, M as Maybe, P as Projection, d as RawEndpoint, b as Replacement, R as ResponseData, a as ResponseListenerInfo, U as Unpacked } from './types-85e628f6.js';
|
|
3
3
|
|
|
4
|
-
type IClientOptions = {
|
|
5
|
-
output?: PathLike;
|
|
6
|
-
clientName?: string;
|
|
7
|
-
headers?: {
|
|
8
|
-
[key: string]: string;
|
|
9
|
-
};
|
|
10
|
-
introspectionEndpoint?: string;
|
|
11
|
-
endpoint: string;
|
|
12
|
-
verbose?: boolean;
|
|
13
|
-
formatGraphQL?: boolean;
|
|
14
|
-
skipCache?: boolean;
|
|
15
|
-
errorsParser?: (errors: any[]) => any;
|
|
16
|
-
};
|
|
17
|
-
declare function generateTypescriptClient({ introspectionEndpoint, output, ...options }: IClientOptions): Promise<{
|
|
18
|
-
typings: string;
|
|
19
|
-
js: string;
|
|
4
|
+
type IClientOptions = {
|
|
5
|
+
output?: PathLike;
|
|
6
|
+
clientName?: string;
|
|
7
|
+
headers?: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
introspectionEndpoint?: string;
|
|
11
|
+
endpoint: string;
|
|
12
|
+
verbose?: boolean;
|
|
13
|
+
formatGraphQL?: boolean;
|
|
14
|
+
skipCache?: boolean;
|
|
15
|
+
errorsParser?: (errors: any[]) => any;
|
|
16
|
+
};
|
|
17
|
+
declare function generateTypescriptClient({ introspectionEndpoint, output, ...options }: IClientOptions): Promise<{
|
|
18
|
+
typings: string;
|
|
19
|
+
js: string;
|
|
20
20
|
}>;
|
|
21
21
|
|
|
22
22
|
export { generateTypescriptClient };
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
2
|
+
function _arrayLikeToArray(arr, len) {
|
|
3
3
|
if (len == null || len > arr.length) len = arr.length;
|
|
4
4
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
5
|
return arr2;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function _arrayWithHoles(arr) {
|
|
8
8
|
if (Array.isArray(arr)) return arr;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
if (Array.isArray(arr)) return
|
|
10
|
+
function _arrayWithoutHoles(arr) {
|
|
11
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function _assertThisInitialized(self) {
|
|
14
14
|
if (self === void 0) {
|
|
15
15
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
16
16
|
}
|
|
@@ -30,7 +30,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
30
30
|
Promise.resolve(value).then(_next, _throw);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function _asyncToGenerator(fn) {
|
|
34
34
|
return function() {
|
|
35
35
|
var self = this, args = arguments;
|
|
36
36
|
return new Promise(function(resolve, reject) {
|
|
@@ -45,23 +45,34 @@ function _async_to_generator(fn) {
|
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function _classCallCheck(instance, Constructor) {
|
|
49
49
|
if (!(instance instanceof Constructor)) {
|
|
50
50
|
throw new TypeError("Cannot call a class as a function");
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
function isNativeReflectConstruct() {
|
|
54
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
55
|
+
if (Reflect.construct.sham) return false;
|
|
56
|
+
if (typeof Proxy === "function") return true;
|
|
57
|
+
try {
|
|
58
|
+
Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
|
|
59
|
+
return true;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
53
64
|
function _construct(Parent, args, Class) {
|
|
54
|
-
if (
|
|
65
|
+
if (isNativeReflectConstruct()) {
|
|
55
66
|
_construct = Reflect.construct;
|
|
56
67
|
} else {
|
|
57
|
-
_construct = function
|
|
68
|
+
_construct = function _construct(Parent, args, Class) {
|
|
58
69
|
var a = [
|
|
59
70
|
null
|
|
60
71
|
];
|
|
61
72
|
a.push.apply(a, args);
|
|
62
73
|
var Constructor = Function.bind.apply(Parent, a);
|
|
63
74
|
var instance = new Constructor();
|
|
64
|
-
if (Class)
|
|
75
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
65
76
|
return instance;
|
|
66
77
|
};
|
|
67
78
|
}
|
|
@@ -76,12 +87,12 @@ function _defineProperties(target, props) {
|
|
|
76
87
|
Object.defineProperty(target, descriptor.key, descriptor);
|
|
77
88
|
}
|
|
78
89
|
}
|
|
79
|
-
function
|
|
90
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
80
91
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
81
92
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
82
93
|
return Constructor;
|
|
83
94
|
}
|
|
84
|
-
function
|
|
95
|
+
function _defineProperty(obj, key, value) {
|
|
85
96
|
if (key in obj) {
|
|
86
97
|
Object.defineProperty(obj, key, {
|
|
87
98
|
value: value,
|
|
@@ -94,11 +105,11 @@ function _define_property(obj, key, value) {
|
|
|
94
105
|
}
|
|
95
106
|
return obj;
|
|
96
107
|
}
|
|
97
|
-
function
|
|
98
|
-
|
|
108
|
+
function _getPrototypeOf(o) {
|
|
109
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
99
110
|
return o.__proto__ || Object.getPrototypeOf(o);
|
|
100
111
|
};
|
|
101
|
-
return
|
|
112
|
+
return _getPrototypeOf(o);
|
|
102
113
|
}
|
|
103
114
|
function _inherits(subClass, superClass) {
|
|
104
115
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
@@ -111,15 +122,15 @@ function _inherits(subClass, superClass) {
|
|
|
111
122
|
configurable: true
|
|
112
123
|
}
|
|
113
124
|
});
|
|
114
|
-
if (superClass)
|
|
125
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
115
126
|
}
|
|
116
|
-
function
|
|
127
|
+
function _isNativeFunction(fn) {
|
|
117
128
|
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
118
129
|
}
|
|
119
|
-
function
|
|
130
|
+
function _iterableToArray(iter) {
|
|
120
131
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
121
132
|
}
|
|
122
|
-
function
|
|
133
|
+
function _iterableToArrayLimit(arr, i) {
|
|
123
134
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
124
135
|
if (_i == null) return;
|
|
125
136
|
var _arr = [];
|
|
@@ -143,13 +154,13 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
143
154
|
}
|
|
144
155
|
return _arr;
|
|
145
156
|
}
|
|
146
|
-
function
|
|
157
|
+
function _nonIterableRest() {
|
|
147
158
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
148
159
|
}
|
|
149
|
-
function
|
|
160
|
+
function _nonIterableSpread() {
|
|
150
161
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
151
162
|
}
|
|
152
|
-
function
|
|
163
|
+
function _objectSpread(target) {
|
|
153
164
|
for(var i = 1; i < arguments.length; i++){
|
|
154
165
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
155
166
|
var ownKeys = Object.keys(source);
|
|
@@ -159,7 +170,7 @@ function _object_spread(target) {
|
|
|
159
170
|
}));
|
|
160
171
|
}
|
|
161
172
|
ownKeys.forEach(function(key) {
|
|
162
|
-
|
|
173
|
+
_defineProperty(target, key, source[key]);
|
|
163
174
|
});
|
|
164
175
|
}
|
|
165
176
|
return target;
|
|
@@ -177,7 +188,7 @@ function ownKeys(object, enumerableOnly) {
|
|
|
177
188
|
}
|
|
178
189
|
return keys;
|
|
179
190
|
}
|
|
180
|
-
function
|
|
191
|
+
function _objectSpreadProps(target, source) {
|
|
181
192
|
source = source != null ? source : {};
|
|
182
193
|
if (Object.getOwnPropertyDescriptors) {
|
|
183
194
|
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
@@ -188,9 +199,9 @@ function _object_spread_props(target, source) {
|
|
|
188
199
|
}
|
|
189
200
|
return target;
|
|
190
201
|
}
|
|
191
|
-
function
|
|
202
|
+
function _objectWithoutProperties(source, excluded) {
|
|
192
203
|
if (source == null) return {};
|
|
193
|
-
var target =
|
|
204
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
194
205
|
var key, i;
|
|
195
206
|
if (Object.getOwnPropertySymbols) {
|
|
196
207
|
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
@@ -203,7 +214,7 @@ function _object_without_properties(source, excluded) {
|
|
|
203
214
|
}
|
|
204
215
|
return target;
|
|
205
216
|
}
|
|
206
|
-
function
|
|
217
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
207
218
|
if (source == null) return {};
|
|
208
219
|
var target = {};
|
|
209
220
|
var sourceKeys = Object.keys(source);
|
|
@@ -215,41 +226,41 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
215
226
|
}
|
|
216
227
|
return target;
|
|
217
228
|
}
|
|
218
|
-
function
|
|
219
|
-
if (call && (
|
|
229
|
+
function _possibleConstructorReturn(self, call) {
|
|
230
|
+
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
220
231
|
return call;
|
|
221
232
|
}
|
|
222
|
-
return
|
|
233
|
+
return _assertThisInitialized(self);
|
|
223
234
|
}
|
|
224
|
-
function
|
|
225
|
-
|
|
235
|
+
function _setPrototypeOf(o, p) {
|
|
236
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
226
237
|
o.__proto__ = p;
|
|
227
238
|
return o;
|
|
228
239
|
};
|
|
229
|
-
return
|
|
240
|
+
return _setPrototypeOf(o, p);
|
|
230
241
|
}
|
|
231
|
-
function
|
|
232
|
-
return
|
|
242
|
+
function _slicedToArray(arr, i) {
|
|
243
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
233
244
|
}
|
|
234
|
-
function
|
|
235
|
-
return
|
|
245
|
+
function _toConsumableArray(arr) {
|
|
246
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
236
247
|
}
|
|
237
|
-
function
|
|
248
|
+
var _typeof = function(obj) {
|
|
238
249
|
"@swc/helpers - typeof";
|
|
239
250
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
240
|
-
}
|
|
241
|
-
function
|
|
251
|
+
};
|
|
252
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
242
253
|
if (!o) return;
|
|
243
|
-
if (typeof o === "string") return
|
|
254
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
244
255
|
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
245
256
|
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
246
257
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
247
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return
|
|
258
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
248
259
|
}
|
|
249
|
-
function
|
|
260
|
+
function _wrapNativeSuper(Class) {
|
|
250
261
|
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
251
|
-
|
|
252
|
-
if (Class === null || !
|
|
262
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
263
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
253
264
|
if (typeof Class !== "function") {
|
|
254
265
|
throw new TypeError("Super expression must either be null or a function");
|
|
255
266
|
}
|
|
@@ -258,7 +269,7 @@ function _wrap_native_super(Class) {
|
|
|
258
269
|
_cache.set(Class, Wrapper);
|
|
259
270
|
}
|
|
260
271
|
function Wrapper() {
|
|
261
|
-
return _construct(Class, arguments,
|
|
272
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
262
273
|
}
|
|
263
274
|
Wrapper.prototype = Object.create(Class.prototype, {
|
|
264
275
|
constructor: {
|
|
@@ -268,11 +279,11 @@ function _wrap_native_super(Class) {
|
|
|
268
279
|
configurable: true
|
|
269
280
|
}
|
|
270
281
|
});
|
|
271
|
-
return
|
|
282
|
+
return _setPrototypeOf(Wrapper, Class);
|
|
272
283
|
};
|
|
273
|
-
return
|
|
284
|
+
return _wrapNativeSuper(Class);
|
|
274
285
|
}
|
|
275
|
-
function
|
|
286
|
+
function _isNativeReflectConstruct() {
|
|
276
287
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
277
288
|
if (Reflect.construct.sham) return false;
|
|
278
289
|
if (typeof Proxy === "function") return true;
|
|
@@ -283,20 +294,20 @@ function _is_native_reflect_construct() {
|
|
|
283
294
|
return false;
|
|
284
295
|
}
|
|
285
296
|
}
|
|
286
|
-
function
|
|
287
|
-
var hasNativeReflectConstruct =
|
|
297
|
+
function _createSuper(Derived) {
|
|
298
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
288
299
|
return function _createSuperInternal() {
|
|
289
|
-
var Super =
|
|
300
|
+
var Super = _getPrototypeOf(Derived), result;
|
|
290
301
|
if (hasNativeReflectConstruct) {
|
|
291
|
-
var NewTarget =
|
|
302
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
292
303
|
result = Reflect.construct(Super, arguments, NewTarget);
|
|
293
304
|
} else {
|
|
294
305
|
result = Super.apply(this, arguments);
|
|
295
306
|
}
|
|
296
|
-
return
|
|
307
|
+
return _possibleConstructorReturn(this, result);
|
|
297
308
|
};
|
|
298
309
|
}
|
|
299
|
-
function
|
|
310
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
300
311
|
var f, y, t, g, _ = {
|
|
301
312
|
label: 0,
|
|
302
313
|
sent: function() {
|
|
@@ -390,7 +401,7 @@ function _ts_generator(thisArg, body) {
|
|
|
390
401
|
done: true
|
|
391
402
|
};
|
|
392
403
|
}
|
|
393
|
-
}
|
|
404
|
+
};
|
|
394
405
|
var __create = Object.create;
|
|
395
406
|
var __defProp = Object.defineProperty;
|
|
396
407
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -435,11 +446,7 @@ var __copyProps = function(to, from, except, desc) {
|
|
|
435
446
|
return to;
|
|
436
447
|
};
|
|
437
448
|
var __toESM = function(mod, isNodeMode, target) {
|
|
438
|
-
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
439
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
440
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
441
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
442
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
449
|
+
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
443
450
|
value: mod,
|
|
444
451
|
enumerable: true
|
|
445
452
|
}) : target, mod);
|
|
@@ -477,7 +484,7 @@ var prettier = __toESM(require("prettier"));
|
|
|
477
484
|
// package.json
|
|
478
485
|
var package_default = {
|
|
479
486
|
name: "@avantstay/graphql-ts-client",
|
|
480
|
-
version: "10.5.
|
|
487
|
+
version: "10.5.1",
|
|
481
488
|
description: "GraphQL Typescript Client Generator",
|
|
482
489
|
author: "Wellington Guimaraes",
|
|
483
490
|
license: "MIT",
|
|
@@ -531,38 +538,43 @@ var package_default = {
|
|
|
531
538
|
],
|
|
532
539
|
dependencies: {
|
|
533
540
|
"@types/md5": "^2.3.2",
|
|
534
|
-
axios: "^
|
|
535
|
-
"axios-retry": "^3.
|
|
541
|
+
axios: "^0.24.0",
|
|
542
|
+
"axios-retry": "^3.2.4",
|
|
536
543
|
case: "^1.6.3",
|
|
537
|
-
esbuild: "^0.
|
|
538
|
-
graphql: "^
|
|
544
|
+
esbuild: "^0.13.14",
|
|
545
|
+
graphql: "^15.6.0",
|
|
539
546
|
lodash: "^4.17.21",
|
|
540
547
|
md5: "^2.3.0",
|
|
541
|
-
moize: "^6.1.
|
|
542
|
-
prettier: "^2.
|
|
548
|
+
moize: "^6.1.0",
|
|
549
|
+
prettier: "^2.5.1",
|
|
550
|
+
"temp-dir": "^3.0.0",
|
|
543
551
|
"ts-essentials": "^8.1.0"
|
|
544
552
|
},
|
|
545
553
|
devDependencies: {
|
|
546
|
-
"@babel/preset-env": "^7.
|
|
547
|
-
"@babel/preset-typescript": "^7.
|
|
548
|
-
"@jest/globals": "^29.
|
|
554
|
+
"@babel/preset-env": "^7.20.2",
|
|
555
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
556
|
+
"@jest/globals": "^29.3.1",
|
|
557
|
+
"@size-limit/preset-small-lib": "^5.0.4",
|
|
558
|
+
"@swc/core": "^1.3.22",
|
|
549
559
|
"@types/graphql": "^14.5.0",
|
|
550
|
-
"@types/jest": "^29.
|
|
551
|
-
"@types/lodash": "^4.14.
|
|
552
|
-
"@types/node": "^
|
|
553
|
-
"@types/prettier": "^2.
|
|
554
|
-
"apollo-server": "^3.
|
|
560
|
+
"@types/jest": "^29.2.4",
|
|
561
|
+
"@types/lodash": "^4.14.177",
|
|
562
|
+
"@types/node": "^16.11.12",
|
|
563
|
+
"@types/prettier": "^2.4.2",
|
|
564
|
+
"apollo-server": "^3.11.1",
|
|
565
|
+
concurrently: "^7.6.0",
|
|
555
566
|
"cross-env": "^7.0.3",
|
|
556
|
-
jest: "^29.
|
|
567
|
+
jest: "^29.3.1",
|
|
568
|
+
"ts-jest": "^29.0.3",
|
|
557
569
|
"ts-node": "^10.9.1",
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
570
|
+
tslib: "^2.3.1",
|
|
571
|
+
tsup: "^6.5.0",
|
|
572
|
+
typescript: "^4.9.4"
|
|
561
573
|
}
|
|
562
574
|
};
|
|
563
575
|
// src/generateTypescriptClient.ts
|
|
564
576
|
var tempDir = fs.realpathSync(import_os.default.tmpdir());
|
|
565
|
-
var graphqlTsClientPath = process.env.GQL_CLIENT_DIST_PATH || "graphql-ts-client/dist";
|
|
577
|
+
var graphqlTsClientPath = process.env.GQL_CLIENT_DIST_PATH || "@avantstay/graphql-ts-client/dist";
|
|
566
578
|
function gqlScalarToTypescript(gqlType) {
|
|
567
579
|
if (/(int|long|double|decimal|float)/i.test(gqlType)) return "number";
|
|
568
580
|
if (/boolean/i.test(gqlType)) return "boolean";
|
|
@@ -736,13 +748,13 @@ function getTypesTreeCode(types) {
|
|
|
736
748
|
});
|
|
737
749
|
});
|
|
738
750
|
return "\n const typesTree = {\n ".concat(Object.entries(typesTree).map(function(param) {
|
|
739
|
-
var _param =
|
|
751
|
+
var _param = _slicedToArray(param, 2), key = _param[0], value = _param[1];
|
|
740
752
|
var entryCode = Object.entries(value).map(function(param) {
|
|
741
|
-
var _param =
|
|
753
|
+
var _param = _slicedToArray(param, 2), k = _param[0], v = _param[1];
|
|
742
754
|
var cleanShapeType = v.__shape && v.__shape.replace(/[\[\]!?]/g, "");
|
|
743
755
|
var fieldsCode = v.__shape && typesTree.hasOwnProperty(cleanShapeType) ? "__fields: typesTree.".concat(cleanShapeType, ",") : "";
|
|
744
756
|
var argsCode = v.__args ? "__args: {\n ".concat(Object.entries(v.__args).map(function(param) {
|
|
745
|
-
var _param =
|
|
757
|
+
var _param = _slicedToArray(param, 2), k2 = _param[0], v2 = _param[1];
|
|
746
758
|
return "".concat(k2, ": '").concat(v2, "'");
|
|
747
759
|
}).join(",\n"), "\n }") : "";
|
|
748
760
|
return fieldsCode || argsCode ? "get ".concat(k, "() {\n return {\n ").concat(fieldsCode, "\n ").concat(argsCode, "\n }\n }") : "".concat(k, ": {}");
|
|
@@ -806,7 +818,7 @@ function generateClientCode(types, options) {
|
|
|
806
818
|
});
|
|
807
819
|
}).join("\n"), "\n \n type AllEnums = ").concat(enums.length ? enums.map(function(it) {
|
|
808
820
|
return it.name;
|
|
809
|
-
}).join(" | ") : "never", "\n \n // Args\n ").concat(
|
|
821
|
+
}).join(" | ") : "never", "\n \n // Args\n ").concat(_toConsumableArray(queries).concat(_toConsumableArray(mutations)).map(function(query) {
|
|
810
822
|
var argsType = getArgsType(query);
|
|
811
823
|
return "export interface ".concat(argsType.alias, " ").concat(argsType.type);
|
|
812
824
|
}).join("\n"), "\n\n // Input/Output Types\n ").concat(objectTypes.map(function(it) {
|
|
@@ -843,9 +855,9 @@ function fetchIntrospection(_) {
|
|
|
843
855
|
return _fetchIntrospection.apply(this, arguments);
|
|
844
856
|
}
|
|
845
857
|
function _fetchIntrospection() {
|
|
846
|
-
_fetchIntrospection =
|
|
858
|
+
_fetchIntrospection = _asyncToGenerator(function(param) {
|
|
847
859
|
var endpoint, headers, introspectionCacheFileName, introspectionCacheFilePath, loadedFromCache, types, data;
|
|
848
|
-
return
|
|
860
|
+
return __generator(this, function(_state) {
|
|
849
861
|
switch(_state.label){
|
|
850
862
|
case 0:
|
|
851
863
|
endpoint = param.endpoint, headers = param.headers;
|
|
@@ -857,7 +869,7 @@ function _fetchIntrospection() {
|
|
|
857
869
|
import_axios.default.post(endpoint, {
|
|
858
870
|
query: (0, import_graphql.getIntrospectionQuery)()
|
|
859
871
|
}, {
|
|
860
|
-
headers:
|
|
872
|
+
headers: _objectSpread({
|
|
861
873
|
"Content-Type": "application/json"
|
|
862
874
|
}, headers)
|
|
863
875
|
}).catch(function() {
|
|
@@ -898,12 +910,12 @@ function generateTypescriptClient(_param) {
|
|
|
898
910
|
return _generateTypescriptClient.apply(this, arguments);
|
|
899
911
|
}
|
|
900
912
|
function _generateTypescriptClient() {
|
|
901
|
-
_generateTypescriptClient =
|
|
913
|
+
_generateTypescriptClient = _asyncToGenerator(function(_param) {
|
|
902
914
|
var introspectionEndpoint, output, options, types, _generateClientCode, js, typings, outputDir;
|
|
903
|
-
return
|
|
915
|
+
return __generator(this, function(_state) {
|
|
904
916
|
switch(_state.label){
|
|
905
917
|
case 0:
|
|
906
|
-
introspectionEndpoint = _param.introspectionEndpoint, output = _param.output, options =
|
|
918
|
+
introspectionEndpoint = _param.introspectionEndpoint, output = _param.output, options = _objectWithoutProperties(_param, [
|
|
907
919
|
"introspectionEndpoint",
|
|
908
920
|
"output"
|
|
909
921
|
]);
|
|
@@ -915,7 +927,7 @@ function _generateTypescriptClient() {
|
|
|
915
927
|
});
|
|
916
928
|
return [
|
|
917
929
|
4,
|
|
918
|
-
fetchIntrospection(
|
|
930
|
+
fetchIntrospection(_objectSpreadProps(_objectSpread({}, options), {
|
|
919
931
|
endpoint: introspectionEndpoint || options.endpoint
|
|
920
932
|
}))
|
|
921
933
|
];
|
|
@@ -950,17 +962,17 @@ function _generateTypescriptClient() {
|
|
|
950
962
|
}
|
|
951
963
|
// src/types.ts
|
|
952
964
|
var GraphQLClientError = /*#__PURE__*/ function(Error1) {
|
|
953
|
-
_inherits(
|
|
954
|
-
var _super =
|
|
955
|
-
function
|
|
956
|
-
|
|
965
|
+
_inherits(GraphQLClientError1, Error1);
|
|
966
|
+
var _super = _createSuper(GraphQLClientError1);
|
|
967
|
+
function GraphQLClientError1(responseData) {
|
|
968
|
+
_classCallCheck(this, GraphQLClientError1);
|
|
957
969
|
var _this;
|
|
958
970
|
_this = _super.call(this);
|
|
959
971
|
_this.responseData = responseData;
|
|
960
|
-
Object.setPrototypeOf(
|
|
972
|
+
Object.setPrototypeOf(_assertThisInitialized(_this), GraphQLClientError.prototype);
|
|
961
973
|
return _this;
|
|
962
974
|
}
|
|
963
|
-
|
|
975
|
+
_createClass(GraphQLClientError1, [
|
|
964
976
|
{
|
|
965
977
|
key: "message",
|
|
966
978
|
get: function get() {
|
|
@@ -976,8 +988,8 @@ var GraphQLClientError = /*#__PURE__*/ function(Error1) {
|
|
|
976
988
|
}
|
|
977
989
|
}
|
|
978
990
|
]);
|
|
979
|
-
return
|
|
980
|
-
}(
|
|
991
|
+
return GraphQLClientError1;
|
|
992
|
+
}(_wrapNativeSuper(Error));
|
|
981
993
|
// Annotate the CommonJS export names for ESM import in node:
|
|
982
994
|
0 && (module.exports = {
|
|
983
995
|
GraphQLClientError: GraphQLClientError,
|
|
@@ -0,0 +1,69 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avantstay/graphql-ts-client",
|
|
3
|
-
"version": "10.5.
|
|
3
|
+
"version": "10.5.1",
|
|
4
4
|
"description": "GraphQL Typescript Client Generator",
|
|
5
5
|
"author": "Wellington Guimaraes",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,32 +54,37 @@
|
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@types/md5": "^2.3.2",
|
|
57
|
-
"axios": "^
|
|
58
|
-
"axios-retry": "^3.
|
|
57
|
+
"axios": "^0.24.0",
|
|
58
|
+
"axios-retry": "^3.2.4",
|
|
59
59
|
"case": "^1.6.3",
|
|
60
|
-
"esbuild": "^0.
|
|
61
|
-
"graphql": "^
|
|
60
|
+
"esbuild": "^0.13.14",
|
|
61
|
+
"graphql": "^15.6.0",
|
|
62
62
|
"lodash": "^4.17.21",
|
|
63
63
|
"md5": "^2.3.0",
|
|
64
|
-
"moize": "^6.1.
|
|
65
|
-
"prettier": "^2.
|
|
64
|
+
"moize": "^6.1.0",
|
|
65
|
+
"prettier": "^2.5.1",
|
|
66
|
+
"temp-dir": "^3.0.0",
|
|
66
67
|
"ts-essentials": "^8.1.0"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
|
-
"@babel/preset-env": "^7.
|
|
70
|
-
"@babel/preset-typescript": "^7.
|
|
71
|
-
"@jest/globals": "^29.
|
|
70
|
+
"@babel/preset-env": "^7.20.2",
|
|
71
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
72
|
+
"@jest/globals": "^29.3.1",
|
|
73
|
+
"@size-limit/preset-small-lib": "^5.0.4",
|
|
74
|
+
"@swc/core": "^1.3.22",
|
|
72
75
|
"@types/graphql": "^14.5.0",
|
|
73
|
-
"@types/jest": "^29.
|
|
74
|
-
"@types/lodash": "^4.14.
|
|
75
|
-
"@types/node": "^
|
|
76
|
-
"@types/prettier": "^2.
|
|
77
|
-
"apollo-server": "^3.
|
|
76
|
+
"@types/jest": "^29.2.4",
|
|
77
|
+
"@types/lodash": "^4.14.177",
|
|
78
|
+
"@types/node": "^16.11.12",
|
|
79
|
+
"@types/prettier": "^2.4.2",
|
|
80
|
+
"apollo-server": "^3.11.1",
|
|
81
|
+
"concurrently": "^7.6.0",
|
|
78
82
|
"cross-env": "^7.0.3",
|
|
79
|
-
"jest": "^29.
|
|
83
|
+
"jest": "^29.3.1",
|
|
84
|
+
"ts-jest": "^29.0.3",
|
|
80
85
|
"ts-node": "^10.9.1",
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
86
|
+
"tslib": "^2.3.1",
|
|
87
|
+
"tsup": "^6.5.0",
|
|
88
|
+
"typescript": "^4.9.4"
|
|
84
89
|
}
|
|
85
90
|
}
|
|
@@ -25,7 +25,7 @@ import pkg from '../package.json'
|
|
|
25
25
|
|
|
26
26
|
const tempDir = fs.realpathSync(os.tmpdir())
|
|
27
27
|
|
|
28
|
-
const graphqlTsClientPath = process.env.GQL_CLIENT_DIST_PATH || 'graphql-ts-client/dist'
|
|
28
|
+
const graphqlTsClientPath = process.env.GQL_CLIENT_DIST_PATH || '@avantstay/graphql-ts-client/dist'
|
|
29
29
|
|
|
30
30
|
function gqlScalarToTypescript(gqlType: string) {
|
|
31
31
|
if (/(int|long|double|decimal|float)/i.test(gqlType)) return 'number'
|