@devticon-os/graphql-codegen-axios 0.5.3 → 0.5.5

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/lib/operation.js DELETED
@@ -1,303 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __values = (this && this.__values) || function(o) {
14
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
15
- if (m) return m.call(o);
16
- if (o && typeof o.length === "number") return {
17
- next: function () {
18
- if (o && i >= o.length) o = void 0;
19
- return { value: o && o[i++], done: !o };
20
- }
21
- };
22
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
23
- };
24
- var __read = (this && this.__read) || function (o, n) {
25
- var m = typeof Symbol === "function" && o[Symbol.iterator];
26
- if (!m) return o;
27
- var i = m.call(o), r, ar = [], e;
28
- try {
29
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
30
- }
31
- catch (error) { e = { error: error }; }
32
- finally {
33
- try {
34
- if (r && !r.done && (m = i["return"])) m.call(i);
35
- }
36
- finally { if (e) throw e.error; }
37
- }
38
- return ar;
39
- };
40
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
41
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
42
- if (ar || !(i in from)) {
43
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
44
- ar[i] = from[i];
45
- }
46
- }
47
- return to.concat(ar || Array.prototype.slice.call(from));
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.findUsageOperation = exports.pluginDirectives = exports.pluginDirectivesOptions = void 0;
51
- var kinds_1 = require("graphql/language/kinds");
52
- var ast_1 = require("graphql/language/ast");
53
- var utils_1 = require("./utils");
54
- var graphql_1 = require("./graphql");
55
- var type_1 = require("graphql/type");
56
- var fragments_1 = require("./fragments");
57
- exports.pluginDirectivesOptions = [
58
- {
59
- name: 'firstOrFail',
60
- on: ['FIELD'],
61
- },
62
- {
63
- name: 'first',
64
- on: ['FIELD'],
65
- },
66
- {
67
- name: 'singleResult',
68
- on: ['FIELD'],
69
- },
70
- {
71
- name: 'required',
72
- on: ['FIELD'],
73
- },
74
- {
75
- name: 'type',
76
- args: [{ name: 't', type: 'String!' }],
77
- on: ['FIELD'],
78
- },
79
- {
80
- name: 'jsonSchema',
81
- on: ['FIELD', 'FRAGMENT_DEFINITION'],
82
- },
83
- ];
84
- exports.pluginDirectives = exports.pluginDirectivesOptions.map(function (p) { return p.name; });
85
- var findUsageOperation = function (documents, schema, config) {
86
- var e_1, _a, e_2, _b;
87
- var _c;
88
- var allFragments = (0, fragments_1.findUsageFragments)(documents);
89
- var operations = [];
90
- try {
91
- for (var documents_1 = __values(documents), documents_1_1 = documents_1.next(); !documents_1_1.done; documents_1_1 = documents_1.next()) {
92
- var document_1 = documents_1_1.value.document;
93
- try {
94
- for (var _d = (e_2 = void 0, __values(document_1.definitions)), _e = _d.next(); !_e.done; _e = _d.next()) {
95
- var definition = _e.value;
96
- if (definition.kind === kinds_1.Kind.OPERATION_DEFINITION) {
97
- var name_1 = definition.name.value;
98
- var root = void 0;
99
- if (definition.operation === ast_1.OperationTypeNode.QUERY) {
100
- root = schema.getQueryType();
101
- }
102
- else if (definition.operation === ast_1.OperationTypeNode.MUTATION) {
103
- root = schema.getMutationType();
104
- }
105
- else if (definition.operation === ast_1.OperationTypeNode.SUBSCRIPTION) {
106
- throw new Error('subscription operation is not supported');
107
- }
108
- var directives = findDirectives(definition.selectionSet.selections, allFragments);
109
- if (config.autoSingleResult !== false &&
110
- definition.selectionSet.selections.length === 1 &&
111
- !directives.some(function (d) { return d.name === 'singleResult'; })) {
112
- var fields = definition.selectionSet.selections.filter(function (f) { return f.kind === kinds_1.Kind.FIELD; });
113
- directives.push({
114
- name: 'singleResult',
115
- path: ((_c = fields[0].alias) === null || _c === void 0 ? void 0 : _c.value) || fields[0].name.value,
116
- args: {},
117
- });
118
- }
119
- var resultsType = __assign({ name: (0, utils_1.capitalize)(name_1) + 'Results', kind: 'object', unions: [], isNullable: false, isList: false }, (0, graphql_1.selectionSetToTsType)(root, definition.selectionSet.selections, config));
120
- var singleResult = directives.find(function (d) { return d.name === 'singleResult'; });
121
- if (singleResult) {
122
- var type = getNestedType(resultsType, singleResult.path);
123
- resultsType = __assign(__assign({}, type), { name: resultsType.name });
124
- }
125
- var variableFields = definition.variableDefinitions.map(function (variableDefinition) {
126
- var type = parseVariableNode(variableDefinition.type, schema);
127
- return __assign(__assign({ name: variableDefinition.variable.name.value, kind: 'inLine', type: (0, graphql_1.graphqlTypeToTypescript)(type, config) }, (0, graphql_1.getGraphqlTypeWrappers)(type)), { unionListAndObject: true });
128
- });
129
- operations.push({
130
- name: name_1,
131
- definition: definition,
132
- directives: directives,
133
- singleResultKey: singleResult ? singleResult.path : '',
134
- variables: definition.variableDefinitions.length
135
- ? {
136
- kind: 'object',
137
- name: (0, utils_1.capitalize)(name_1) + 'Variables',
138
- fields: variableFields,
139
- unions: [],
140
- isList: false,
141
- isNullable: variableFields.filter(function (f) { return f.isNullable; }).length === variableFields.length,
142
- }
143
- : undefined,
144
- results: resultsType,
145
- fragments: findFragmentsUsedInSelection(definition.selectionSet.selections, allFragments),
146
- });
147
- }
148
- }
149
- }
150
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
151
- finally {
152
- try {
153
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
154
- }
155
- finally { if (e_2) throw e_2.error; }
156
- }
157
- }
158
- }
159
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
160
- finally {
161
- try {
162
- if (documents_1_1 && !documents_1_1.done && (_a = documents_1.return)) _a.call(documents_1);
163
- }
164
- finally { if (e_1) throw e_1.error; }
165
- }
166
- return operations;
167
- };
168
- exports.findUsageOperation = findUsageOperation;
169
- var findDirectives = function (selections, fragments, key) {
170
- var e_3, _a;
171
- var _b, _c;
172
- if (key === void 0) { key = ''; }
173
- var directives = [];
174
- var _loop_1 = function (selection) {
175
- var e_4, _d;
176
- if (selection.kind === kinds_1.Kind.FRAGMENT_SPREAD) {
177
- var fragmentName_1 = selection.name.value;
178
- var fragment = fragments.find(function (f) { return f.name.value === fragmentName_1; });
179
- if (!fragment) {
180
- throw new Error("Cannot find fragment: ".concat(fragmentName_1));
181
- }
182
- directives.push.apply(directives, __spreadArray([], __read(findDirectives(fragment.selectionSet.selections, fragments, key)), false));
183
- }
184
- if (selection.kind === kinds_1.Kind.FIELD) {
185
- var path = key + (((_b = selection.alias) === null || _b === void 0 ? void 0 : _b.value) || selection.name.value);
186
- try {
187
- for (var _e = (e_4 = void 0, __values(selection.directives)), _f = _e.next(); !_f.done; _f = _e.next()) {
188
- var directive = _f.value;
189
- if (exports.pluginDirectives.includes(directive.name.value)) {
190
- directives.push({
191
- name: directive.name.value,
192
- path: path,
193
- args: directive.arguments.reduce(function (args, arg) {
194
- if ('value' in arg.value) {
195
- args[arg.name.value] = arg.value.value;
196
- }
197
- return args;
198
- }, {}),
199
- });
200
- }
201
- }
202
- }
203
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
204
- finally {
205
- try {
206
- if (_f && !_f.done && (_d = _e.return)) _d.call(_e);
207
- }
208
- finally { if (e_4) throw e_4.error; }
209
- }
210
- if ((_c = selection.selectionSet) === null || _c === void 0 ? void 0 : _c.selections.length) {
211
- directives.push.apply(directives, __spreadArray([], __read(findDirectives(selection.selectionSet.selections, fragments, path + '.')), false));
212
- }
213
- }
214
- };
215
- try {
216
- for (var selections_1 = __values(selections), selections_1_1 = selections_1.next(); !selections_1_1.done; selections_1_1 = selections_1.next()) {
217
- var selection = selections_1_1.value;
218
- _loop_1(selection);
219
- }
220
- }
221
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
222
- finally {
223
- try {
224
- if (selections_1_1 && !selections_1_1.done && (_a = selections_1.return)) _a.call(selections_1);
225
- }
226
- finally { if (e_3) throw e_3.error; }
227
- }
228
- return directives;
229
- };
230
- var getNestedType = function (type, path) {
231
- var e_5, _a;
232
- var t = type;
233
- var _loop_2 = function (key) {
234
- var field = t.fields.find(function (f) { return f.name === key; });
235
- if (!field) {
236
- throw new Error("cannot find field ".concat(key));
237
- }
238
- t = field;
239
- };
240
- try {
241
- for (var _b = __values(path.split('.')), _c = _b.next(); !_c.done; _c = _b.next()) {
242
- var key = _c.value;
243
- _loop_2(key);
244
- }
245
- }
246
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
247
- finally {
248
- try {
249
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
250
- }
251
- finally { if (e_5) throw e_5.error; }
252
- }
253
- return t;
254
- };
255
- var parseVariableNode = function (type, schema, isNullable, isList) {
256
- if (isNullable === void 0) { isNullable = true; }
257
- if (isList === void 0) { isList = false; }
258
- if (type.kind === kinds_1.Kind.LIST_TYPE) {
259
- return parseVariableNode(type.type, schema, isNullable, true);
260
- }
261
- if (type.kind === kinds_1.Kind.NON_NULL_TYPE) {
262
- return parseVariableNode(type.type, schema, false, isList);
263
- }
264
- var gqlType = schema.getType(type.name.value);
265
- if (!isNullable) {
266
- gqlType = new type_1.GraphQLNonNull(gqlType);
267
- }
268
- if (isList) {
269
- gqlType = new type_1.GraphQLList(gqlType);
270
- }
271
- return gqlType;
272
- };
273
- var findFragmentsUsedInSelection = function (selections, allFragments, fragments) {
274
- var e_6, _a;
275
- var _b;
276
- if (fragments === void 0) { fragments = new Set(); }
277
- var _loop_3 = function (selection) {
278
- if (selection.kind === kinds_1.Kind.FRAGMENT_SPREAD) {
279
- var name_2 = selection.name.value;
280
- var fragment = allFragments.find(function (f) { return f.name.value === name_2; });
281
- fragments.add(name_2);
282
- findFragmentsUsedInSelection(fragment.selectionSet.selections, allFragments, fragments);
283
- }
284
- if (selection.kind === kinds_1.Kind.FIELD && ((_b = selection.selectionSet) === null || _b === void 0 ? void 0 : _b.selections.length)) {
285
- findFragmentsUsedInSelection(selection.selectionSet.selections, allFragments, fragments);
286
- }
287
- };
288
- try {
289
- for (var selections_2 = __values(selections), selections_2_1 = selections_2.next(); !selections_2_1.done; selections_2_1 = selections_2.next()) {
290
- var selection = selections_2_1.value;
291
- _loop_3(selection);
292
- }
293
- }
294
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
295
- finally {
296
- try {
297
- if (selections_2_1 && !selections_2_1.done && (_a = selections_2.return)) _a.call(selections_2);
298
- }
299
- finally { if (e_6) throw e_6.error; }
300
- }
301
- return __spreadArray([], __read(fragments), false);
302
- };
303
- //# sourceMappingURL=operation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../src/operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,gDAA8C;AAC9C,4CAAqH;AACrH,iCAAqC;AACrC,qCAAkG;AAClG,qCAA6F;AAE7F,yCAAiD;AACpC,QAAA,uBAAuB,GAA8E;IAChH;QACE,IAAI,EAAE,aAAa;QACnB,EAAE,EAAE,CAAC,OAAO,CAAC;KACd;IACD;QACE,IAAI,EAAE,OAAO;QACb,EAAE,EAAE,CAAC,OAAO,CAAC;KACd;IACD;QACE,IAAI,EAAE,cAAc;QACpB,EAAE,EAAE,CAAC,OAAO,CAAC;KACd;IACD;QACE,IAAI,EAAE,UAAU;QAChB,EAAE,EAAE,CAAC,OAAO,CAAC;KACd;IACD;QACE,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACtC,EAAE,EAAE,CAAC,OAAO,CAAC;KACd;IACD;QACE,IAAI,EAAE,YAAY;QAClB,EAAE,EAAE,CAAC,OAA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C,UAAU,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;SAC1F;;;QATH,KAAsB,IAAA,eAAA,SAAA,UAAU,CAAA,sCAAA;YAA3B,IAAI,SAAS,uBAAA;oBAAT,SAAS;SAUjB;;;;;;;;;IAED,gCAAW,SAAS,UAAE;AACxB,CAAC,CAAC"}
package/lib/prettier.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runPrettierIfExists = void 0;
4
- var runPrettierIfExists = function (config, content) {
5
- if (config.prettier === false) {
6
- return content;
7
- }
8
- try {
9
- var prettier = require('prettier');
10
- return prettier.format(content, { parser: 'typescript' });
11
- }
12
- catch (e) {
13
- return content;
14
- }
15
- };
16
- exports.runPrettierIfExists = runPrettierIfExists;
17
- //# sourceMappingURL=prettier.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prettier.js","sourceRoot":"","sources":["../src/prettier.ts"],"names":[],"mappings":";;;AAEO,IAAM,mBAAmB,GAAG,UAAC,MAAc,EAAE,OAAe;IACjE,IAAI,MAAM,CAAC,QAAQ,KAAK,KAAK,EAAE;QAC7B,OAAO,OAAO,CAAC;KAChB;IACD,IAAI;QACF,IAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QACrC,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;KAC3D;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,OAAO,CAAC;KAChB;AACH,CAAC,CAAC;AAVW,QAAA,mBAAmB,uBAU9B"}
package/lib/print.js DELETED
@@ -1,314 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __values = (this && this.__values) || function(o) {
14
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
15
- if (m) return m.call(o);
16
- if (o && typeof o.length === "number") return {
17
- next: function () {
18
- if (o && i >= o.length) o = void 0;
19
- return { value: o && o[i++], done: !o };
20
- }
21
- };
22
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
23
- };
24
- var __read = (this && this.__read) || function (o, n) {
25
- var m = typeof Symbol === "function" && o[Symbol.iterator];
26
- if (!m) return o;
27
- var i = m.call(o), r, ar = [], e;
28
- try {
29
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
30
- }
31
- catch (error) { e = { error: error }; }
32
- finally {
33
- try {
34
- if (r && !r.done && (m = i["return"])) m.call(i);
35
- }
36
- finally { if (e) throw e.error; }
37
- }
38
- return ar;
39
- };
40
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
41
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
42
- if (ar || !(i in from)) {
43
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
44
- ar[i] = from[i];
45
- }
46
- }
47
- return to.concat(ar || Array.prototype.slice.call(from));
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.printTsTypeVariable = exports.printScalars = exports.printIgnores = exports.printNullable = exports.printHelpers = exports.printInput = exports.printFragmentGql = exports.printObjectType = exports.printFragmentType = exports.printEnum = exports.printCreateSdkFunction = exports.printFragmentJsonSchema = exports.printOperationResultsJsonSchema = exports.directivesToFunctions = exports.printOperationTypes = void 0;
51
- var type_1 = require("graphql/type");
52
- var language_1 = require("graphql/language");
53
- var graphql_1 = require("./graphql");
54
- var fs = require("fs");
55
- var path = require("path");
56
- var operation_1 = require("./operation");
57
- var utils_1 = require("./utils");
58
- var definition_1 = require("graphql/type/definition");
59
- var printOperationTypes = function (operation, config) {
60
- var e_1, _a;
61
- var content = [];
62
- if (operation.variables) {
63
- content.push((0, exports.printTsTypeVariable)(operation.variables));
64
- }
65
- content.push((0, exports.printTsTypeVariable)(operation.results));
66
- var queryFragments = operation.fragments.map(function (fragment) { return "${".concat(fragment, "FragmentQuery}\n"); });
67
- var query = (0, language_1.print)(operation.definition);
68
- try {
69
- for (var pluginDirectives_1 = __values(operation_1.pluginDirectives), pluginDirectives_1_1 = pluginDirectives_1.next(); !pluginDirectives_1_1.done; pluginDirectives_1_1 = pluginDirectives_1.next()) {
70
- var pluginDirective = pluginDirectives_1_1.value;
71
- query = query.replace(new RegExp('@' + pluginDirective + '(\\(.*?\\))?', 'g'), '');
72
- }
73
- }
74
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
75
- finally {
76
- try {
77
- if (pluginDirectives_1_1 && !pluginDirectives_1_1.done && (_a = pluginDirectives_1.return)) _a.call(pluginDirectives_1);
78
- }
79
- finally { if (e_1) throw e_1.error; }
80
- }
81
- content.push("const ".concat(getOperationQueryName(operation.name), " = `").concat(queryFragments.join('')).concat(query, "`;"));
82
- return content.join('\n');
83
- };
84
- exports.printOperationTypes = printOperationTypes;
85
- var directivesToFunctions = function (directives) {
86
- var e_2, _a;
87
- var functions = [];
88
- directives.sort(function (a, b) { return (a.path.length < b.path.length ? 1 : b.path.length < a.path.length ? -1 : 0); });
89
- try {
90
- for (var directives_1 = __values(directives), directives_1_1 = directives_1.next(); !directives_1_1.done; directives_1_1 = directives_1.next()) {
91
- var directive = directives_1_1.value;
92
- switch (directive.name) {
93
- case 'first':
94
- case 'firstOrFail':
95
- case 'required':
96
- functions.push("".concat(directive.name, "(\"").concat(directive.path, "\")"));
97
- break;
98
- }
99
- }
100
- }
101
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
102
- finally {
103
- try {
104
- if (directives_1_1 && !directives_1_1.done && (_a = directives_1.return)) _a.call(directives_1);
105
- }
106
- finally { if (e_2) throw e_2.error; }
107
- }
108
- return functions;
109
- };
110
- exports.directivesToFunctions = directivesToFunctions;
111
- var printOperationResultsJsonSchema = function (operations, config) {
112
- operations = operations.filter(function (o) { return o.directives.some(function (d) { return d.name === 'jsonSchema'; }); });
113
- return operations
114
- .filter(function (o) { return o.directives.some(function (d) { return d.name === 'jsonSchema'; }); })
115
- .map(function (o) { return "export const ".concat(o.name, "JsonSchema = ").concat(JSON.stringify(tsTypeToJsonSchema(o.results, config), null, 2)); });
116
- };
117
- exports.printOperationResultsJsonSchema = printOperationResultsJsonSchema;
118
- var printFragmentJsonSchema = function (fragments, schema, config) {
119
- var _a;
120
- var suffix = ((_a = config === null || config === void 0 ? void 0 : config.suffix) === null || _a === void 0 ? void 0 : _a.fragment) || '';
121
- return fragments
122
- .filter(function (f) { return f.directives.some(function (d) { return d.name.value === 'jsonSchema'; }); })
123
- .map(function (fragment) {
124
- var parent = (0, type_1.assertObjectType)(schema.getType(fragment.typeCondition.name.value));
125
- return __assign({ name: fragment.name.value + suffix, kind: 'object', isList: false, isNullable: false }, (0, graphql_1.selectionSetToTsType)(parent, fragment.selectionSet.selections, config));
126
- })
127
- .map(function (o) { return "export const ".concat(o.name, "JsonSchema = ").concat(JSON.stringify(tsTypeToJsonSchema(o, config), null, 2)); });
128
- };
129
- exports.printFragmentJsonSchema = printFragmentJsonSchema;
130
- var tsTypeToJsonSchema = function (tsType, config) {
131
- if (tsType.kind === 'object') {
132
- return {
133
- type: 'object',
134
- properties: tsType.fields.reduce(function (p, f) {
135
- p[f.name] = tsTypeToJsonSchema(f, config);
136
- return p;
137
- }, {}),
138
- };
139
- }
140
- if (tsType.isList) {
141
- return {
142
- type: 'array',
143
- items: tsTypeToJsonSchema(__assign(__assign({}, tsType), { isList: false }), config),
144
- };
145
- }
146
- return {
147
- type: gqlScalarTypeToJsonSchemaType(tsType.type, config),
148
- };
149
- };
150
- var gqlScalarTypeToJsonSchemaType = function (type, config) {
151
- console.log(type);
152
- switch (type) {
153
- case 'Scalar["String"]':
154
- return 'string';
155
- case 'Scalar["Int"]':
156
- return 'integer';
157
- case 'Scalar["Float"]':
158
- return 'number';
159
- case 'Scalar["Boolean"]':
160
- return 'boolean';
161
- }
162
- return 'string';
163
- };
164
- var printCreateSdkFunction = function (operations, config) {
165
- var fields = operations
166
- .map(function (operation) {
167
- var hasVariables = !!operation.variables;
168
- var functions = (0, exports.directivesToFunctions)(operation.directives);
169
- if (operation.singleResultKey) {
170
- functions.push("singleResult(\"".concat(operation.singleResultKey, "\")"));
171
- }
172
- var defArgs = [];
173
- var execArgs = ['client'];
174
- if (hasVariables) {
175
- defArgs.push("variables".concat(operation.variables.isNullable ? '?' : '', ": ").concat(operation.variables.name));
176
- execArgs.push("{variables, query: ".concat(getOperationQueryName(operation.name), "}"));
177
- }
178
- else {
179
- execArgs.push("{query: ".concat(getOperationQueryName(operation.name), "}"));
180
- }
181
- execArgs.push("[".concat(functions.join(','), "]"));
182
- execArgs.push('config');
183
- defArgs.push("config?: AxiosRequestConfig");
184
- return "".concat(operation.name, ": (").concat(defArgs.join(','), "): Promise<").concat(operation.results.name, "> => execute(").concat(execArgs.join(','), ")");
185
- })
186
- .join(',');
187
- return "export const createSdk = (client: AxiosInstance) => ({".concat(fields, "});");
188
- };
189
- exports.printCreateSdkFunction = printCreateSdkFunction;
190
- var printEnum = function (e, config) {
191
- var _a;
192
- var suffix = ((_a = config === null || config === void 0 ? void 0 : config.suffix) === null || _a === void 0 ? void 0 : _a.enum) || '';
193
- var values = e.getValues().map(function (_a) {
194
- var name = _a.name, value = _a.value;
195
- return "".concat((0, utils_1.capitalize)(name.toLowerCase()), " = \"").concat(value, "\"");
196
- });
197
- return "export enum ".concat(e.name + suffix, " {").concat(values.join(','), "};");
198
- };
199
- exports.printEnum = printEnum;
200
- var printFragmentType = function (fragment, schema, config) {
201
- var _a;
202
- var suffix = ((_a = config === null || config === void 0 ? void 0 : config.suffix) === null || _a === void 0 ? void 0 : _a.fragment) || '';
203
- var parent = (0, type_1.assertObjectType)(schema.getType(fragment.typeCondition.name.value));
204
- return (0, exports.printTsTypeVariable)(__assign({ name: fragment.name.value + suffix, kind: 'object', isList: false, isNullable: false }, (0, graphql_1.selectionSetToTsType)(parent, fragment.selectionSet.selections, config)));
205
- };
206
- exports.printFragmentType = printFragmentType;
207
- var printObjectType = function (object, config) {
208
- return (0, exports.printTsTypeVariable)({
209
- kind: 'object',
210
- name: (0, utils_1.capitalize)(object.name),
211
- fields: Object.values((0, type_1.assertObjectType)((0, definition_1.getNamedType)(object)).getFields()).map(function (field) { return (__assign({ name: field.name, kind: 'inLine', type: (0, graphql_1.graphqlTypeToTypescript)(field.type, config) }, (0, graphql_1.getGraphqlTypeWrappers)(field.type))); }),
212
- isList: false,
213
- isNullable: false,
214
- });
215
- };
216
- exports.printObjectType = printObjectType;
217
- var printFragmentGql = function (fragment) {
218
- var e_3, _a;
219
- var query = (0, language_1.print)(fragment);
220
- try {
221
- for (var pluginDirectives_2 = __values(operation_1.pluginDirectives), pluginDirectives_2_1 = pluginDirectives_2.next(); !pluginDirectives_2_1.done; pluginDirectives_2_1 = pluginDirectives_2.next()) {
222
- var pluginDirective = pluginDirectives_2_1.value;
223
- query = query.replace(new RegExp('@' + pluginDirective, 'g'), '');
224
- }
225
- }
226
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
227
- finally {
228
- try {
229
- if (pluginDirectives_2_1 && !pluginDirectives_2_1.done && (_a = pluginDirectives_2.return)) _a.call(pluginDirectives_2);
230
- }
231
- finally { if (e_3) throw e_3.error; }
232
- }
233
- return "const ".concat(fragment.name.value, "FragmentQuery = `").concat(query, "`");
234
- };
235
- exports.printFragmentGql = printFragmentGql;
236
- var printInput = function (input, config, unionListAndObject) {
237
- var _a;
238
- if (unionListAndObject === void 0) { unionListAndObject = false; }
239
- var suffix = ((_a = config === null || config === void 0 ? void 0 : config.suffix) === null || _a === void 0 ? void 0 : _a.input) || '';
240
- return (0, exports.printTsTypeVariable)({
241
- kind: 'object',
242
- name: input.name + suffix,
243
- fields: Object.values(input.getFields()).map(function (field) { return (__assign(__assign({ name: field.name, kind: 'inLine', type: (0, graphql_1.graphqlTypeToTypescript)(field.type, config) }, (0, graphql_1.getGraphqlTypeWrappers)(field.type)), { unionListAndObject: unionListAndObject })); }),
244
- isNullable: false,
245
- isList: false,
246
- });
247
- };
248
- exports.printInput = printInput;
249
- var printHelpers = function (config) {
250
- return fs.readFileSync(path.resolve(__dirname, '../templates/helpers.ts'), 'utf8');
251
- };
252
- exports.printHelpers = printHelpers;
253
- var printNullable = function (config) {
254
- return "type Nullable<T> = ".concat(config.nullableValue ? config.nullableValue : 'T | null', ";\n");
255
- };
256
- exports.printNullable = printNullable;
257
- var printIgnores = function (config) {
258
- return "// @ts-nocheck\n/* tslint:disable */\n";
259
- };
260
- exports.printIgnores = printIgnores;
261
- var printScalars = function (scalars, config) {
262
- var e_4, _a;
263
- var map = __assign({ String: 'string', Int: 'number', Float: 'number', Boolean: 'boolean' }, (config.scalars || {}));
264
- try {
265
- for (var scalars_1 = __values(scalars), scalars_1_1 = scalars_1.next(); !scalars_1_1.done; scalars_1_1 = scalars_1.next()) {
266
- var scalar = scalars_1_1.value;
267
- if (!map[scalar.name]) {
268
- map[scalar.name] = 'any';
269
- }
270
- }
271
- }
272
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
273
- finally {
274
- try {
275
- if (scalars_1_1 && !scalars_1_1.done && (_a = scalars_1.return)) _a.call(scalars_1);
276
- }
277
- finally { if (e_4) throw e_4.error; }
278
- }
279
- return "export type Scalar = {".concat(Object.entries(map).map(function (_a) {
280
- var _b = __read(_a, 2), name = _b[0], value = _b[1];
281
- return "".concat(name, ": ").concat(value);
282
- }), "};");
283
- };
284
- exports.printScalars = printScalars;
285
- var printTsType = function (type) {
286
- var _a;
287
- var ts;
288
- if (type.kind === 'object') {
289
- ts = type.fields.map(function (field) { return "".concat(field.name).concat(field.isNullable ? '?' : '', ": ").concat(printTsType(field)); }).join(',');
290
- ts = "{".concat(ts, "}");
291
- }
292
- else {
293
- ts = type.type;
294
- }
295
- if ((_a = type.unions) === null || _a === void 0 ? void 0 : _a.length) {
296
- ts = '(' + __spreadArray(__spreadArray([], __read(type.unions), false), [ts], false).join(' & ') + ')';
297
- }
298
- if (type.isList) {
299
- ts += '[]';
300
- }
301
- if (type.isNullable) {
302
- ts = "Nullable<".concat(ts, ">");
303
- }
304
- if (type.isList && type.unionListAndObject) {
305
- ts = "(".concat(ts, " | ").concat(printTsType(__assign(__assign({}, type), { unionListAndObject: false, isList: false })), ")");
306
- }
307
- return ts;
308
- };
309
- var printTsTypeVariable = function (type) {
310
- return "export type ".concat(type.name, " = ").concat(printTsType(type), ";");
311
- };
312
- exports.printTsTypeVariable = printTsTypeVariable;
313
- var getOperationQueryName = function (name) { return "".concat(name, "Query"); };
314
- //# sourceMappingURL=print.js.map