@avantstay/graphql-ts-client 10.5.0 → 10.6.0-rc.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.js +97 -90
- package/dist/index.d.ts +5 -3
- package/dist/index.js +154 -124
- package/package.json +28 -21
- package/src/__snapshots__/generateTypescriptClient.test.ts.snap +133 -0
- package/src/__testClient.d.ts +1 -1
- package/src/__testClient.js +16 -24
- package/src/generateTypescriptClient.test.ts +10 -1
- package/src/generateTypescriptClient.ts +31 -10
- package/src/index.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.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
|
@@ -14,9 +14,11 @@ type IClientOptions = {
|
|
|
14
14
|
skipCache?: boolean;
|
|
15
15
|
errorsParser?: (errors: any[]) => any;
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
type Client = {
|
|
18
18
|
typings: string;
|
|
19
19
|
js: string;
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
|
+
declare function generateTypescriptClient({ introspectionEndpoint, ...options }: IClientOptions): Promise<Client>;
|
|
22
|
+
declare function generateTypescriptClientFromSDL(SDL: string, options: IClientOptions): Client;
|
|
21
23
|
|
|
22
|
-
export { generateTypescriptClient };
|
|
24
|
+
export { generateTypescriptClient, generateTypescriptClientFromSDL };
|