1 | import { serializeFetchParameter } from "./serializeFetchParameter.js";
|
2 |
|
3 |
|
4 | export function rewriteURIForGET(chosenURI, body) {
|
5 |
|
6 |
|
7 | var queryParams = [];
|
8 | var addQueryParam = function (key, value) {
|
9 | queryParams.push("".concat(key, "=").concat(encodeURIComponent(value)));
|
10 | };
|
11 | if ("query" in body) {
|
12 | addQueryParam("query", body.query);
|
13 | }
|
14 | if (body.operationName) {
|
15 | addQueryParam("operationName", body.operationName);
|
16 | }
|
17 | if (body.variables) {
|
18 | var serializedVariables = void 0;
|
19 | try {
|
20 | serializedVariables = serializeFetchParameter(body.variables, "Variables map");
|
21 | }
|
22 | catch (parseError) {
|
23 | return { parseError: parseError };
|
24 | }
|
25 | addQueryParam("variables", serializedVariables);
|
26 | }
|
27 | if (body.extensions) {
|
28 | var serializedExtensions = void 0;
|
29 | try {
|
30 | serializedExtensions = serializeFetchParameter(body.extensions, "Extensions map");
|
31 | }
|
32 | catch (parseError) {
|
33 | return { parseError: parseError };
|
34 | }
|
35 | addQueryParam("extensions", serializedExtensions);
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | var fragment = "", preFragment = chosenURI;
|
44 | var fragmentStart = chosenURI.indexOf("#");
|
45 | if (fragmentStart !== -1) {
|
46 | fragment = chosenURI.substr(fragmentStart);
|
47 | preFragment = chosenURI.substr(0, fragmentStart);
|
48 | }
|
49 | var queryParamsPrefix = preFragment.indexOf("?") === -1 ? "?" : "&";
|
50 | var newURI = preFragment + queryParamsPrefix + queryParams.join("&") + fragment;
|
51 | return { newURI: newURI };
|
52 | }
|
53 |
|
\ | No newline at end of file |