1 | import { __assign, __spreadArray } from "tslib";
|
2 | import { print } from "../../utilities/index.js";
|
3 | var defaultHttpOptions = {
|
4 | includeQuery: true,
|
5 | includeExtensions: false,
|
6 | preserveHeaderCase: false,
|
7 | };
|
8 | var defaultHeaders = {
|
9 |
|
10 | accept: "*/*",
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | "content-type": "application/json",
|
24 | };
|
25 | var defaultOptions = {
|
26 | method: "POST",
|
27 | };
|
28 | export var fallbackHttpConfig = {
|
29 | http: defaultHttpOptions,
|
30 | headers: defaultHeaders,
|
31 | options: defaultOptions,
|
32 | };
|
33 | export var defaultPrinter = function (ast, printer) { return printer(ast); };
|
34 | export function selectHttpOptionsAndBody(operation, fallbackConfig) {
|
35 | var configs = [];
|
36 | for (var _i = 2; _i < arguments.length; _i++) {
|
37 | configs[_i - 2] = arguments[_i];
|
38 | }
|
39 | configs.unshift(fallbackConfig);
|
40 | return selectHttpOptionsAndBodyInternal.apply(void 0, __spreadArray([operation,
|
41 | defaultPrinter], configs, false));
|
42 | }
|
43 | export function selectHttpOptionsAndBodyInternal(operation, printer) {
|
44 | var configs = [];
|
45 | for (var _i = 2; _i < arguments.length; _i++) {
|
46 | configs[_i - 2] = arguments[_i];
|
47 | }
|
48 | var options = {};
|
49 | var http = {};
|
50 | configs.forEach(function (config) {
|
51 | options = __assign(__assign(__assign({}, options), config.options), { headers: __assign(__assign({}, options.headers), config.headers) });
|
52 | if (config.credentials) {
|
53 | options.credentials = config.credentials;
|
54 | }
|
55 | http = __assign(__assign({}, http), config.http);
|
56 | });
|
57 | if (options.headers) {
|
58 | options.headers = removeDuplicateHeaders(options.headers, http.preserveHeaderCase);
|
59 | }
|
60 |
|
61 | var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
|
62 | var body = { operationName: operationName, variables: variables };
|
63 | if (http.includeExtensions)
|
64 | body.extensions = extensions;
|
65 |
|
66 | if (http.includeQuery)
|
67 | body.query = printer(query, print);
|
68 | return {
|
69 | options: options,
|
70 | body: body,
|
71 | };
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 | function removeDuplicateHeaders(headers, preserveHeaderCase) {
|
77 |
|
78 | if (!preserveHeaderCase) {
|
79 | var normalizedHeaders_1 = Object.create(null);
|
80 | Object.keys(Object(headers)).forEach(function (name) {
|
81 | normalizedHeaders_1[name.toLowerCase()] = headers[name];
|
82 | });
|
83 | return normalizedHeaders_1;
|
84 | }
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | var headerData = Object.create(null);
|
90 | Object.keys(Object(headers)).forEach(function (name) {
|
91 | headerData[name.toLowerCase()] = {
|
92 | originalName: name,
|
93 | value: headers[name],
|
94 | };
|
95 | });
|
96 | var normalizedHeaders = Object.create(null);
|
97 | Object.keys(headerData).forEach(function (name) {
|
98 | normalizedHeaders[headerData[name].originalName] = headerData[name].value;
|
99 | });
|
100 | return normalizedHeaders;
|
101 | }
|
102 |
|
\ | No newline at end of file |