adaptic-backend 1.0.284 → 1.0.285
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/client-esm.d.ts +21 -0
- package/client.cjs +31 -65
- package/client.d.ts +4 -7
- package/esm/client-esm.d.ts +21 -0
- package/esm/client-esm.d.ts.map +1 -0
- package/esm/client-esm.js.map +1 -0
- package/esm/client.d.ts +4 -7
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js.map +1 -1
- package/esm/client.mjs +70 -65
- package/package.json +1 -1
package/client-esm.d.ts
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { ApolloClient as ApolloClientType, InMemoryCache as InMemoryCacheType, HttpLink as HttpLinkType, NormalizedCacheObject } from "@apollo/client";
|
2
|
+
import type { DocumentNode } from "graphql";
|
3
|
+
interface ApolloRuntimeExports {
|
4
|
+
ApolloClient: typeof import("@apollo/client").ApolloClient;
|
5
|
+
InMemoryCache: typeof import("@apollo/client").InMemoryCache;
|
6
|
+
HttpLink: typeof import("@apollo/client").HttpLink;
|
7
|
+
gql: typeof import("@apollo/client").gql;
|
8
|
+
ApolloError: any;
|
9
|
+
split: typeof import("@apollo/client").split;
|
10
|
+
setContext: any;
|
11
|
+
onError: any;
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* Returns the singleton Apollo Client.
|
15
|
+
* (You must await this call in your code.)
|
16
|
+
*/
|
17
|
+
export declare function getApolloClient(): Promise<ApolloClientType<NormalizedCacheObject>>;
|
18
|
+
export declare const clientPromise: Promise<ApolloClientType<NormalizedCacheObject>>;
|
19
|
+
export declare function getApolloRuntime(): Promise<ApolloRuntimeExports>;
|
20
|
+
export type { ApolloClientType, InMemoryCacheType, HttpLinkType, NormalizedCacheObject, DocumentNode, };
|
21
|
+
//# sourceMappingURL=client-esm.d.ts.map
|
package/client.cjs
CHANGED
@@ -1,78 +1,44 @@
|
|
1
1
|
"use strict";
|
2
|
-
// client.ts
|
2
|
+
// src/client-cjs.ts
|
3
|
+
// This file is written in TypeScript and intended to be compiled as a CommonJS module.
|
4
|
+
// It uses synchronous require() to load runtime modules and handles both server and client environments.
|
3
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
4
6
|
exports.split = exports.onError = exports.setContext = exports.HttpLink = exports.InMemoryCache = exports.gql = exports.ApolloError = exports.ApolloClient = exports.client = void 0;
|
5
7
|
exports.getApolloClient = getApolloClient;
|
8
|
+
const isServer = typeof window === "undefined";
|
6
9
|
/**
|
7
|
-
*
|
8
|
-
*
|
9
|
-
* hide the import path from bundlers (like Next.js) that might do static
|
10
|
-
* analysis on it.
|
10
|
+
* Synchronously loads the Apollo Client package and its submodules using require.
|
11
|
+
* We use string concatenation to “hide” the literal path from bundler static analysis.
|
11
12
|
*/
|
12
|
-
function
|
13
|
-
|
14
|
-
//
|
15
|
-
const
|
16
|
-
|
17
|
-
const
|
13
|
+
function loadApolloClientCjs() {
|
14
|
+
let pkg = require("@apollo/" + "client");
|
15
|
+
// No interop check is done here because we expect a pure CommonJS export.
|
16
|
+
const { ApolloClient, InMemoryCache, HttpLink, gql, ApolloError, split } = pkg;
|
17
|
+
const contextPkg = require("@apollo/client/link/context/" + "context.cjs");
|
18
|
+
const errorPkg = require("@apollo/client/link/error/" + "error.cjs");
|
18
19
|
return {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
ApolloClient,
|
21
|
+
InMemoryCache,
|
22
|
+
HttpLink,
|
23
|
+
gql,
|
24
|
+
ApolloError,
|
25
|
+
split,
|
26
|
+
setContext: contextPkg.setContext,
|
27
|
+
onError: errorPkg.onError,
|
26
28
|
};
|
27
29
|
}
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
*/
|
32
|
-
function loadSetContext() {
|
33
|
-
const contextCjs = require("@apollo/client/link/context/" + "context.cjs");
|
34
|
-
// If there's an ESM interop, it could be on contextCjs.default:
|
35
|
-
const maybeDefault = contextCjs.default || {};
|
36
|
-
// setContext might be on the top or on a default export:
|
37
|
-
return contextCjs.setContext || maybeDefault.setContext;
|
38
|
-
}
|
39
|
-
/**
|
40
|
-
* Similarly, load onError from @apollo/client/link/error/error.cjs
|
41
|
-
*/
|
42
|
-
function loadOnError() {
|
43
|
-
const errorCjs = require("@apollo/client/link/error/" + "error.cjs");
|
44
|
-
const maybeDefault = errorCjs.default || {};
|
45
|
-
return errorCjs.onError || maybeDefault.onError;
|
46
|
-
}
|
47
|
-
// Dynamically load all the runtime exports from @apollo/client and its submodules.
|
48
|
-
const { ApolloClient, InMemoryCache, HttpLink, gql, ApolloError, split, } = loadApolloClientPackage();
|
49
|
-
exports.ApolloClient = ApolloClient;
|
50
|
-
exports.InMemoryCache = InMemoryCache;
|
51
|
-
exports.HttpLink = HttpLink;
|
52
|
-
exports.gql = gql;
|
53
|
-
exports.ApolloError = ApolloError;
|
54
|
-
exports.split = split;
|
55
|
-
const setContext = loadSetContext();
|
56
|
-
exports.setContext = setContext;
|
57
|
-
const onError = loadOnError();
|
58
|
-
exports.onError = onError;
|
59
|
-
// --- Apollo Client Setup ---
|
60
|
-
// Use the type-only alias for type annotations.
|
30
|
+
// Synchronously load and cache the runtime exports.
|
31
|
+
const apolloExports = loadApolloClientCjs();
|
32
|
+
// Singleton Apollo Client instance.
|
61
33
|
let apolloClient = null;
|
62
|
-
/**
|
63
|
-
* Initializes a new Apollo Client instance.
|
64
|
-
* @returns ApolloClient instance.
|
65
|
-
*/
|
66
34
|
function initializeApollo() {
|
35
|
+
const { ApolloClient, InMemoryCache, HttpLink, setContext, onError } = apolloExports;
|
67
36
|
const isProduction = process.env.NODE_ENV === "production";
|
68
|
-
const httpUrl = isProduction
|
37
|
+
const httpUrl = isProduction || process.env.BACKEND_HTTPS_URL
|
69
38
|
? process.env.BACKEND_HTTPS_URL || "https://api.adaptic.ai/graphql"
|
70
39
|
: "http://localhost:4000/graphql";
|
71
|
-
// Create the HTTP link.
|
72
40
|
const httpLinkInstance = new HttpLink({ uri: httpUrl, fetch });
|
73
|
-
// Create the auth link.
|
74
41
|
const authLink = setContext((_, { headers }) => {
|
75
|
-
// Retrieve the token from environment variables or other secure storage.
|
76
42
|
const token = process.env.SERVER_AUTH_TOKEN || "";
|
77
43
|
return {
|
78
44
|
headers: {
|
@@ -82,24 +48,23 @@ function initializeApollo() {
|
|
82
48
|
},
|
83
49
|
};
|
84
50
|
});
|
85
|
-
// Create the error handling link.
|
86
51
|
const errorLink = onError(({ graphQLErrors, networkError }) => {
|
87
52
|
if (graphQLErrors) {
|
88
|
-
graphQLErrors.forEach(({ message, locations, path }) =>
|
53
|
+
graphQLErrors.forEach(({ message, locations, path }) => {
|
54
|
+
console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
|
55
|
+
});
|
89
56
|
}
|
90
57
|
if (networkError) {
|
91
58
|
console.error(`[Network error]: ${networkError}`);
|
92
59
|
}
|
93
60
|
});
|
94
|
-
// Combine the links and initialize the Apollo Client.
|
95
61
|
return new ApolloClient({
|
96
62
|
link: errorLink.concat(authLink.concat(httpLinkInstance)),
|
97
63
|
cache: new InMemoryCache(),
|
98
64
|
});
|
99
65
|
}
|
100
66
|
/**
|
101
|
-
*
|
102
|
-
* @returns ApolloClient instance.
|
67
|
+
* Returns the singleton Apollo Client (synchronously).
|
103
68
|
*/
|
104
69
|
function getApolloClient() {
|
105
70
|
if (!apolloClient) {
|
@@ -107,6 +72,7 @@ function getApolloClient() {
|
|
107
72
|
}
|
108
73
|
return apolloClient;
|
109
74
|
}
|
110
|
-
// Export the singleton instance for convenience.
|
111
75
|
exports.client = getApolloClient();
|
76
|
+
// Re-export the runtime implementations so they can be imported by other modules.
|
77
|
+
exports.ApolloClient = apolloExports.ApolloClient, exports.ApolloError = apolloExports.ApolloError, exports.gql = apolloExports.gql, exports.InMemoryCache = apolloExports.InMemoryCache, exports.HttpLink = apolloExports.HttpLink, exports.setContext = apolloExports.setContext, exports.onError = apolloExports.onError, exports.split = apolloExports.split;
|
112
78
|
//# sourceMappingURL=client.js.map
|
package/client.d.ts
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
import type { ApolloClient as ApolloClientType, InMemoryCache as InMemoryCacheType, HttpLink as HttpLinkType, NormalizedCacheObject } from "@apollo/client";
|
2
|
-
|
3
|
-
declare const setContext: any;
|
4
|
-
declare const onError: any;
|
2
|
+
import type { DocumentNode } from "graphql";
|
5
3
|
/**
|
6
|
-
*
|
7
|
-
* @returns ApolloClient instance.
|
4
|
+
* Returns the singleton Apollo Client (synchronously).
|
8
5
|
*/
|
9
6
|
export declare function getApolloClient(): ApolloClientType<NormalizedCacheObject>;
|
10
7
|
export declare const client: ApolloClientType<NormalizedCacheObject>;
|
11
|
-
export
|
12
|
-
export type { ApolloClientType, InMemoryCacheType, HttpLinkType, NormalizedCacheObject, };
|
8
|
+
export declare const ApolloClient: typeof ApolloClientType, ApolloError: any, gql: typeof import("graphql-tag").gql, InMemoryCache: typeof InMemoryCacheType, HttpLink: typeof HttpLinkType, setContext: any, onError: any, split: typeof import("@apollo/client").ApolloLink.split;
|
9
|
+
export type { ApolloClientType, InMemoryCacheType, HttpLinkType, NormalizedCacheObject, DocumentNode, };
|
13
10
|
//# sourceMappingURL=client.d.ts.map
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { ApolloClient as ApolloClientType, InMemoryCache as InMemoryCacheType, HttpLink as HttpLinkType, NormalizedCacheObject } from "@apollo/client";
|
2
|
+
import type { DocumentNode } from "graphql";
|
3
|
+
interface ApolloRuntimeExports {
|
4
|
+
ApolloClient: typeof import("@apollo/client").ApolloClient;
|
5
|
+
InMemoryCache: typeof import("@apollo/client").InMemoryCache;
|
6
|
+
HttpLink: typeof import("@apollo/client").HttpLink;
|
7
|
+
gql: typeof import("@apollo/client").gql;
|
8
|
+
ApolloError: any;
|
9
|
+
split: typeof import("@apollo/client").split;
|
10
|
+
setContext: any;
|
11
|
+
onError: any;
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* Returns the singleton Apollo Client.
|
15
|
+
* (You must await this call in your code.)
|
16
|
+
*/
|
17
|
+
export declare function getApolloClient(): Promise<ApolloClientType<NormalizedCacheObject>>;
|
18
|
+
export declare const clientPromise: Promise<ApolloClientType<NormalizedCacheObject>>;
|
19
|
+
export declare function getApolloRuntime(): Promise<ApolloRuntimeExports>;
|
20
|
+
export type { ApolloClientType, InMemoryCacheType, HttpLinkType, NormalizedCacheObject, DocumentNode, };
|
21
|
+
//# sourceMappingURL=client-esm.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"client-esm.d.ts","sourceRoot":"","sources":["../../src/client-esm.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,aAAa,IAAI,iBAAiB,EAClC,QAAQ,IAAI,YAAY,EACxB,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI5C,UAAU,oBAAoB;IAC5B,YAAY,EAAE,cAAc,gBAAgB,EAAE,YAAY,CAAC;IAC3D,aAAa,EAAE,cAAc,gBAAgB,EAAE,aAAa,CAAC;IAC7D,QAAQ,EAAE,cAAc,gBAAgB,EAAE,QAAQ,CAAC;IACnD,GAAG,EAAE,cAAc,gBAAgB,EAAE,GAAG,CAAC;IACzC,WAAW,EAAE,GAAG,CAAC;IACjB,KAAK,EAAE,cAAc,gBAAgB,EAAE,KAAK,CAAC;IAC7C,UAAU,EAAE,GAAG,CAAC;IAChB,OAAO,EAAE,GAAG,CAAC;CACd;AAqGD;;;GAGG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,CAAC,CAKxF;AAGD,eAAO,MAAM,aAAa,kDAAoB,CAAC;AAG/C,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAEtE;AAGD,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ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;gBAC7C,UAAU,EAAE,YAAY;aACzB;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,EAAE,aAAa,EAAE,YAAY,EAAO,EAAE,EAAE;QACjE,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAO,EAAE,EAAE;gBAC1D,OAAO,CAAC,KAAK,CACX,6BAA6B,OAAO,eAAe,SAAS,WAAW,IAAI,EAAE,CAC9E,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,IAAI,YAAY,EAAE,CAAC;YACjB,OAAO,CAAC,KAAK,CAAC,oBAAoB,YAAY,EAAE,CAAC,CAAC;QACpD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,YAAY,CAAC;QACtB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACzD,KAAK,EAAE,IAAI,aAAa,EAAE;KAC3B,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,iEAAiE;AACjE,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,EAAE,CAAC;AAE/C,4DAA4D;AAC5D,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,OAAO,gBAAgB,EAAE,CAAC;AAC5B,CAAC"}
|
package/esm/client.d.ts
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
import type { ApolloClient as ApolloClientType, InMemoryCache as InMemoryCacheType, HttpLink as HttpLinkType, NormalizedCacheObject } from "@apollo/client";
|
2
|
-
|
3
|
-
declare const setContext: any;
|
4
|
-
declare const onError: any;
|
2
|
+
import type { DocumentNode } from "graphql";
|
5
3
|
/**
|
6
|
-
*
|
7
|
-
* @returns ApolloClient instance.
|
4
|
+
* Returns the singleton Apollo Client (synchronously).
|
8
5
|
*/
|
9
6
|
export declare function getApolloClient(): ApolloClientType<NormalizedCacheObject>;
|
10
7
|
export declare const client: ApolloClientType<NormalizedCacheObject>;
|
11
|
-
export
|
12
|
-
export type { ApolloClientType, InMemoryCacheType, HttpLinkType, NormalizedCacheObject, };
|
8
|
+
export declare const ApolloClient: typeof ApolloClientType, ApolloError: any, gql: typeof import("graphql-tag").gql, InMemoryCache: typeof InMemoryCacheType, HttpLink: typeof HttpLinkType, setContext: any, onError: any, split: typeof import("@apollo/client").ApolloLink.split;
|
9
|
+
export type { ApolloClientType, InMemoryCacheType, HttpLinkType, NormalizedCacheObject, DocumentNode, };
|
13
10
|
//# sourceMappingURL=client.d.ts.map
|
package/esm/client.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,aAAa,IAAI,iBAAiB,EAClC,QAAQ,IAAI,YAAY,EACxB,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA8E5C;;GAEG;AACH,wBAAgB,eAAe,IAAI,gBAAgB,CAAC,qBAAqB,CAAC,CAKzE;AAED,eAAO,MAAM,MAAM,yCAAoB,CAAC;AAGxC,eAAO,MACL,YAAY,2BACZ,WAAW,OACX,GAAG,oCACH,aAAa,4BACb,QAAQ,uBACR,UAAU,OACV,OAAO,OACP,KAAK,kDACU,CAAC;AAGlB,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,EACrB,YAAY,GACb,CAAC"}
|
package/esm/client.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,uFAAuF;AACvF,yGAAyG;AAUzG,MAAM,QAAQ,GAAY,OAAO,MAAM,KAAK,WAAW,CAAC;AAcxD;;;GAGG;AACH,SAAS,mBAAmB;IAC1B,IAAI,GAAG,GAAG,OAAO,CAAC,UAAU,GAAG,QAAQ,CAAC,CAAC;IACzC,0EAA0E;IAC1E,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC/E,MAAM,UAAU,GAAG,OAAO,CAAC,8BAA8B,GAAG,aAAa,CAAC,CAAC;IAC3E,MAAM,QAAQ,GAAG,OAAO,CAAC,4BAA4B,GAAG,WAAW,CAAC,CAAC;IACrE,OAAO;QACL,YAAY;QACZ,aAAa;QACb,QAAQ;QACR,GAAG;QACH,WAAW;QACX,KAAK;QACL,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,OAAO,EAAE,QAAQ,CAAC,OAAO;KAC1B,CAAC;AACJ,CAAC;AAED,oDAAoD;AACpD,MAAM,aAAa,GAAyB,mBAAmB,EAAE,CAAC;AAElE,oCAAoC;AACpC,IAAI,YAAY,GAAmD,IAAI,CAAC;AAExE,SAAS,gBAAgB;IACvB,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC;IACrF,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;IAC3D,MAAM,OAAO,GACX,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,iBAA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e;IAC7B,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,gBAAgB,EAAE,CAAC;IACpC,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,EAAE,CAAC;AAExC,kFAAkF;AAClF,MAAM,CAAC,MAAM,EACX,YAAY,EACZ,WAAW,EACX,GAAG,EACH,aAAa,EACb,QAAQ,EACR,UAAU,EACV,OAAO,EACP,KAAK,GACN,GAAG,aAAa,CAAC"}
|
package/esm/client.mjs
CHANGED
@@ -1,66 +1,69 @@
|
|
1
|
-
// client.ts
|
1
|
+
// client-esm.ts
|
2
|
+
// This file avoids createRequire(import.meta.url) by using a simple if-check
|
3
|
+
// for server vs. client. On the server, we do a require() if it's available.
|
4
|
+
// On the client, we do a dynamic import(). We also do string concatenation
|
5
|
+
// to hide the literal import path from bundlers like Next.js.
|
6
|
+
const isServer = typeof window === "undefined";
|
2
7
|
/**
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
* analysis on it.
|
8
|
+
* Loads the Apollo Client package and its submodules.
|
9
|
+
* - On the server (if require is available): uses require().
|
10
|
+
* - On the client (browser): uses dynamic import().
|
7
11
|
*/
|
8
|
-
function
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
12
|
+
async function loadApolloClientEsm() {
|
13
|
+
if (isServer && typeof require !== "undefined") {
|
14
|
+
// --- Server path: require()
|
15
|
+
let pkg = require("@apollo/" + "client");
|
16
|
+
// We assume it's CommonJS. If there's an ESM interop wrapper, you might check pkg.default.
|
17
|
+
const { ApolloClient, InMemoryCache, HttpLink, gql, ApolloError, split } = pkg;
|
18
|
+
const contextPkg = require("@apollo/client/link/context/" + "context.cjs");
|
19
|
+
const errorPkg = require("@apollo/client/link/error/" + "error.cjs");
|
20
|
+
return {
|
21
|
+
ApolloClient,
|
22
|
+
InMemoryCache,
|
23
|
+
HttpLink,
|
24
|
+
gql,
|
25
|
+
ApolloError,
|
26
|
+
split,
|
27
|
+
setContext: contextPkg.setContext,
|
28
|
+
onError: errorPkg.onError,
|
29
|
+
};
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
// --- Client path: dynamic import
|
33
|
+
let pkg = await import("@apollo/client");
|
34
|
+
const { ApolloClient, InMemoryCache, HttpLink, gql, ApolloError, split } = pkg;
|
35
|
+
const contextPkg = await import("@apollo/client/link/context/" + "context.cjs");
|
36
|
+
const errorPkg = await import("@apollo/client/link/error/" + "error.cjs");
|
37
|
+
return {
|
38
|
+
ApolloClient,
|
39
|
+
InMemoryCache,
|
40
|
+
HttpLink,
|
41
|
+
gql,
|
42
|
+
ApolloError,
|
43
|
+
split,
|
44
|
+
setContext: contextPkg.setContext,
|
45
|
+
onError: errorPkg.onError,
|
46
|
+
};
|
47
|
+
}
|
34
48
|
}
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
return
|
49
|
+
// Cache the loaded runtime exports.
|
50
|
+
let apolloExports = null;
|
51
|
+
async function getApolloExports() {
|
52
|
+
if (!apolloExports) {
|
53
|
+
apolloExports = await loadApolloClientEsm();
|
54
|
+
}
|
55
|
+
return apolloExports;
|
42
56
|
}
|
43
|
-
//
|
44
|
-
const { ApolloClient, InMemoryCache, HttpLink, gql, ApolloError, split, } = loadApolloClientPackage();
|
45
|
-
const setContext = loadSetContext();
|
46
|
-
const onError = loadOnError();
|
47
|
-
// --- Apollo Client Setup ---
|
48
|
-
// Use the type-only alias for type annotations.
|
57
|
+
// Singleton Apollo Client instance (asynchronous in this version).
|
49
58
|
let apolloClient = null;
|
50
|
-
|
51
|
-
|
52
|
-
* @returns ApolloClient instance.
|
53
|
-
*/
|
54
|
-
function initializeApollo() {
|
59
|
+
async function initializeApollo() {
|
60
|
+
const { ApolloClient, InMemoryCache, HttpLink, setContext, onError } = await getApolloExports();
|
55
61
|
const isProduction = process.env.NODE_ENV === "production";
|
56
|
-
const httpUrl = isProduction
|
62
|
+
const httpUrl = isProduction || process.env.BACKEND_HTTPS_URL
|
57
63
|
? process.env.BACKEND_HTTPS_URL || "https://api.adaptic.ai/graphql"
|
58
64
|
: "http://localhost:4000/graphql";
|
59
|
-
// Create the HTTP link.
|
60
65
|
const httpLinkInstance = new HttpLink({ uri: httpUrl, fetch });
|
61
|
-
// Create the auth link.
|
62
66
|
const authLink = setContext((_, { headers }) => {
|
63
|
-
// Retrieve the token from environment variables or other secure storage.
|
64
67
|
const token = process.env.SERVER_AUTH_TOKEN || "";
|
65
68
|
return {
|
66
69
|
headers: {
|
@@ -70,33 +73,35 @@ function initializeApollo() {
|
|
70
73
|
},
|
71
74
|
};
|
72
75
|
});
|
73
|
-
// Create the error handling link.
|
74
76
|
const errorLink = onError(({ graphQLErrors, networkError }) => {
|
75
77
|
if (graphQLErrors) {
|
76
|
-
graphQLErrors.forEach(({ message, locations, path }) =>
|
78
|
+
graphQLErrors.forEach(({ message, locations, path }) => {
|
79
|
+
console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
|
80
|
+
});
|
77
81
|
}
|
78
82
|
if (networkError) {
|
79
83
|
console.error(`[Network error]: ${networkError}`);
|
80
84
|
}
|
81
85
|
});
|
82
|
-
// Combine the links and initialize the Apollo Client.
|
83
86
|
return new ApolloClient({
|
84
87
|
link: errorLink.concat(authLink.concat(httpLinkInstance)),
|
85
88
|
cache: new InMemoryCache(),
|
86
89
|
});
|
87
90
|
}
|
88
91
|
/**
|
89
|
-
*
|
90
|
-
*
|
92
|
+
* Returns the singleton Apollo Client.
|
93
|
+
* (You must await this call in your code.)
|
91
94
|
*/
|
92
|
-
export function getApolloClient() {
|
95
|
+
export async function getApolloClient() {
|
93
96
|
if (!apolloClient) {
|
94
|
-
apolloClient = initializeApollo();
|
97
|
+
apolloClient = await initializeApollo();
|
95
98
|
}
|
96
99
|
return apolloClient;
|
97
100
|
}
|
98
|
-
//
|
99
|
-
export const
|
100
|
-
//
|
101
|
-
export
|
102
|
-
|
101
|
+
// For convenience, export a promise that resolves to the client.
|
102
|
+
export const clientPromise = getApolloClient();
|
103
|
+
// Expose a helper to get all the runtime exports if needed.
|
104
|
+
export async function getApolloRuntime() {
|
105
|
+
return getApolloExports();
|
106
|
+
}
|
107
|
+
//# sourceMappingURL=client-esm.js.map
|
package/package.json
CHANGED