@nhost/nhost-js 3.3.1 → 4.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/README.md +68 -32
- package/dist/fetch-2PHmQBIJ.mjs +61 -0
- package/dist/fetch-2PHmQBIJ.mjs.map +1 -0
- package/dist/fetch-DWXwEnoe.js +2 -0
- package/dist/fetch-DWXwEnoe.js.map +1 -0
- package/dist/nhost-js/auth.cjs.js +2 -0
- package/dist/nhost-js/auth.cjs.js.map +1 -0
- package/dist/nhost-js/auth.es.js +917 -0
- package/dist/nhost-js/auth.es.js.map +1 -0
- package/dist/nhost-js/fetch.cjs.js +2 -0
- package/dist/nhost-js/fetch.cjs.js.map +1 -0
- package/dist/nhost-js/fetch.es.js +90 -0
- package/dist/nhost-js/fetch.es.js.map +1 -0
- package/dist/nhost-js/functions.cjs.js +2 -0
- package/dist/nhost-js/functions.cjs.js.map +1 -0
- package/dist/nhost-js/functions.es.js +45 -0
- package/dist/nhost-js/functions.es.js.map +1 -0
- package/dist/nhost-js/graphql.cjs.js +2 -0
- package/dist/nhost-js/graphql.cjs.js.map +1 -0
- package/dist/nhost-js/graphql.es.js +48 -0
- package/dist/nhost-js/graphql.es.js.map +1 -0
- package/dist/nhost-js/session.cjs.js +2 -0
- package/dist/nhost-js/session.cjs.js.map +1 -0
- package/dist/nhost-js/session.es.js +234 -0
- package/dist/nhost-js/session.es.js.map +1 -0
- package/dist/nhost-js/storage.cjs.js +2 -0
- package/dist/nhost-js/storage.cjs.js.map +1 -0
- package/dist/nhost-js/storage.es.js +324 -0
- package/dist/nhost-js/storage.es.js.map +1 -0
- package/dist/nhost-js.cjs.js +2 -0
- package/dist/nhost-js.cjs.js.map +1 -0
- package/dist/nhost-js.es.js +228 -0
- package/dist/nhost-js.es.js.map +1 -0
- package/dist/nhost-js.umd.js +2 -0
- package/dist/nhost-js.umd.js.map +1 -0
- package/dist/refreshSession-Bw715ZmX.js +2 -0
- package/dist/refreshSession-Bw715ZmX.js.map +1 -0
- package/dist/refreshSession-WwGlzgtM.mjs +95 -0
- package/dist/refreshSession-WwGlzgtM.mjs.map +1 -0
- package/dist/src/auth/client.d.ts +1763 -0
- package/dist/src/auth/client.d.ts.map +1 -0
- package/dist/src/auth/client.js +1043 -0
- package/dist/src/auth/client.js.map +1 -0
- package/dist/src/auth/index.d.ts +35 -0
- package/dist/src/auth/index.d.ts.map +1 -0
- package/dist/src/auth/index.js +35 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/fetch/fetch.d.ts +88 -0
- package/dist/src/fetch/fetch.d.ts.map +1 -0
- package/dist/src/fetch/fetch.js +98 -0
- package/dist/src/fetch/fetch.js.map +1 -0
- package/dist/src/fetch/index.d.ts +38 -0
- package/dist/src/fetch/index.d.ts.map +1 -0
- package/dist/src/fetch/index.js +38 -0
- package/dist/src/fetch/index.js.map +1 -0
- package/dist/src/fetch/middlewareAttachAccessToken.d.ts +24 -0
- package/dist/src/fetch/middlewareAttachAccessToken.d.ts.map +1 -0
- package/dist/src/fetch/middlewareAttachAccessToken.js +54 -0
- package/dist/src/fetch/middlewareAttachAccessToken.js.map +1 -0
- package/dist/src/fetch/middlewareSessionRefresh.d.ts +30 -0
- package/dist/src/fetch/middlewareSessionRefresh.d.ts.map +1 -0
- package/dist/src/fetch/middlewareSessionRefresh.js +61 -0
- package/dist/src/fetch/middlewareSessionRefresh.js.map +1 -0
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.d.ts +26 -0
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.d.ts.map +1 -0
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.js +79 -0
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.js.map +1 -0
- package/dist/src/functions/client.d.ts +52 -0
- package/dist/src/functions/client.d.ts.map +1 -0
- package/dist/src/functions/client.js +89 -0
- package/dist/src/functions/client.js.map +1 -0
- package/dist/src/functions/index.d.ts +43 -0
- package/dist/src/functions/index.d.ts.map +1 -0
- package/dist/src/functions/index.js +43 -0
- package/dist/src/functions/index.js.map +1 -0
- package/dist/src/graphql/client.d.ts +93 -0
- package/dist/src/graphql/client.d.ts.map +1 -0
- package/dist/src/graphql/client.js +66 -0
- package/dist/src/graphql/client.js.map +1 -0
- package/dist/src/graphql/index.d.ts +65 -0
- package/dist/src/graphql/index.d.ts.map +1 -0
- package/dist/src/graphql/index.js +65 -0
- package/dist/src/graphql/index.js.map +1 -0
- package/dist/src/index.d.ts +35 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +45 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/nhost.d.ts +301 -0
- package/dist/src/nhost.d.ts.map +1 -0
- package/dist/src/nhost.js +323 -0
- package/dist/src/nhost.js.map +1 -0
- package/dist/src/session/index.d.ts +20 -0
- package/dist/src/session/index.d.ts.map +1 -0
- package/dist/src/session/index.js +19 -0
- package/dist/src/session/index.js.map +1 -0
- package/dist/src/session/refreshSession.d.ts +17 -0
- package/dist/src/session/refreshSession.d.ts.map +1 -0
- package/dist/src/session/refreshSession.js +120 -0
- package/dist/src/session/refreshSession.js.map +1 -0
- package/dist/src/session/session.d.ts +24 -0
- package/dist/src/session/session.d.ts.map +1 -0
- package/dist/src/session/session.js +48 -0
- package/dist/src/session/session.js.map +1 -0
- package/dist/src/session/storage.d.ts +62 -0
- package/dist/src/session/storage.d.ts.map +1 -0
- package/dist/src/session/storage.js +91 -0
- package/dist/src/session/storage.js.map +1 -0
- package/dist/src/session/storageBackend.d.ts +122 -0
- package/dist/src/session/storageBackend.d.ts.map +1 -0
- package/dist/src/session/storageBackend.js +145 -0
- package/dist/src/session/storageBackend.js.map +1 -0
- package/dist/src/storage/client.d.ts +546 -0
- package/dist/src/storage/client.d.ts.map +1 -0
- package/dist/src/storage/client.js +368 -0
- package/dist/src/storage/client.js.map +1 -0
- package/dist/src/storage/index.d.ts +37 -0
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/src/storage/index.js +37 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +103 -59
- package/dist/clients/auth.d.ts +0 -8
- package/dist/clients/auth.d.ts.map +0 -1
- package/dist/clients/functions/index.d.ts +0 -107
- package/dist/clients/functions/index.d.ts.map +0 -1
- package/dist/clients/functions/types.d.ts +0 -28
- package/dist/clients/functions/types.d.ts.map +0 -1
- package/dist/clients/graphql.d.ts +0 -8
- package/dist/clients/graphql.d.ts.map +0 -1
- package/dist/clients/index.d.ts +0 -6
- package/dist/clients/index.d.ts.map +0 -1
- package/dist/clients/nhost.d.ts +0 -83
- package/dist/clients/nhost.d.ts.map +0 -1
- package/dist/clients/storage.d.ts +0 -8
- package/dist/clients/storage.d.ts.map +0 -1
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js +0 -356
- package/dist/index.esm.js.map +0 -1
- package/dist/utils/helpers.d.ts +0 -20
- package/dist/utils/helpers.d.ts.map +0 -1
- package/dist/utils/types.d.ts +0 -57
- package/dist/utils/types.d.ts.map +0 -1
- package/umd/nhost-js.umd.js +0 -22
- package/umd/nhost-js.umd.js.map +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session response middleware for the Nhost SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides middleware functionality to automatically extract
|
|
5
|
+
* and persist session information from authentication responses, ensuring
|
|
6
|
+
* that new sessions are properly stored after sign-in operations.
|
|
7
|
+
*/
|
|
8
|
+
import type { SessionStorage } from "../session/storage";
|
|
9
|
+
import type { ChainFunction } from "./fetch";
|
|
10
|
+
/**
|
|
11
|
+
* Creates a fetch middleware that automatically extracts and stores session data from API responses.
|
|
12
|
+
*
|
|
13
|
+
* This middleware:
|
|
14
|
+
* 1. Monitors responses from authentication-related endpoints
|
|
15
|
+
* 2. Extracts session information when present
|
|
16
|
+
* 3. Stores the session in the provided storage implementation
|
|
17
|
+
* 4. Handles session removal on sign-out
|
|
18
|
+
*
|
|
19
|
+
* This ensures that session data is always up-to-date in storage after operations
|
|
20
|
+
* that create or invalidate sessions.
|
|
21
|
+
*
|
|
22
|
+
* @param storage - Storage implementation for persisting session data
|
|
23
|
+
* @returns A middleware function that can be used in the fetch chain
|
|
24
|
+
*/
|
|
25
|
+
export declare const updateSessionFromResponseMiddleware: (storage: SessionStorage) => ChainFunction;
|
|
26
|
+
//# sourceMappingURL=middlewareUpdateSessionFromResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewareUpdateSessionFromResponse.d.ts","sourceRoot":"","sources":["../../../src/fetch/middlewareUpdateSessionFromResponse.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mCAAmC,GAC9C,SAAS,cAAc,KACtB,aAuEF,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session response middleware for the Nhost SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides middleware functionality to automatically extract
|
|
5
|
+
* and persist session information from authentication responses, ensuring
|
|
6
|
+
* that new sessions are properly stored after sign-in operations.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Creates a fetch middleware that automatically extracts and stores session data from API responses.
|
|
10
|
+
*
|
|
11
|
+
* This middleware:
|
|
12
|
+
* 1. Monitors responses from authentication-related endpoints
|
|
13
|
+
* 2. Extracts session information when present
|
|
14
|
+
* 3. Stores the session in the provided storage implementation
|
|
15
|
+
* 4. Handles session removal on sign-out
|
|
16
|
+
*
|
|
17
|
+
* This ensures that session data is always up-to-date in storage after operations
|
|
18
|
+
* that create or invalidate sessions.
|
|
19
|
+
*
|
|
20
|
+
* @param storage - Storage implementation for persisting session data
|
|
21
|
+
* @returns A middleware function that can be used in the fetch chain
|
|
22
|
+
*/
|
|
23
|
+
export const updateSessionFromResponseMiddleware = (storage) => {
|
|
24
|
+
/**
|
|
25
|
+
* Helper function to extract session data from various response formats
|
|
26
|
+
*
|
|
27
|
+
* @param body - Response data to extract session from
|
|
28
|
+
* @returns Session object if found, null otherwise
|
|
29
|
+
*/
|
|
30
|
+
const sessionExtractor = (body) => {
|
|
31
|
+
if (typeof body === "string") {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if ("session" in body) {
|
|
35
|
+
// SessionPayload
|
|
36
|
+
return body.session || null;
|
|
37
|
+
}
|
|
38
|
+
if ("accessToken" in body && "refreshToken" in body) {
|
|
39
|
+
// Session
|
|
40
|
+
return body;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
44
|
+
return (next) => async (url, options) => {
|
|
45
|
+
// Call the next middleware in the chain
|
|
46
|
+
const response = await next(url, options);
|
|
47
|
+
try {
|
|
48
|
+
// Check if this is a logout request
|
|
49
|
+
if (url.endsWith("/signout")) {
|
|
50
|
+
// Remove session on sign-out
|
|
51
|
+
storage.remove();
|
|
52
|
+
return response;
|
|
53
|
+
}
|
|
54
|
+
// Check if this is an auth-related endpoint that might return session data
|
|
55
|
+
if (url.endsWith("/token") ||
|
|
56
|
+
url.includes("/signin/") ||
|
|
57
|
+
url.includes("/signup/")) {
|
|
58
|
+
// Clone the response to avoid consuming it
|
|
59
|
+
const clonedResponse = response.clone();
|
|
60
|
+
// Parse the JSON data
|
|
61
|
+
const body = (await clonedResponse.json().catch(() => null));
|
|
62
|
+
if (body) {
|
|
63
|
+
// Extract session data from response using provided extractor
|
|
64
|
+
const session = sessionExtractor(body);
|
|
65
|
+
// If session data is found, store it
|
|
66
|
+
if (session?.accessToken && session.refreshToken) {
|
|
67
|
+
storage.set(session);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.warn("Error in session response middleware:", error);
|
|
74
|
+
}
|
|
75
|
+
// Return the original response
|
|
76
|
+
return response;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=middlewareUpdateSessionFromResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewareUpdateSessionFromResponse.js","sourceRoot":"","sources":["../../../src/fetch/middlewareUpdateSessionFromResponse.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CACjD,OAAuB,EACR,EAAE;IACjB;;;;;OAKG;IACH,MAAM,gBAAgB,GAAG,CACvB,IAAuC,EACvB,EAAE;QAClB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,iBAAiB;YACjB,OAAO,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC;QAC9B,CAAC;QAED,IAAI,aAAa,IAAI,IAAI,IAAI,cAAc,IAAI,IAAI,EAAE,CAAC;YACpD,UAAU;YACV,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,OAAO,CAAC,IAA+D,EAAE,EAAE,CACzE,KAAK,EAAE,GAAW,EAAE,OAAqB,EAAE,EAAE;QAC3C,wCAAwC;QACxC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAE1C,IAAI,CAAC;YACH,oCAAoC;YACpC,IAAI,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC7B,6BAA6B;gBAC7B,OAAO,CAAC,MAAM,EAAE,CAAC;gBACjB,OAAO,QAAQ,CAAC;YAClB,CAAC;YAED,2EAA2E;YAC3E,IACE,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACtB,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC;gBACxB,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EACxB,CAAC;gBACD,2CAA2C;gBAC3C,MAAM,cAAc,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;gBAExC,sBAAsB;gBACtB,MAAM,IAAI,GAAG,CAAC,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAEzC,CAAC;gBAEnB,IAAI,IAAI,EAAE,CAAC;oBACT,8DAA8D;oBAC9D,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;oBAEvC,qCAAqC;oBACrC,IAAI,OAAO,EAAE,WAAW,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;wBACjD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;oBACvB,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;QAC/D,CAAC;QAED,+BAA+B;QAC/B,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Functions client for the Nhost JavaScript SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides functionality for executing serverless function calls
|
|
5
|
+
* against Nhost serverless functions.
|
|
6
|
+
*/
|
|
7
|
+
import { type ChainFunction, type FetchResponse } from "../fetch";
|
|
8
|
+
/**
|
|
9
|
+
* Functions client interface providing methods for executing serverless function calls
|
|
10
|
+
*/
|
|
11
|
+
export interface Client {
|
|
12
|
+
baseURL: string;
|
|
13
|
+
/**
|
|
14
|
+
* Execute a request to a serverless function
|
|
15
|
+
* The response body will be automatically parsed based on the content type into the following types:
|
|
16
|
+
* - Object if the response is application/json
|
|
17
|
+
* - string text string if the response is text/*
|
|
18
|
+
* - Blob if the response is any other type
|
|
19
|
+
*
|
|
20
|
+
* @param path - The path to the serverless function
|
|
21
|
+
* @param options - Additional fetch options to apply to the request
|
|
22
|
+
* @returns Promise with the function response and metadata. */
|
|
23
|
+
fetch<T = unknown>(path: string, options?: RequestInit): Promise<FetchResponse<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* Executes a POST request to a serverless function with a JSON body
|
|
26
|
+
*
|
|
27
|
+
* This is a convenience method assuming the request is a POST with JSON body
|
|
28
|
+
* setting the `Content-Type` and 'Accept' headers to `application/json` and
|
|
29
|
+
* automatically stringifying the body.
|
|
30
|
+
*
|
|
31
|
+
* For a more generic request, use the `fetch` method instead.
|
|
32
|
+
*
|
|
33
|
+
* @param path - The path to the serverless function
|
|
34
|
+
* @param body - The JSON body to send in the request
|
|
35
|
+
* @param options - Additional fetch options to apply to the request
|
|
36
|
+
* @returns Promise with the function response and metadata
|
|
37
|
+
*/
|
|
38
|
+
post<T = unknown>(path: string, body?: unknown, options?: RequestInit): Promise<FetchResponse<T>>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a Functions API client for interacting with serverless functions.
|
|
42
|
+
*
|
|
43
|
+
* This client provides methods for executing requests against serverless functions,
|
|
44
|
+
* with support for middleware functions to handle authentication, error handling,
|
|
45
|
+
* and other cross-cutting concerns.
|
|
46
|
+
*
|
|
47
|
+
* @param baseURL - Base URL for the functions endpoint
|
|
48
|
+
* @param chainFunctions - Array of middleware functions for the fetch chain
|
|
49
|
+
* @returns Functions client with fetch method
|
|
50
|
+
*/
|
|
51
|
+
export declare const createAPIClient: (baseURL: string, chainFunctions?: ChainFunction[]) => Client;
|
|
52
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/functions/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,KAAK,aAAa,EAGlB,KAAK,aAAa,EACnB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;;;;sEASkE;IAClE,KAAK,CAAC,CAAC,GAAG,OAAO,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7B;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,CAAC,GAAG,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,EACf,iBAAgB,aAAa,EAAO,KACnC,MAiFF,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Functions client for the Nhost JavaScript SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides functionality for executing serverless function calls
|
|
5
|
+
* against Nhost serverless functions.
|
|
6
|
+
*/
|
|
7
|
+
import { createEnhancedFetch, FetchError, } from "../fetch";
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Functions API client for interacting with serverless functions.
|
|
10
|
+
*
|
|
11
|
+
* This client provides methods for executing requests against serverless functions,
|
|
12
|
+
* with support for middleware functions to handle authentication, error handling,
|
|
13
|
+
* and other cross-cutting concerns.
|
|
14
|
+
*
|
|
15
|
+
* @param baseURL - Base URL for the functions endpoint
|
|
16
|
+
* @param chainFunctions - Array of middleware functions for the fetch chain
|
|
17
|
+
* @returns Functions client with fetch method
|
|
18
|
+
*/
|
|
19
|
+
export const createAPIClient = (baseURL, chainFunctions = []) => {
|
|
20
|
+
const enhancedFetch = createEnhancedFetch(chainFunctions);
|
|
21
|
+
/**
|
|
22
|
+
* Executes a request to a serverless function and processes the response
|
|
23
|
+
*
|
|
24
|
+
* @param path - The path to the serverless function
|
|
25
|
+
* @param options - Additional fetch options to apply to the request
|
|
26
|
+
* @returns Promise with the function response and metadata. Body will be either
|
|
27
|
+
* - JSON object if the response is application/json
|
|
28
|
+
- text string if the response is text/*
|
|
29
|
+
- Blob if the response is any other type
|
|
30
|
+
*/
|
|
31
|
+
const fetch = async (path, options) => {
|
|
32
|
+
const resp = await enhancedFetch(`${baseURL}${path}`, options);
|
|
33
|
+
let body;
|
|
34
|
+
// Process response based on content type
|
|
35
|
+
if (resp.headers.get("content-type")?.includes("application/json")) {
|
|
36
|
+
body = (await resp.json());
|
|
37
|
+
}
|
|
38
|
+
else if (resp.headers.get("content-type")?.startsWith("text/")) {
|
|
39
|
+
body = await resp.text();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
body = await resp.blob();
|
|
43
|
+
}
|
|
44
|
+
// Throw error for non-OK responses
|
|
45
|
+
if (!resp.ok) {
|
|
46
|
+
throw new FetchError(body, resp.status, resp.headers);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
status: resp.status,
|
|
50
|
+
body,
|
|
51
|
+
headers: resp.headers,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Executes a POST request to a serverless function with a JSON body
|
|
56
|
+
*
|
|
57
|
+
* This is a convenience method assuming the request is a POST with JSON body
|
|
58
|
+
* setting the `Content-Type` and 'Accept' headers to `application/json` and
|
|
59
|
+
* automatically stringifying the body.
|
|
60
|
+
*
|
|
61
|
+
* For a more generic request, use the `fetch` method instead.
|
|
62
|
+
*
|
|
63
|
+
* @param path - The path to the serverless function
|
|
64
|
+
* @param body - The JSON body to send in the request
|
|
65
|
+
* @param options - Additional fetch options to apply to the request
|
|
66
|
+
* @returns Promise with the function response and metadata
|
|
67
|
+
*/
|
|
68
|
+
const post = async (path, body, options = {}) => {
|
|
69
|
+
// Ensure the method is POST and set the body
|
|
70
|
+
const requestOptions = {
|
|
71
|
+
...options,
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: {
|
|
74
|
+
Accept: "application/json",
|
|
75
|
+
"Content-Type": "application/json",
|
|
76
|
+
...options.headers,
|
|
77
|
+
},
|
|
78
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
79
|
+
};
|
|
80
|
+
return fetch(path, requestOptions);
|
|
81
|
+
};
|
|
82
|
+
// Return client object with the fetch method
|
|
83
|
+
return {
|
|
84
|
+
baseURL,
|
|
85
|
+
fetch,
|
|
86
|
+
post,
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/functions/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,mBAAmB,EACnB,UAAU,GAEX,MAAM,UAAU,CAAC;AA4ClB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAAe,EACf,iBAAkC,EAAE,EAC5B,EAAE;IACV,MAAM,aAAa,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAE1D;;;;;;;;;OASG;IACH,MAAM,KAAK,GAAG,KAAK,EACjB,IAAY,EACZ,OAAqB,EACsB,EAAE;QAC7C,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,GAAG,OAAO,GAAG,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;QAE/D,IAAI,IAAuB,CAAC;QAC5B,yCAAyC;QACzC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACnE,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAM,CAAC;QAClC,CAAC;aAAM,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YACjE,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAC3B,CAAC;QAED,mCAAmC;QACnC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC;QAED,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI;YACJ,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC,CAAC;IAEF;;;;;;;;;;;;;OAaG;IACH,MAAM,IAAI,GAAG,KAAK,EAChB,IAAY,EACZ,IAAc,EACd,UAAuB,EAAE,EACkB,EAAE;QAC7C,6CAA6C;QAC7C,MAAM,cAAc,GAAgB;YAClC,GAAG,OAAO;YACV,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO,CAAC,OAAO;aACnB;YACD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC;QAEF,OAAO,KAAK,CAAI,IAAI,EAAE,cAAc,CAAC,CAAC;IACxC,CAAC,CAAC;IAEF,6CAA6C;IAC7C,OAAO;QACL,OAAO;QACP,KAAK;QACL,IAAI;KACK,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the main module to interact with Nhost's Functions service.
|
|
3
|
+
* Typically you would use this module via the main [Nhost client](main#createclient)
|
|
4
|
+
* but you can also use it directly if you have a specific use case.
|
|
5
|
+
*
|
|
6
|
+
* ## Import
|
|
7
|
+
*
|
|
8
|
+
* You can import and use this package with:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createClient } from "@nhost/nhost-js/functions";
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* ## Usage
|
|
15
|
+
*
|
|
16
|
+
* You can use this library by passing the path to the function you want to call and any body
|
|
17
|
+
* or fetch options you want to apply (optional):
|
|
18
|
+
*
|
|
19
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,4,9-20}
|
|
20
|
+
*
|
|
21
|
+
* The post method above is a convenience method for executing a POST request with a JSON body.
|
|
22
|
+
* For more generic requests, you can use the `fetch` method instead:
|
|
23
|
+
*
|
|
24
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,4,30-43}
|
|
25
|
+
*
|
|
26
|
+
* ## Error handling
|
|
27
|
+
*
|
|
28
|
+
* The SDK will throw errors in most operations if the request returns a status >=300 or
|
|
29
|
+
* if the request fails entirely (i.e., due to network errors). The type of the error
|
|
30
|
+
* will be a `FetchError<T>`:
|
|
31
|
+
*
|
|
32
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2-4,53-64,67-79,84}
|
|
33
|
+
*
|
|
34
|
+
* This type extends the standard `Error` type so if you want to just log the error you can
|
|
35
|
+
* do so like this:
|
|
36
|
+
*
|
|
37
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2-4,91-102,105-112,115}
|
|
38
|
+
*
|
|
39
|
+
* @module functions
|
|
40
|
+
* @packageDocumentation
|
|
41
|
+
*/
|
|
42
|
+
export * from "./client";
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the main module to interact with Nhost's Functions service.
|
|
3
|
+
* Typically you would use this module via the main [Nhost client](main#createclient)
|
|
4
|
+
* but you can also use it directly if you have a specific use case.
|
|
5
|
+
*
|
|
6
|
+
* ## Import
|
|
7
|
+
*
|
|
8
|
+
* You can import and use this package with:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createClient } from "@nhost/nhost-js/functions";
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* ## Usage
|
|
15
|
+
*
|
|
16
|
+
* You can use this library by passing the path to the function you want to call and any body
|
|
17
|
+
* or fetch options you want to apply (optional):
|
|
18
|
+
*
|
|
19
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,4,9-20}
|
|
20
|
+
*
|
|
21
|
+
* The post method above is a convenience method for executing a POST request with a JSON body.
|
|
22
|
+
* For more generic requests, you can use the `fetch` method instead:
|
|
23
|
+
*
|
|
24
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,4,30-43}
|
|
25
|
+
*
|
|
26
|
+
* ## Error handling
|
|
27
|
+
*
|
|
28
|
+
* The SDK will throw errors in most operations if the request returns a status >=300 or
|
|
29
|
+
* if the request fails entirely (i.e., due to network errors). The type of the error
|
|
30
|
+
* will be a `FetchError<T>`:
|
|
31
|
+
*
|
|
32
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2-4,53-64,67-79,84}
|
|
33
|
+
*
|
|
34
|
+
* This type extends the standard `Error` type so if you want to just log the error you can
|
|
35
|
+
* do so like this:
|
|
36
|
+
*
|
|
37
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2-4,91-102,105-112,115}
|
|
38
|
+
*
|
|
39
|
+
* @module functions
|
|
40
|
+
* @packageDocumentation
|
|
41
|
+
*/
|
|
42
|
+
export * from "./client";
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL client for the Nhost JavaScript SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides functionality for executing GraphQL operations against
|
|
5
|
+
* a Hasura GraphQL API.
|
|
6
|
+
*/
|
|
7
|
+
import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
|
|
8
|
+
import { type ChainFunction, type FetchResponse } from "../fetch";
|
|
9
|
+
/**
|
|
10
|
+
* Variables object for GraphQL operations.
|
|
11
|
+
* Key-value pairs of variable names and their values.
|
|
12
|
+
*/
|
|
13
|
+
export type GraphQLVariables = Record<string, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* GraphQL request object used for queries and mutations.
|
|
16
|
+
*/
|
|
17
|
+
export interface GraphQLRequest<TVariables = GraphQLVariables> {
|
|
18
|
+
/** The GraphQL query or mutation string */
|
|
19
|
+
query: string;
|
|
20
|
+
/** Optional variables for parameterized queries */
|
|
21
|
+
variables?: TVariables;
|
|
22
|
+
/** Optional name of the operation to execute */
|
|
23
|
+
operationName?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Represents a GraphQL error returned from the server.
|
|
27
|
+
*/
|
|
28
|
+
export interface GraphQLError {
|
|
29
|
+
/** Error message */
|
|
30
|
+
message: string;
|
|
31
|
+
/** Source locations in the GraphQL document where the error occurred */
|
|
32
|
+
locations?: {
|
|
33
|
+
line: number;
|
|
34
|
+
column: number;
|
|
35
|
+
}[];
|
|
36
|
+
/** Path in the query where the error occurred */
|
|
37
|
+
path?: string[];
|
|
38
|
+
/** Additional error information specific to the GraphQL implementation */
|
|
39
|
+
extensions?: {
|
|
40
|
+
path: string;
|
|
41
|
+
code: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Standard GraphQL response format as defined by the GraphQL specification.
|
|
46
|
+
*/
|
|
47
|
+
export interface GraphQLResponse<TResponseData = unknown> {
|
|
48
|
+
/** The data returned from successful execution */
|
|
49
|
+
data?: TResponseData;
|
|
50
|
+
/** Array of errors if execution was unsuccessful or partially successful */
|
|
51
|
+
errors?: GraphQLError[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* GraphQL client interface providing methods for executing queries and mutations
|
|
55
|
+
*/
|
|
56
|
+
export interface Client {
|
|
57
|
+
/**
|
|
58
|
+
* Execute a GraphQL query operation
|
|
59
|
+
*
|
|
60
|
+
* Queries are used to fetch data and should not modify any data on the server.
|
|
61
|
+
*
|
|
62
|
+
* @param request - GraphQL request object containing query and optional variables
|
|
63
|
+
* @param options - Additional fetch options to apply to the request
|
|
64
|
+
* @returns Promise with the GraphQL response and metadata
|
|
65
|
+
*/
|
|
66
|
+
request<TResponseData = unknown, TVariables = GraphQLVariables>(request: GraphQLRequest<TVariables>, options?: RequestInit): Promise<FetchResponse<GraphQLResponse<TResponseData>>>;
|
|
67
|
+
/**
|
|
68
|
+
* Execute a GraphQL query operation using a typed document node
|
|
69
|
+
*
|
|
70
|
+
* @param document - TypedDocumentNode containing the query and type information
|
|
71
|
+
* @param variables - Variables for the GraphQL operation
|
|
72
|
+
* @param options - Additional fetch options to apply to the request
|
|
73
|
+
* @returns Promise with the GraphQL response and metadata
|
|
74
|
+
*/
|
|
75
|
+
request<TResponseData, TVariables = GraphQLVariables>(document: TypedDocumentNode<TResponseData, TVariables>, variables?: TVariables, options?: RequestInit): Promise<FetchResponse<GraphQLResponse<TResponseData>>>;
|
|
76
|
+
/**
|
|
77
|
+
* URL for the GraphQL endpoint.
|
|
78
|
+
*/
|
|
79
|
+
url: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Creates a GraphQL API client for interacting with a GraphQL endpoint.
|
|
83
|
+
*
|
|
84
|
+
* This client provides methods for executing queries and mutations against
|
|
85
|
+
* a GraphQL API, with support for middleware functions to handle authentication,
|
|
86
|
+
* error handling, and other cross-cutting concerns.
|
|
87
|
+
*
|
|
88
|
+
* @param url - Base URL for the GraphQL endpoint
|
|
89
|
+
* @param chainFunctions - Array of middleware functions for the fetch chain
|
|
90
|
+
* @returns GraphQL client with query and mutation methods
|
|
91
|
+
*/
|
|
92
|
+
export declare const createAPIClient: (url: string, chainFunctions?: ChainFunction[]) => Client;
|
|
93
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/graphql/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EACL,KAAK,aAAa,EAGlB,KAAK,aAAa,EACnB,MAAM,UAAU,CAAC;AAElB;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,UAAU,GAAG,gBAAgB;IAC3D,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,oBAAoB;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC/C,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,0EAA0E;IAC1E,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,aAAa,GAAG,OAAO;IACtD,kDAAkD;IAClD,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,4EAA4E;IAC5E,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa,GAAG,OAAO,EAAE,UAAU,GAAG,gBAAgB,EAC5D,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,EACnC,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAE1D;;;;;;;OAOG;IACH,OAAO,CAAC,aAAa,EAAE,UAAU,GAAG,gBAAgB,EAClD,QAAQ,EAAE,iBAAiB,CAAC,aAAa,EAAE,UAAU,CAAC,EACtD,SAAS,CAAC,EAAE,UAAU,EACtB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAE1D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,MAAM,EACX,iBAAgB,aAAa,EAAO,KACnC,MA6EF,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL client for the Nhost JavaScript SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides functionality for executing GraphQL operations against
|
|
5
|
+
* a Hasura GraphQL API.
|
|
6
|
+
*/
|
|
7
|
+
import { createEnhancedFetch, FetchError, } from "../fetch";
|
|
8
|
+
/**
|
|
9
|
+
* Creates a GraphQL API client for interacting with a GraphQL endpoint.
|
|
10
|
+
*
|
|
11
|
+
* This client provides methods for executing queries and mutations against
|
|
12
|
+
* a GraphQL API, with support for middleware functions to handle authentication,
|
|
13
|
+
* error handling, and other cross-cutting concerns.
|
|
14
|
+
*
|
|
15
|
+
* @param url - Base URL for the GraphQL endpoint
|
|
16
|
+
* @param chainFunctions - Array of middleware functions for the fetch chain
|
|
17
|
+
* @returns GraphQL client with query and mutation methods
|
|
18
|
+
*/
|
|
19
|
+
export const createAPIClient = (url, chainFunctions = []) => {
|
|
20
|
+
const enhancedFetch = createEnhancedFetch(chainFunctions);
|
|
21
|
+
const executeOperation = async (request, options) => {
|
|
22
|
+
const response = await enhancedFetch(`${url}`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "application/json",
|
|
26
|
+
},
|
|
27
|
+
body: JSON.stringify(request),
|
|
28
|
+
...options,
|
|
29
|
+
});
|
|
30
|
+
const body = await response.text();
|
|
31
|
+
const data = (body ? JSON.parse(body) : {});
|
|
32
|
+
const resp = {
|
|
33
|
+
body: data,
|
|
34
|
+
status: response.status,
|
|
35
|
+
headers: response.headers,
|
|
36
|
+
};
|
|
37
|
+
if (data.errors) {
|
|
38
|
+
throw new FetchError(data, response.status, response.headers);
|
|
39
|
+
}
|
|
40
|
+
return resp;
|
|
41
|
+
};
|
|
42
|
+
function request(requestOrDocument, variablesOrOptions, options) {
|
|
43
|
+
if (typeof requestOrDocument === "object" && "kind" in requestOrDocument) {
|
|
44
|
+
const definition = requestOrDocument.definitions[0];
|
|
45
|
+
const request = {
|
|
46
|
+
query: requestOrDocument.loc?.source.body || "",
|
|
47
|
+
variables: variablesOrOptions,
|
|
48
|
+
operationName: definition && "name" in definition
|
|
49
|
+
? definition.name?.value
|
|
50
|
+
: undefined,
|
|
51
|
+
};
|
|
52
|
+
return executeOperation(request, options);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// Handle GraphQLRequest
|
|
56
|
+
const request = requestOrDocument;
|
|
57
|
+
const requestOptions = variablesOrOptions;
|
|
58
|
+
return executeOperation(request, requestOptions);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
request,
|
|
63
|
+
url,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/graphql/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAEL,mBAAmB,EACnB,UAAU,GAEX,MAAM,UAAU,CAAC;AAkFlB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,GAAW,EACX,iBAAkC,EAAE,EAC5B,EAAE;IACV,MAAM,aAAa,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAE1D,MAAM,gBAAgB,GAAG,KAAK,EAI5B,OAAmC,EACnC,OAAqB,EACmC,EAAE;QAC1D,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,GAAG,GAAG,EAAE,EAAE;YAC7C,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;YAC7B,GAAG,OAAO;SACX,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,MAAM,IAAI,GAAmC,CAC3C,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CACK,CAAC;QAEpC,MAAM,IAAI,GAAG;YACX,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;SAC1B,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAChE,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAWF,SAAS,OAAO,CACd,iBAEgD,EAChD,kBAA6C,EAC7C,OAAqB;QAErB,IAAI,OAAO,iBAAiB,KAAK,QAAQ,IAAI,MAAM,IAAI,iBAAiB,EAAE,CAAC;YACzE,MAAM,UAAU,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YAEpD,MAAM,OAAO,GAA+B;gBAC1C,KAAK,EAAE,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;gBAC/C,SAAS,EAAE,kBAAgC;gBAC3C,aAAa,EACX,UAAU,IAAI,MAAM,IAAI,UAAU;oBAChC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK;oBACxB,CAAC,CAAC,SAAS;aAChB,CAAC;YACF,OAAO,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,wBAAwB;YACxB,MAAM,OAAO,GAAG,iBAAiB,CAAC;YAClC,MAAM,cAAc,GAAG,kBAAiC,CAAC;YACzD,OAAO,gBAAgB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO;QACP,GAAG;KACM,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the main module to interact with Nhost's GraphQL service.
|
|
3
|
+
* Typically you would use this module via the main [Nhost client](main#createclient)
|
|
4
|
+
* but you can also use it directly if you have a specific use case.
|
|
5
|
+
*
|
|
6
|
+
* ## Import
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createClient } from "@nhost/nhost-js/graphql";
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* ## Usage
|
|
13
|
+
*
|
|
14
|
+
* The `request` method provides type-safe GraphQL operations with full TypeScript support.
|
|
15
|
+
* You can leverage generics to type your responses and use GraphQL document nodes for better
|
|
16
|
+
* integration with third-party libraries.
|
|
17
|
+
*
|
|
18
|
+
* ### Basic Usage
|
|
19
|
+
*
|
|
20
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,6,11-25}
|
|
21
|
+
*
|
|
22
|
+
* ### Using Variables
|
|
23
|
+
* You can pass variables to your GraphQL queries and mutations using the `variables` option:
|
|
24
|
+
*
|
|
25
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,6,195-228}
|
|
26
|
+
*
|
|
27
|
+
* This allows you to dynamically pass values to your queries and mutations, making them more
|
|
28
|
+
* flexible and reusable.
|
|
29
|
+
*
|
|
30
|
+
* ### Using String Queries with Type Generics
|
|
31
|
+
*
|
|
32
|
+
* You can type your GraphQL queries and responses using TypeScript generics:
|
|
33
|
+
*
|
|
34
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,6,97-123}
|
|
35
|
+
*
|
|
36
|
+
* ### Using GraphQL Document Nodes
|
|
37
|
+
*
|
|
38
|
+
* For better integration with third-party libraries like Apollo Client or The Guild's GraphQL
|
|
39
|
+
* Code Generator, you can use GraphQL document nodes created with `gql` template literal tags:
|
|
40
|
+
*
|
|
41
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,5,6,248-293}
|
|
42
|
+
*
|
|
43
|
+
* Using document nodes enables:
|
|
44
|
+
* - Better IDE support with syntax highlighting and validation
|
|
45
|
+
* - Integration with code generation tools
|
|
46
|
+
* - Compatibility with Apollo Client and other GraphQL libraries
|
|
47
|
+
*
|
|
48
|
+
* ## Error handling
|
|
49
|
+
*
|
|
50
|
+
* The SDK will throw errors in GraphQL operations that respond with an errors attribute
|
|
51
|
+
* with length > 0. The error will be an instance of `FetchError<GraphQLResponse>` and will
|
|
52
|
+
* contain the response body with the errors.
|
|
53
|
+
*
|
|
54
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2-4,6,313-353,367}
|
|
55
|
+
*
|
|
56
|
+
* This type extends the standard `Error` type so if you want to just log the error you can
|
|
57
|
+
* do so like this:
|
|
58
|
+
*
|
|
59
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2-4,6,371-394,399}
|
|
60
|
+
*
|
|
61
|
+
* @module graphql
|
|
62
|
+
* @packageDocumentation
|
|
63
|
+
*/
|
|
64
|
+
export * from "./client";
|
|
65
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/graphql/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAEH,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the main module to interact with Nhost's GraphQL service.
|
|
3
|
+
* Typically you would use this module via the main [Nhost client](main#createclient)
|
|
4
|
+
* but you can also use it directly if you have a specific use case.
|
|
5
|
+
*
|
|
6
|
+
* ## Import
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createClient } from "@nhost/nhost-js/graphql";
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* ## Usage
|
|
13
|
+
*
|
|
14
|
+
* The `request` method provides type-safe GraphQL operations with full TypeScript support.
|
|
15
|
+
* You can leverage generics to type your responses and use GraphQL document nodes for better
|
|
16
|
+
* integration with third-party libraries.
|
|
17
|
+
*
|
|
18
|
+
* ### Basic Usage
|
|
19
|
+
*
|
|
20
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,6,11-25}
|
|
21
|
+
*
|
|
22
|
+
* ### Using Variables
|
|
23
|
+
* You can pass variables to your GraphQL queries and mutations using the `variables` option:
|
|
24
|
+
*
|
|
25
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,6,195-228}
|
|
26
|
+
*
|
|
27
|
+
* This allows you to dynamically pass values to your queries and mutations, making them more
|
|
28
|
+
* flexible and reusable.
|
|
29
|
+
*
|
|
30
|
+
* ### Using String Queries with Type Generics
|
|
31
|
+
*
|
|
32
|
+
* You can type your GraphQL queries and responses using TypeScript generics:
|
|
33
|
+
*
|
|
34
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,6,97-123}
|
|
35
|
+
*
|
|
36
|
+
* ### Using GraphQL Document Nodes
|
|
37
|
+
*
|
|
38
|
+
* For better integration with third-party libraries like Apollo Client or The Guild's GraphQL
|
|
39
|
+
* Code Generator, you can use GraphQL document nodes created with `gql` template literal tags:
|
|
40
|
+
*
|
|
41
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2,5,6,248-293}
|
|
42
|
+
*
|
|
43
|
+
* Using document nodes enables:
|
|
44
|
+
* - Better IDE support with syntax highlighting and validation
|
|
45
|
+
* - Integration with code generation tools
|
|
46
|
+
* - Compatibility with Apollo Client and other GraphQL libraries
|
|
47
|
+
*
|
|
48
|
+
* ## Error handling
|
|
49
|
+
*
|
|
50
|
+
* The SDK will throw errors in GraphQL operations that respond with an errors attribute
|
|
51
|
+
* with length > 0. The error will be an instance of `FetchError<GraphQLResponse>` and will
|
|
52
|
+
* contain the response body with the errors.
|
|
53
|
+
*
|
|
54
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2-4,6,313-353,367}
|
|
55
|
+
*
|
|
56
|
+
* This type extends the standard `Error` type so if you want to just log the error you can
|
|
57
|
+
* do so like this:
|
|
58
|
+
*
|
|
59
|
+
* {@includeCode ./__tests__/docstrings.test.ts:2-4,6,371-394,399}
|
|
60
|
+
*
|
|
61
|
+
* @module graphql
|
|
62
|
+
* @packageDocumentation
|
|
63
|
+
*/
|
|
64
|
+
export * from "./client";
|
|
65
|
+
//# sourceMappingURL=index.js.map
|