@hyper-fetch/graphql 7.5.3 → 8.0.0
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/{.eslintrc.json → .eslintrc copy.json } +1 -1
- package/.eslintrc.cjs +12 -0
- package/__tests__/e2e/e2e.graphql-server.ts +135 -0
- package/__tests__/e2e/e2e.graphql.spec.ts +486 -0
- package/__tests__/features/adapter/adapter.browser.spec.ts +110 -20
- package/__tests__/features/adapter/adapter.server.spec.ts +20 -27
- package/__tests__/features/adapter/adapter.utils.spec.ts +36 -3
- package/__tests__/request-module.d.ts +12 -0
- package/__tests__/shared/callbacks.shared.ts +3 -1
- package/__tests__/shared/progress.shared.ts +2 -1
- package/__tests__/tsconfig.json +13 -3
- package/__tests__/vitest.setup.ts +10 -0
- package/dist/adapter/adapter.constants.d.ts +4 -0
- package/dist/adapter/adapter.constants.d.ts.map +1 -0
- package/dist/adapter/adapter.d.ts +3 -0
- package/dist/adapter/adapter.d.ts.map +1 -0
- package/dist/adapter/adapter.types.d.ts +24 -0
- package/dist/adapter/adapter.types.d.ts.map +1 -0
- package/dist/adapter/adapter.utils.d.ts +9 -0
- package/dist/adapter/adapter.utils.d.ts.map +1 -0
- package/dist/adapter/http-adapter.fetch.d.ts +3 -0
- package/dist/adapter/http-adapter.fetch.d.ts.map +1 -0
- package/dist/adapter/index.d.ts +6 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/index.d.ts +2 -34
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +183 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +10 -25
- package/src/adapter/adapter.constants.ts +1 -1
- package/src/adapter/adapter.ts +3 -8
- package/src/adapter/adapter.types.ts +7 -3
- package/src/adapter/adapter.utils.ts +8 -3
- package/src/adapter/http-adapter.fetch.ts +186 -0
- package/src/adapter/index.ts +1 -0
- package/tsconfig.base.json +2 -6
- package/tsconfig.json +2 -6
- package/vite.config.ts +45 -0
- package/__tests__/global.d.ts +0 -1
- package/__tests__/jest.setup.ts +0 -1
- package/dist/browser/index.js +0 -191
- package/dist/browser/index.js.map +0 -7
- package/dist/index.js +0 -330
- package/dist/index.js.map +0 -7
- package/jest.config.ts +0 -6
- package/src/adapter/http-adapter.browser.ts +0 -148
- package/src/adapter/http-adapter.server.ts +0 -148
|
@@ -2,8 +2,10 @@ import { Client, getErrorMessage } from "@hyper-fetch/core";
|
|
|
2
2
|
import { createGraphqlMockingServer } from "@hyper-fetch/testing";
|
|
3
3
|
|
|
4
4
|
import { GraphqlAdapter } from "adapter";
|
|
5
|
-
import { GetUserQueryResponse
|
|
6
|
-
import {
|
|
5
|
+
import type { GetUserQueryResponse } from "../../constants/queries.constants";
|
|
6
|
+
import { getUserQuery, getUserQueryString } from "../../constants/queries.constants";
|
|
7
|
+
import type { LoginMutationVariables } from "../../constants/mutations.constants";
|
|
8
|
+
import { loginMutation } from "../../constants/mutations.constants";
|
|
7
9
|
|
|
8
10
|
const { startServer, stopServer, resetMocks, mockRequest } = createGraphqlMockingServer();
|
|
9
11
|
|
|
@@ -26,7 +28,7 @@ describe("Graphql Adapter [ Browser ]", () => {
|
|
|
26
28
|
});
|
|
27
29
|
|
|
28
30
|
resetMocks();
|
|
29
|
-
|
|
31
|
+
vi.resetAllMocks();
|
|
30
32
|
});
|
|
31
33
|
|
|
32
34
|
afterAll(() => {
|
|
@@ -130,25 +132,15 @@ describe("Graphql Adapter [ Browser ]", () => {
|
|
|
130
132
|
// window.XMLHttpRequest = xml;
|
|
131
133
|
// });
|
|
132
134
|
|
|
133
|
-
it("should allow to set options", async () => {
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
class ExtendedXml extends XMLHttpRequest {
|
|
137
|
-
constructor() {
|
|
138
|
-
super();
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
140
|
-
instance = this;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
135
|
+
it("should allow to set options and timeout the request", async () => {
|
|
136
|
+
const timeoutRequest = request.setOptions({ timeout: 5 });
|
|
137
|
+
mockRequest(timeoutRequest, { delay: 500 });
|
|
143
138
|
|
|
144
|
-
|
|
139
|
+
const { data, error, status } = await timeoutRequest.send();
|
|
145
140
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
expect(instance!.timeout).toBe(50);
|
|
150
|
-
|
|
151
|
-
window.XMLHttpRequest = xml;
|
|
141
|
+
expect(data).toBeNull();
|
|
142
|
+
expect(status).toBe(0);
|
|
143
|
+
expect(error).toStrictEqual(getErrorMessage("timeout"));
|
|
152
144
|
});
|
|
153
145
|
|
|
154
146
|
it("should handle undefined response data as null", async () => {
|
|
@@ -166,4 +158,102 @@ describe("Graphql Adapter [ Browser ]", () => {
|
|
|
166
158
|
const { error } = await request.send();
|
|
167
159
|
expect(error).toStrictEqual([getErrorMessage()]);
|
|
168
160
|
});
|
|
161
|
+
|
|
162
|
+
it("should fallback to response.text() when body.getReader is not available", async () => {
|
|
163
|
+
const responseData = JSON.stringify({ data: { username: "prc", firstName: "Maciej" } });
|
|
164
|
+
const originalFetch = global.fetch;
|
|
165
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
166
|
+
ok: true,
|
|
167
|
+
status: 200,
|
|
168
|
+
headers: new Headers({ "content-type": "application/json" }),
|
|
169
|
+
body: null,
|
|
170
|
+
text: () => Promise.resolve(responseData),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const { data, status, error } = await request.send();
|
|
174
|
+
|
|
175
|
+
expect(status).toBe(200);
|
|
176
|
+
expect(data).toStrictEqual({ username: "prc", firstName: "Maciej" });
|
|
177
|
+
expect(error).toBe(null);
|
|
178
|
+
|
|
179
|
+
global.fetch = originalFetch;
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("should handle network error in catch block when not aborted", async () => {
|
|
183
|
+
const originalFetch = global.fetch;
|
|
184
|
+
const networkError = new Error("Network failure");
|
|
185
|
+
global.fetch = vi.fn().mockRejectedValue(networkError);
|
|
186
|
+
|
|
187
|
+
const { data, error, status } = await request.send();
|
|
188
|
+
|
|
189
|
+
expect(data).toBeNull();
|
|
190
|
+
expect(status).toBe(0);
|
|
191
|
+
expect(error).toBe(networkError);
|
|
192
|
+
|
|
193
|
+
global.fetch = originalFetch;
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("should handle request with abort controller present", async () => {
|
|
197
|
+
mockRequest(request, { data: { username: "prc", firstName: "Maciej" } });
|
|
198
|
+
|
|
199
|
+
const { data, status, error } = await request.send();
|
|
200
|
+
|
|
201
|
+
expect(status).toBe(200);
|
|
202
|
+
expect(data).toStrictEqual({ username: "prc", firstName: "Maciej" });
|
|
203
|
+
expect(error).toBe(null);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("should handle response with content-length header for progress tracking", async () => {
|
|
207
|
+
const responseData = JSON.stringify({ data: { username: "prc", firstName: "Maciej" } });
|
|
208
|
+
const encoder = new TextEncoder();
|
|
209
|
+
const encoded = encoder.encode(responseData);
|
|
210
|
+
const originalFetch = global.fetch;
|
|
211
|
+
|
|
212
|
+
let readerDone = false;
|
|
213
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
214
|
+
ok: true,
|
|
215
|
+
status: 200,
|
|
216
|
+
headers: new Headers({
|
|
217
|
+
"content-type": "application/json",
|
|
218
|
+
"content-length": String(encoded.length),
|
|
219
|
+
}),
|
|
220
|
+
body: {
|
|
221
|
+
getReader: () => ({
|
|
222
|
+
read: () => {
|
|
223
|
+
if (!readerDone) {
|
|
224
|
+
readerDone = true;
|
|
225
|
+
return Promise.resolve({ done: false, value: encoded });
|
|
226
|
+
}
|
|
227
|
+
return Promise.resolve({ done: true, value: undefined });
|
|
228
|
+
},
|
|
229
|
+
}),
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const { data, status } = await request.send();
|
|
234
|
+
|
|
235
|
+
expect(status).toBe(200);
|
|
236
|
+
expect(data).toStrictEqual({ username: "prc", firstName: "Maciej" });
|
|
237
|
+
|
|
238
|
+
global.fetch = originalFetch;
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("should handle failure response when body has no getReader", async () => {
|
|
242
|
+
const originalFetch = global.fetch;
|
|
243
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
244
|
+
ok: false,
|
|
245
|
+
status: 500,
|
|
246
|
+
headers: new Headers({ "content-type": "application/json" }),
|
|
247
|
+
body: null,
|
|
248
|
+
text: () => Promise.resolve(JSON.stringify({ errors: ["Internal Server Error"] })),
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const { data, error, status } = await request.send();
|
|
252
|
+
|
|
253
|
+
expect(data).toBeNull();
|
|
254
|
+
expect(status).toBe(500);
|
|
255
|
+
expect(error).toStrictEqual(["Internal Server Error"]);
|
|
256
|
+
|
|
257
|
+
global.fetch = originalFetch;
|
|
258
|
+
});
|
|
169
259
|
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @vitest-environment node
|
|
3
3
|
*/
|
|
4
4
|
import { Client, getErrorMessage } from "@hyper-fetch/core";
|
|
5
5
|
import { createGraphqlMockingServer } from "@hyper-fetch/testing";
|
|
6
|
-
import https from "https";
|
|
7
6
|
|
|
8
7
|
import { GraphqlAdapter, GraphqlMethod } from "../../../src/adapter";
|
|
9
|
-
import { GetUserQueryResponse
|
|
10
|
-
import {
|
|
8
|
+
import type { GetUserQueryResponse } from "../../constants/queries.constants";
|
|
9
|
+
import { getUserQuery, getUserQueryString } from "../../constants/queries.constants";
|
|
10
|
+
import type { LoginMutationVariables } from "../../constants/mutations.constants";
|
|
11
|
+
import { loginMutation } from "../../constants/mutations.constants";
|
|
11
12
|
|
|
12
13
|
const { startServer, stopServer, resetMocks, mockRequest } = createGraphqlMockingServer();
|
|
13
14
|
|
|
14
15
|
describe("Graphql Adapter [ Server ]", () => {
|
|
15
16
|
const requestId = "test";
|
|
16
|
-
const requestCopy = https.request;
|
|
17
17
|
let clientHttp = new Client({ url: "http://shared-base-url/graphql" }).setAdapter(GraphqlAdapter()).setDebug(true);
|
|
18
18
|
let client = new Client({ url: "https://shared-base-url/graphql" }).setAdapter(GraphqlAdapter()).setDebug(true);
|
|
19
19
|
let requestHttp = clientHttp.createRequest<{ response: GetUserQueryResponse }>()({ endpoint: getUserQuery });
|
|
@@ -39,10 +39,9 @@ describe("Graphql Adapter [ Server ]", () => {
|
|
|
39
39
|
|
|
40
40
|
afterEach(() => {
|
|
41
41
|
client.clear();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
https.globalAgent.destroy();
|
|
42
|
+
vi.resetAllMocks();
|
|
43
|
+
vi.clearAllMocks();
|
|
44
|
+
vi.restoreAllMocks();
|
|
46
45
|
resetMocks();
|
|
47
46
|
});
|
|
48
47
|
|
|
@@ -71,11 +70,10 @@ describe("Graphql Adapter [ Server ]", () => {
|
|
|
71
70
|
expect(res.data).toBeDefined();
|
|
72
71
|
});
|
|
73
72
|
|
|
74
|
-
it("should
|
|
75
|
-
mockRequest(
|
|
76
|
-
client.requestManager.addAbortController(request.abortKey, requestId);
|
|
73
|
+
it("should handle http and https urls", async () => {
|
|
74
|
+
mockRequest(requestHttp);
|
|
77
75
|
|
|
78
|
-
const res = await
|
|
76
|
+
const res = await requestHttp.send();
|
|
79
77
|
|
|
80
78
|
expect(res.data).toBeDefined();
|
|
81
79
|
});
|
|
@@ -173,26 +171,21 @@ describe("Graphql Adapter [ Server ]", () => {
|
|
|
173
171
|
expect(error).toStrictEqual([getErrorMessage()]);
|
|
174
172
|
});
|
|
175
173
|
|
|
176
|
-
it("should allow to set options", async () => {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
jest.spyOn(https, "request").mockImplementation((url, options, callback) => {
|
|
180
|
-
receivedOptions = options;
|
|
181
|
-
return requestCopy(options, callback);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
const timeoutRequest = request.setOptions({ timeout: 10 });
|
|
185
|
-
mockRequest(timeoutRequest, { delay: 20 });
|
|
174
|
+
it("should allow to set options and timeout the request", async () => {
|
|
175
|
+
const timeoutRequest = request.setOptions({ timeout: 5 });
|
|
176
|
+
mockRequest(timeoutRequest, { delay: 500 });
|
|
186
177
|
|
|
187
|
-
await timeoutRequest.send();
|
|
178
|
+
const { data, error, status } = await timeoutRequest.send();
|
|
188
179
|
|
|
189
|
-
expect(
|
|
180
|
+
expect(data).toBeNull();
|
|
181
|
+
expect(status).toBe(0);
|
|
182
|
+
expect(error).toStrictEqual(getErrorMessage("timeout"));
|
|
190
183
|
});
|
|
191
184
|
|
|
192
185
|
// it("should allow to calculate payload size", async () => {
|
|
193
186
|
// let receivedOptions: any;
|
|
194
187
|
|
|
195
|
-
//
|
|
188
|
+
// vi.spyOn(https, "request").mockImplementation((url, options, callback) => {
|
|
196
189
|
// receivedOptions = options;
|
|
197
190
|
// return requestCopy(options, callback);
|
|
198
191
|
// });
|
|
@@ -211,7 +204,7 @@ describe("Graphql Adapter [ Server ]", () => {
|
|
|
211
204
|
// it("should allow to calculate Buffer size", async () => {
|
|
212
205
|
// let receivedOptions: any;
|
|
213
206
|
|
|
214
|
-
//
|
|
207
|
+
// vi.spyOn(https, "request").mockImplementation((url, options, callback) => {
|
|
215
208
|
// receivedOptions = options;
|
|
216
209
|
// return requestCopy(options, callback);
|
|
217
210
|
// });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client } from "@hyper-fetch/core";
|
|
2
2
|
|
|
3
3
|
import { GraphqlMethod, getRequestValues, GraphqlAdapter } from "adapter";
|
|
4
|
+
import { gqlEndpointNameMapper } from "../../../src/adapter/adapter.utils";
|
|
4
5
|
import { getUserQuery, getUserQueryString } from "../../constants/queries.constants";
|
|
5
6
|
|
|
6
7
|
describe("Graphql Adapter [ Utils ]", () => {
|
|
@@ -25,9 +26,9 @@ describe("Graphql Adapter [ Utils ]", () => {
|
|
|
25
26
|
method: GraphqlMethod.GET,
|
|
26
27
|
});
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
vi.resetAllMocks();
|
|
30
|
+
vi.clearAllMocks();
|
|
31
|
+
vi.restoreAllMocks();
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
describe("When using getRequestValues", () => {
|
|
@@ -50,4 +51,36 @@ describe("Graphql Adapter [ Utils ]", () => {
|
|
|
50
51
|
expect(requestGet.endpoint).toBeString();
|
|
51
52
|
});
|
|
52
53
|
});
|
|
54
|
+
|
|
55
|
+
describe("When using gqlEndpointNameMapper", () => {
|
|
56
|
+
it("should return operation name for a named query", () => {
|
|
57
|
+
const result = gqlEndpointNameMapper("query GetUser { username { username firstName } }");
|
|
58
|
+
expect(result).toBe("GetUser");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("should return field name when operation has no name", () => {
|
|
62
|
+
const result = gqlEndpointNameMapper("query { username { username firstName } }");
|
|
63
|
+
expect(result).toBe("username");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should fallback when operation has no name and selection is not a Field", () => {
|
|
67
|
+
const result = gqlEndpointNameMapper("query { ... on User { username } }");
|
|
68
|
+
expect(result).toBe("User");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should return 'graphql-request' when endpoint is empty after cleanup", () => {
|
|
72
|
+
const result = gqlEndpointNameMapper("{}");
|
|
73
|
+
expect(result).toBe("graphql-request");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should use fallback when parse throws (invalid graphql)", () => {
|
|
77
|
+
const result = gqlEndpointNameMapper("not a valid graphql string at all");
|
|
78
|
+
expect(result).toBe("not");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("should return 'graphql-request' when entire fallback string is empty", () => {
|
|
82
|
+
const result = gqlEndpointNameMapper("query");
|
|
83
|
+
expect(result).toBe("graphql-request");
|
|
84
|
+
});
|
|
85
|
+
});
|
|
53
86
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Ambient shim: core uses `baseUrl` `request` → `src/request`; gql test tsconfig resolves bare `request` to npm. */
|
|
2
|
+
declare module "request" {
|
|
3
|
+
export type RequestInstance = object;
|
|
4
|
+
|
|
5
|
+
export function getProgressValue(event: { loaded?: number; total?: number }): number;
|
|
6
|
+
|
|
7
|
+
export function getRequestEta(
|
|
8
|
+
startDate: Date,
|
|
9
|
+
progressDate: Date,
|
|
10
|
+
event: { total: number; loaded: number },
|
|
11
|
+
): { sizeLeft: number; timeLeft: number | null };
|
|
12
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Mock } from "vitest";
|
|
2
|
+
|
|
3
|
+
export const testCallbacksExecution = (callbacks: Array<Mock>) => {
|
|
2
4
|
callbacks.forEach((spyFn, index) => {
|
|
3
5
|
const nextSpy = callbacks[index + 1];
|
|
4
6
|
if (nextSpy) {
|
package/__tests__/tsconfig.json
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["dom", "dom.iterable", "ESNext"],
|
|
3
7
|
"strict": true,
|
|
4
8
|
"noEmit": true,
|
|
5
|
-
"
|
|
6
|
-
"moduleResolution": "node",
|
|
9
|
+
"skipLibCheck": true,
|
|
7
10
|
"esModuleInterop": true,
|
|
8
11
|
"allowSyntheticDefaultImports": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noUnusedLocals": false,
|
|
15
|
+
"noUnusedParameters": false,
|
|
16
|
+
"types": ["vitest/globals", "jest-extended", "@types/node"],
|
|
17
|
+
"baseUrl": "../src",
|
|
9
18
|
"paths": {
|
|
10
19
|
"@hyper-fetch/graphql": ["../src"]
|
|
11
20
|
}
|
|
12
|
-
}
|
|
21
|
+
},
|
|
22
|
+
"include": ["**/*.ts", "**/*.tsx", "../../../global.d.ts", "../../../vitest.d.ts"]
|
|
13
23
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="vitest/globals" />
|
|
2
|
+
import { AbortController } from "abortcontroller-polyfill/dist/cjs-ponyfill";
|
|
3
|
+
import * as matchers from "jest-extended";
|
|
4
|
+
import { expect } from "vitest";
|
|
5
|
+
|
|
6
|
+
expect.extend(matchers);
|
|
7
|
+
|
|
8
|
+
if (!globalThis.AbortController) {
|
|
9
|
+
globalThis.AbortController = AbortController as any;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.constants.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.constants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,eAAO,MAAM,cAAc,QAAe,CAAC;AAE3C,eAAO,MAAM,QAAQ,EAAE,gBAGtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,eAAO,MAAM,cAAc,QAAO,kBAEjC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Adapter, EmptyTypes, QueryParamsType } from '@hyper-fetch/core';
|
|
2
|
+
import { DocumentNode } from 'graphql/language/ast';
|
|
3
|
+
export declare enum GraphqlMethod {
|
|
4
|
+
POST = "POST",
|
|
5
|
+
GET = "GET"
|
|
6
|
+
}
|
|
7
|
+
export type GraphQlExtraType = {
|
|
8
|
+
headers: HeadersInit;
|
|
9
|
+
extensions: Record<string, any>;
|
|
10
|
+
};
|
|
11
|
+
export type GraphQlEndpointType = string | DocumentNode;
|
|
12
|
+
export type FetchGraphqlAdapterOptionsType = Omit<RequestInit, "method" | "headers" | "body" | "signal"> & {
|
|
13
|
+
timeout?: number;
|
|
14
|
+
};
|
|
15
|
+
export type GraphqlAdapterType = Adapter<FetchGraphqlAdapterOptionsType, GraphqlMethod, number, GraphQlExtraType, QueryParamsType | string, undefined, GraphQlEndpointType, (endpoint: GraphQlEndpointType) => string>;
|
|
16
|
+
type GqlParamType = boolean | string | number | Record<string, any> | EmptyTypes;
|
|
17
|
+
export type ExtractGqlRouteParams<T extends string> = string extends T ? EmptyTypes : T extends `${string}query ${infer Parameters} {${infer QueryRest}` ? Parameters extends `${string}$${infer Param},${infer Rest}` ? GqlParameter<Param, Rest> & (ExtractGqlRouteParams<QueryRest> extends EmptyTypes ? {} : ExtractGqlRouteParams<QueryRest>) : Parameters extends `${string}$${infer Param})${infer Rest}` ? GqlParameter<Param, Rest> & (ExtractGqlRouteParams<QueryRest> extends EmptyTypes ? {} : ExtractGqlRouteParams<QueryRest>) : EmptyTypes : T extends `${string}$${infer Parameters},${infer Rest}` ? GqlParameter<Parameters, Rest> : T extends `${string}$${infer Parameters})${infer Rest}` ? GqlParameter<Parameters, Rest> : EmptyTypes;
|
|
18
|
+
export type GqlParameter<T extends string, Rest extends string> = T extends `${infer Param}:${string}!` ? {
|
|
19
|
+
[k in Param]: GqlParamType;
|
|
20
|
+
} & (ExtractGqlRouteParams<Rest> extends EmptyTypes ? {} : ExtractGqlRouteParams<Rest>) : T extends `${infer Param}:${string}` ? {
|
|
21
|
+
[k in Param]?: GqlParamType;
|
|
22
|
+
} & (ExtractGqlRouteParams<Rest> extends EmptyTypes ? {} : ExtractGqlRouteParams<Rest>) : EmptyTypes;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=adapter.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.types.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,GAAG,QAAQ;CACZ;AAED,MAAM,MAAM,gBAAgB,GAAG;IAAE,OAAO,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,CAAC;AAEzF,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,YAAY,CAAC;AAExD,MAAM,MAAM,8BAA8B,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC,GAAG;IACzG,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACtC,8BAA8B,EAC9B,aAAa,EACb,MAAM,EACN,gBAAgB,EAChB,eAAe,GAAG,MAAM,EACxB,SAAS,EACT,mBAAmB,EACnB,CAAC,QAAQ,EAAE,mBAAmB,KAAK,MAAM,CAC1C,CAAC;AAIF,KAAK,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,UAAU,CAAC;AAEjF,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,SAAS,CAAC,GAClE,UAAU,GACV,CAAC,SAAS,GAAG,MAAM,SAAS,MAAM,UAAU,KAAK,MAAM,SAAS,EAAE,GAChE,UAAU,SAAS,GAAG,MAAM,IAAI,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,GACzD,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,GAEvB,CAAC,qBAAqB,CAAC,SAAS,CAAC,SAAS,UAAU,GAAG,EAAE,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC,GAC/F,UAAU,SAAS,GAAG,MAAM,IAAI,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,GACzD,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,GAEvB,CAAC,qBAAqB,CAAC,SAAS,CAAC,SAAS,UAAU,GAAG,EAAE,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC,GAC/F,UAAU,GACd,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,UAAU,IAAI,MAAM,IAAI,EAAE,GACrD,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,GAC9B,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,UAAU,IAAI,MAAM,IAAI,EAAE,GACrD,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,GAC9B,UAAU,CAAC;AAErB,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,KAAK,IAAI,MAAM,GAAG,GACnG;KAAG,CAAC,IAAI,KAAK,GAAG,YAAY;CAAE,GAAG,CAAC,qBAAqB,CAAC,IAAI,CAAC,SAAS,UAAU,GAE5E,EAAE,GACF,qBAAqB,CAAC,IAAI,CAAC,CAAC,GAChC,CAAC,SAAS,GAAG,MAAM,KAAK,IAAI,MAAM,EAAE,GAClC;KAAG,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,YAAY;CAAE,GAAG,CAAC,qBAAqB,CAAC,IAAI,CAAC,SAAS,UAAU,GAE7E,EAAE,GACF,qBAAqB,CAAC,IAAI,CAAC,CAAC,GAChC,UAAU,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RequestInstance } from '@hyper-fetch/core';
|
|
2
|
+
import { GraphQlEndpointType } from '.';
|
|
3
|
+
export declare const getRequestValues: <R extends RequestInstance>(request: R) => {
|
|
4
|
+
fullUrl: string;
|
|
5
|
+
payload: string | null;
|
|
6
|
+
};
|
|
7
|
+
export declare const gqlEndpointMapper: <E extends GraphQlEndpointType>(endpoint: E) => string;
|
|
8
|
+
export declare const gqlEndpointNameMapper: (endpoint: string) => string;
|
|
9
|
+
//# sourceMappingURL=adapter.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.utils.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAKzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,eAAe,EAAE,SAAS,CAAC;;;CAgBrE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,mBAAmB,EAAE,UAAU,CAAC,KAAG,MAK9E,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,UAAU,MAAM,KAAG,MAgCxD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-adapter.fetch.d.ts","sourceRoot":"","sources":["../../src/adapter/http-adapter.fetch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAInB,MAAM,SAAS,CAAC;AAUjB,eAAO,MAAM,aAAa,QAAO,kBAuK5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,34 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare enum GraphqlMethod {
|
|
5
|
-
POST = "POST",
|
|
6
|
-
GET = "GET"
|
|
7
|
-
}
|
|
8
|
-
type GraphQlExtraType = {
|
|
9
|
-
headers: HeadersInit;
|
|
10
|
-
extensions: Record<string, any>;
|
|
11
|
-
};
|
|
12
|
-
type GraphQlEndpointType = string | DocumentNode;
|
|
13
|
-
type GraphqlAdapterType = Adapter<Partial<XMLHttpRequest>, GraphqlMethod, number, GraphQlExtraType, QueryParamsType | string, undefined, GraphQlEndpointType, (endpoint: GraphQlEndpointType) => string>;
|
|
14
|
-
type GqlParamType = boolean | string | number | Record<string, any> | EmptyTypes;
|
|
15
|
-
type ExtractGqlRouteParams<T extends string> = string extends T ? EmptyTypes : T extends `${string}query ${infer Parameters} {${infer QueryRest}` ? Parameters extends `${string}$${infer Param},${infer Rest}` ? GqlParameter<Param, Rest> & (ExtractGqlRouteParams<QueryRest> extends EmptyTypes ? {} : ExtractGqlRouteParams<QueryRest>) : Parameters extends `${string}$${infer Param})${infer Rest}` ? GqlParameter<Param, Rest> & (ExtractGqlRouteParams<QueryRest> extends EmptyTypes ? {} : ExtractGqlRouteParams<QueryRest>) : EmptyTypes : T extends `${string}$${infer Parameters},${infer Rest}` ? GqlParameter<Parameters, Rest> : T extends `${string}$${infer Parameters})${infer Rest}` ? GqlParameter<Parameters, Rest> : EmptyTypes;
|
|
16
|
-
type GqlParameter<T extends string, Rest extends string> = T extends `${infer Param}:${string}!` ? {
|
|
17
|
-
[k in Param]: GqlParamType;
|
|
18
|
-
} & (ExtractGqlRouteParams<Rest> extends EmptyTypes ? {} : ExtractGqlRouteParams<Rest>) : T extends `${infer Param}:${string}` ? {
|
|
19
|
-
[k in Param]?: GqlParamType;
|
|
20
|
-
} & (ExtractGqlRouteParams<Rest> extends EmptyTypes ? {} : ExtractGqlRouteParams<Rest>) : EmptyTypes;
|
|
21
|
-
|
|
22
|
-
declare const GraphqlAdapter: () => GraphqlAdapterType;
|
|
23
|
-
|
|
24
|
-
declare const getRequestValues: <R extends RequestInstance>(request: R) => {
|
|
25
|
-
fullUrl: string;
|
|
26
|
-
payload: string | null;
|
|
27
|
-
};
|
|
28
|
-
declare const gqlEndpointMapper: <E extends GraphQlEndpointType>(endpoint: E) => string;
|
|
29
|
-
declare const gqlEndpointNameMapper: (endpoint: string) => string;
|
|
30
|
-
|
|
31
|
-
declare const defaultTimeout: number;
|
|
32
|
-
declare const gqlExtra: GraphQlExtraType;
|
|
33
|
-
|
|
34
|
-
export { type ExtractGqlRouteParams, type GqlParameter, type GraphQlEndpointType, type GraphQlExtraType, GraphqlAdapter, type GraphqlAdapterType, GraphqlMethod, defaultTimeout, getRequestValues, gqlEndpointMapper, gqlEndpointNameMapper, gqlExtra };
|
|
1
|
+
export * from './adapter';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAC"}
|