adaptic-backend 1.0.283 → 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 +35 -42
- package/client.d.ts +4 -12
- 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 -12
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js.map +1 -1
- package/esm/client.mjs +73 -49
- 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,50 +1,43 @@
|
|
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;
|
6
|
-
|
7
|
-
// Instead, we’ll load them dynamically.
|
8
|
-
let ApolloClient;
|
9
|
-
let ApolloError;
|
10
|
-
let gql;
|
11
|
-
let InMemoryCache;
|
12
|
-
let HttpLink;
|
13
|
-
let setContext;
|
14
|
-
let onError;
|
15
|
-
let split;
|
16
|
-
{
|
17
|
-
// Whether on the server or the client, load the module via require.
|
18
|
-
// (If you want to differentiate, you can—but in this case we use require() in both branches.)
|
19
|
-
const pkg = require("@apollo/client");
|
20
|
-
// If the package was imported via ESM interop, it might be on the .default property.
|
21
|
-
const clientPkg = pkg && pkg.__esModule ? pkg.default : pkg;
|
22
|
-
exports.ApolloClient = ApolloClient = clientPkg.ApolloClient;
|
23
|
-
exports.InMemoryCache = InMemoryCache = clientPkg.InMemoryCache;
|
24
|
-
exports.HttpLink = HttpLink = clientPkg.HttpLink;
|
25
|
-
exports.gql = gql = clientPkg.gql;
|
26
|
-
exports.ApolloError = ApolloError = clientPkg.ApolloError;
|
27
|
-
exports.split = split = clientPkg.split;
|
28
|
-
const contextPkg = require("@apollo/client/link/context/context.cjs");
|
29
|
-
exports.setContext = setContext = contextPkg.setContext;
|
30
|
-
const errorPkg = require("@apollo/client/link/error/error.cjs");
|
31
|
-
exports.onError = onError = errorPkg.onError;
|
32
|
-
}
|
33
|
-
// --- Apollo Client Setup ---
|
34
|
-
// Use the type-only alias (ApolloClientType) for type annotations.
|
35
|
-
let apolloClient = null;
|
8
|
+
const isServer = typeof window === "undefined";
|
36
9
|
/**
|
37
|
-
*
|
38
|
-
*
|
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.
|
39
12
|
*/
|
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");
|
19
|
+
return {
|
20
|
+
ApolloClient,
|
21
|
+
InMemoryCache,
|
22
|
+
HttpLink,
|
23
|
+
gql,
|
24
|
+
ApolloError,
|
25
|
+
split,
|
26
|
+
setContext: contextPkg.setContext,
|
27
|
+
onError: errorPkg.onError,
|
28
|
+
};
|
29
|
+
}
|
30
|
+
// Synchronously load and cache the runtime exports.
|
31
|
+
const apolloExports = loadApolloClientCjs();
|
32
|
+
// Singleton Apollo Client instance.
|
33
|
+
let apolloClient = null;
|
40
34
|
function initializeApollo() {
|
35
|
+
const { ApolloClient, InMemoryCache, HttpLink, setContext, onError } = apolloExports;
|
41
36
|
const isProduction = process.env.NODE_ENV === "production";
|
42
|
-
const httpUrl = isProduction
|
37
|
+
const httpUrl = isProduction || process.env.BACKEND_HTTPS_URL
|
43
38
|
? process.env.BACKEND_HTTPS_URL || "https://api.adaptic.ai/graphql"
|
44
39
|
: "http://localhost:4000/graphql";
|
45
|
-
// Create the HTTP link.
|
46
40
|
const httpLinkInstance = new HttpLink({ uri: httpUrl, fetch });
|
47
|
-
// Create the auth link.
|
48
41
|
const authLink = setContext((_, { headers }) => {
|
49
42
|
const token = process.env.SERVER_AUTH_TOKEN || "";
|
50
43
|
return {
|
@@ -55,24 +48,23 @@ function initializeApollo() {
|
|
55
48
|
},
|
56
49
|
};
|
57
50
|
});
|
58
|
-
// Create the error handling link.
|
59
51
|
const errorLink = onError(({ graphQLErrors, networkError }) => {
|
60
52
|
if (graphQLErrors) {
|
61
|
-
graphQLErrors.forEach(({ message, locations, path }) =>
|
53
|
+
graphQLErrors.forEach(({ message, locations, path }) => {
|
54
|
+
console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
|
55
|
+
});
|
62
56
|
}
|
63
57
|
if (networkError) {
|
64
58
|
console.error(`[Network error]: ${networkError}`);
|
65
59
|
}
|
66
60
|
});
|
67
|
-
// Combine the links and initialize the Apollo Client.
|
68
61
|
return new ApolloClient({
|
69
62
|
link: errorLink.concat(authLink.concat(httpLinkInstance)),
|
70
63
|
cache: new InMemoryCache(),
|
71
64
|
});
|
72
65
|
}
|
73
66
|
/**
|
74
|
-
*
|
75
|
-
* @returns ApolloClient instance.
|
67
|
+
* Returns the singleton Apollo Client (synchronously).
|
76
68
|
*/
|
77
69
|
function getApolloClient() {
|
78
70
|
if (!apolloClient) {
|
@@ -80,6 +72,7 @@ function getApolloClient() {
|
|
80
72
|
}
|
81
73
|
return apolloClient;
|
82
74
|
}
|
83
|
-
// Export the singleton instance.
|
84
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;
|
85
78
|
//# sourceMappingURL=client.js.map
|
package/client.d.ts
CHANGED
@@ -1,18 +1,10 @@
|
|
1
1
|
import type { ApolloClient as ApolloClientType, InMemoryCache as InMemoryCacheType, HttpLink as HttpLinkType, NormalizedCacheObject } from "@apollo/client";
|
2
|
-
|
3
|
-
declare let ApolloError: any;
|
4
|
-
declare let gql: any;
|
5
|
-
declare let InMemoryCache: any;
|
6
|
-
declare let HttpLink: any;
|
7
|
-
declare let setContext: any;
|
8
|
-
declare let onError: any;
|
9
|
-
declare let split: any;
|
2
|
+
import type { DocumentNode } from "graphql";
|
10
3
|
/**
|
11
|
-
*
|
12
|
-
* @returns ApolloClient instance.
|
4
|
+
* Returns the singleton Apollo Client (synchronously).
|
13
5
|
*/
|
14
6
|
export declare function getApolloClient(): ApolloClientType<NormalizedCacheObject>;
|
15
7
|
export declare const client: ApolloClientType<NormalizedCacheObject>;
|
16
|
-
export
|
17
|
-
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, };
|
18
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,qBAAqB,EACrB,YAAY,GACb,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"client-esm.js","sourceRoot":"","sources":["../../src/client-esm.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,6EAA6E;AAC7E,6EAA6E;AAC7E,2EAA2E;AAC3E,8DAA8D;AAU9D,MAAM,QAAQ,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O,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,18 +1,10 @@
|
|
1
1
|
import type { ApolloClient as ApolloClientType, InMemoryCache as InMemoryCacheType, HttpLink as HttpLinkType, NormalizedCacheObject } from "@apollo/client";
|
2
|
-
|
3
|
-
declare let ApolloError: any;
|
4
|
-
declare let gql: any;
|
5
|
-
declare let InMemoryCache: any;
|
6
|
-
declare let HttpLink: any;
|
7
|
-
declare let setContext: any;
|
8
|
-
declare let onError: any;
|
9
|
-
declare let split: any;
|
2
|
+
import type { DocumentNode } from "graphql";
|
10
3
|
/**
|
11
|
-
*
|
12
|
-
* @returns ApolloClient instance.
|
4
|
+
* Returns the singleton Apollo Client (synchronously).
|
13
5
|
*/
|
14
6
|
export declare function getApolloClient(): ApolloClientType<NormalizedCacheObject>;
|
15
7
|
export declare const client: ApolloClientType<NormalizedCacheObject>;
|
16
|
-
export
|
17
|
-
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, };
|
18
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":"","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ACtB,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,46 +1,68 @@
|
|
1
|
-
// client.ts
|
2
|
-
//
|
3
|
-
//
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
let InMemoryCache;
|
8
|
-
let HttpLink;
|
9
|
-
let setContext;
|
10
|
-
let onError;
|
11
|
-
let split;
|
12
|
-
{
|
13
|
-
// Whether on the server or the client, load the module via require.
|
14
|
-
// (If you want to differentiate, you can—but in this case we use require() in both branches.)
|
15
|
-
const pkg = require("@apollo/client");
|
16
|
-
// If the package was imported via ESM interop, it might be on the .default property.
|
17
|
-
const clientPkg = pkg && pkg.__esModule ? pkg.default : pkg;
|
18
|
-
ApolloClient = clientPkg.ApolloClient;
|
19
|
-
InMemoryCache = clientPkg.InMemoryCache;
|
20
|
-
HttpLink = clientPkg.HttpLink;
|
21
|
-
gql = clientPkg.gql;
|
22
|
-
ApolloError = clientPkg.ApolloError;
|
23
|
-
split = clientPkg.split;
|
24
|
-
const contextPkg = require("@apollo/client/link/context/context.cjs");
|
25
|
-
setContext = contextPkg.setContext;
|
26
|
-
const errorPkg = require("@apollo/client/link/error/error.cjs");
|
27
|
-
onError = errorPkg.onError;
|
28
|
-
}
|
29
|
-
// --- Apollo Client Setup ---
|
30
|
-
// Use the type-only alias (ApolloClientType) for type annotations.
|
31
|
-
let apolloClient = null;
|
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";
|
32
7
|
/**
|
33
|
-
*
|
34
|
-
*
|
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().
|
35
11
|
*/
|
36
|
-
function
|
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
|
+
}
|
48
|
+
}
|
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;
|
56
|
+
}
|
57
|
+
// Singleton Apollo Client instance (asynchronous in this version).
|
58
|
+
let apolloClient = null;
|
59
|
+
async function initializeApollo() {
|
60
|
+
const { ApolloClient, InMemoryCache, HttpLink, setContext, onError } = await getApolloExports();
|
37
61
|
const isProduction = process.env.NODE_ENV === "production";
|
38
|
-
const httpUrl = isProduction
|
62
|
+
const httpUrl = isProduction || process.env.BACKEND_HTTPS_URL
|
39
63
|
? process.env.BACKEND_HTTPS_URL || "https://api.adaptic.ai/graphql"
|
40
64
|
: "http://localhost:4000/graphql";
|
41
|
-
// Create the HTTP link.
|
42
65
|
const httpLinkInstance = new HttpLink({ uri: httpUrl, fetch });
|
43
|
-
// Create the auth link.
|
44
66
|
const authLink = setContext((_, { headers }) => {
|
45
67
|
const token = process.env.SERVER_AUTH_TOKEN || "";
|
46
68
|
return {
|
@@ -51,33 +73,35 @@ function initializeApollo() {
|
|
51
73
|
},
|
52
74
|
};
|
53
75
|
});
|
54
|
-
// Create the error handling link.
|
55
76
|
const errorLink = onError(({ graphQLErrors, networkError }) => {
|
56
77
|
if (graphQLErrors) {
|
57
|
-
graphQLErrors.forEach(({ message, locations, path }) =>
|
78
|
+
graphQLErrors.forEach(({ message, locations, path }) => {
|
79
|
+
console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
|
80
|
+
});
|
58
81
|
}
|
59
82
|
if (networkError) {
|
60
83
|
console.error(`[Network error]: ${networkError}`);
|
61
84
|
}
|
62
85
|
});
|
63
|
-
// Combine the links and initialize the Apollo Client.
|
64
86
|
return new ApolloClient({
|
65
87
|
link: errorLink.concat(authLink.concat(httpLinkInstance)),
|
66
88
|
cache: new InMemoryCache(),
|
67
89
|
});
|
68
90
|
}
|
69
91
|
/**
|
70
|
-
*
|
71
|
-
*
|
92
|
+
* Returns the singleton Apollo Client.
|
93
|
+
* (You must await this call in your code.)
|
72
94
|
*/
|
73
|
-
export function getApolloClient() {
|
95
|
+
export async function getApolloClient() {
|
74
96
|
if (!apolloClient) {
|
75
|
-
apolloClient = initializeApollo();
|
97
|
+
apolloClient = await initializeApollo();
|
76
98
|
}
|
77
99
|
return apolloClient;
|
78
100
|
}
|
79
|
-
//
|
80
|
-
export const
|
81
|
-
//
|
82
|
-
export
|
83
|
-
|
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