graphlit-client 1.0.20260220002 → 1.0.20260220004
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/dist/client.d.ts +2 -0
- package/dist/client.js +6 -0
- package/dist/partial-errors.d.ts +47 -0
- package/dist/partial-errors.js +58 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -2629,3 +2629,5 @@ declare class Graphlit {
|
|
|
2629
2629
|
}
|
|
2630
2630
|
export { Graphlit };
|
|
2631
2631
|
export * as Types from "./generated/graphql-types.js";
|
|
2632
|
+
export { getPartialErrors, PARTIAL_ERRORS_KEY } from "./partial-errors.js";
|
|
2633
|
+
export type { PartialGraphQLError } from "./partial-errors.js";
|
package/dist/client.js
CHANGED
|
@@ -3,6 +3,7 @@ import jwt from "jsonwebtoken";
|
|
|
3
3
|
import { ApolloClient, InMemoryCache, createHttpLink, ApolloLink, ApolloError, } from "@apollo/client/core/index.js";
|
|
4
4
|
// Apollo retry link for resilient error handling
|
|
5
5
|
import { RetryLink } from "@apollo/client/link/retry/index.js";
|
|
6
|
+
import { attachPartialErrors } from "./partial-errors.js";
|
|
6
7
|
import * as Types from "./generated/graphql-types.js";
|
|
7
8
|
import * as Documents from "./generated/graphql-documents.js";
|
|
8
9
|
import { getServiceType, getModelName, getModelEnum } from "./model-mapping.js";
|
|
@@ -6125,6 +6126,7 @@ class Graphlit {
|
|
|
6125
6126
|
console.warn("GraphQL mutation returned partial data with errors:", result.errors
|
|
6126
6127
|
.map((err) => this.prettyPrintGraphQLError(err))
|
|
6127
6128
|
.join("\n"));
|
|
6129
|
+
attachPartialErrors(result.data, result.errors);
|
|
6128
6130
|
}
|
|
6129
6131
|
if (!result.data) {
|
|
6130
6132
|
throw new Error("No data returned from mutation.");
|
|
@@ -6141,6 +6143,7 @@ class Graphlit {
|
|
|
6141
6143
|
console.warn("GraphQL mutation returned partial data with errors:", error.graphQLErrors
|
|
6142
6144
|
.map((err) => this.prettyPrintGraphQLError(err))
|
|
6143
6145
|
.join("\n"));
|
|
6146
|
+
attachPartialErrors(networkResult.data, error.graphQLErrors);
|
|
6144
6147
|
return networkResult.data;
|
|
6145
6148
|
}
|
|
6146
6149
|
}
|
|
@@ -6179,6 +6182,7 @@ class Graphlit {
|
|
|
6179
6182
|
console.warn("GraphQL query returned partial data with errors:", result.errors
|
|
6180
6183
|
.map((err) => this.prettyPrintGraphQLError(err))
|
|
6181
6184
|
.join("\n"));
|
|
6185
|
+
attachPartialErrors(result.data, result.errors);
|
|
6182
6186
|
}
|
|
6183
6187
|
if (!result.data) {
|
|
6184
6188
|
throw new Error("No data returned from query.");
|
|
@@ -6195,6 +6199,7 @@ class Graphlit {
|
|
|
6195
6199
|
console.warn("GraphQL query returned partial data with errors:", error.graphQLErrors
|
|
6196
6200
|
.map((err) => this.prettyPrintGraphQLError(err))
|
|
6197
6201
|
.join("\n"));
|
|
6202
|
+
attachPartialErrors(networkResult.data, error.graphQLErrors);
|
|
6198
6203
|
return networkResult.data;
|
|
6199
6204
|
}
|
|
6200
6205
|
}
|
|
@@ -6216,3 +6221,4 @@ class Graphlit {
|
|
|
6216
6221
|
}
|
|
6217
6222
|
export { Graphlit };
|
|
6218
6223
|
export * as Types from "./generated/graphql-types.js";
|
|
6224
|
+
export { getPartialErrors, PARTIAL_ERRORS_KEY } from "./partial-errors.js";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Partial GraphQL error surfacing.
|
|
3
|
+
*
|
|
4
|
+
* When a GraphQL response contains both `data` and `errors`, the SDK returns
|
|
5
|
+
* the partial data so callers don't break. This module lets callers opt-in to
|
|
6
|
+
* inspecting the errors that came alongside that partial data.
|
|
7
|
+
*
|
|
8
|
+
* Errors are attached as a non-enumerable, Symbol-keyed property so they are
|
|
9
|
+
* invisible to JSON.stringify, Object.keys, for…in, and spread — no breaking
|
|
10
|
+
* changes for any existing consumer.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PARTIAL_ERRORS_KEY: unique symbol;
|
|
13
|
+
/**
|
|
14
|
+
* Simplified representation of a GraphQL error that doesn't require consumers
|
|
15
|
+
* to depend on the `graphql` package.
|
|
16
|
+
*/
|
|
17
|
+
export interface PartialGraphQLError {
|
|
18
|
+
message: string;
|
|
19
|
+
path?: ReadonlyArray<string | number>;
|
|
20
|
+
extensions?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Retrieve partial errors attached to an SDK result, if any.
|
|
24
|
+
*
|
|
25
|
+
* @returns The array of errors, or `undefined` if the result had no errors.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const result = await client.queryGitHubRepositories(input);
|
|
30
|
+
* const errors = getPartialErrors(result);
|
|
31
|
+
* if (errors) {
|
|
32
|
+
* console.warn("Partial errors:", errors);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function getPartialErrors(result: unknown): PartialGraphQLError[] | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Attach partial errors to an SDK result object. The property is
|
|
39
|
+
* non-enumerable so it won't appear in serialisation or iteration.
|
|
40
|
+
*
|
|
41
|
+
* @internal — only called from client.ts
|
|
42
|
+
*/
|
|
43
|
+
export declare function attachPartialErrors<T>(data: T, errors: ReadonlyArray<{
|
|
44
|
+
message: string;
|
|
45
|
+
path?: ReadonlyArray<string | number>;
|
|
46
|
+
extensions?: Record<string, unknown>;
|
|
47
|
+
}>): T;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Partial GraphQL error surfacing.
|
|
3
|
+
*
|
|
4
|
+
* When a GraphQL response contains both `data` and `errors`, the SDK returns
|
|
5
|
+
* the partial data so callers don't break. This module lets callers opt-in to
|
|
6
|
+
* inspecting the errors that came alongside that partial data.
|
|
7
|
+
*
|
|
8
|
+
* Errors are attached as a non-enumerable, Symbol-keyed property so they are
|
|
9
|
+
* invisible to JSON.stringify, Object.keys, for…in, and spread — no breaking
|
|
10
|
+
* changes for any existing consumer.
|
|
11
|
+
*/
|
|
12
|
+
// Symbol.for() is globally shared, so even if two copies of the SDK are loaded
|
|
13
|
+
// (e.g. CJS + ESM, or different versions) they will share the same key.
|
|
14
|
+
export const PARTIAL_ERRORS_KEY = Symbol.for("graphlit.partialErrors");
|
|
15
|
+
/**
|
|
16
|
+
* Retrieve partial errors attached to an SDK result, if any.
|
|
17
|
+
*
|
|
18
|
+
* @returns The array of errors, or `undefined` if the result had no errors.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const result = await client.queryGitHubRepositories(input);
|
|
23
|
+
* const errors = getPartialErrors(result);
|
|
24
|
+
* if (errors) {
|
|
25
|
+
* console.warn("Partial errors:", errors);
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function getPartialErrors(result) {
|
|
30
|
+
if (result != null &&
|
|
31
|
+
typeof result === "object" &&
|
|
32
|
+
PARTIAL_ERRORS_KEY in result) {
|
|
33
|
+
return result[PARTIAL_ERRORS_KEY];
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Attach partial errors to an SDK result object. The property is
|
|
39
|
+
* non-enumerable so it won't appear in serialisation or iteration.
|
|
40
|
+
*
|
|
41
|
+
* @internal — only called from client.ts
|
|
42
|
+
*/
|
|
43
|
+
export function attachPartialErrors(data, errors) {
|
|
44
|
+
if (data != null && typeof data === "object" && errors.length > 0) {
|
|
45
|
+
const simplified = errors.map((e) => ({
|
|
46
|
+
message: e.message,
|
|
47
|
+
...(e.path ? { path: e.path } : {}),
|
|
48
|
+
...(e.extensions ? { extensions: e.extensions } : {}),
|
|
49
|
+
}));
|
|
50
|
+
Object.defineProperty(data, PARTIAL_ERRORS_KEY, {
|
|
51
|
+
value: simplified,
|
|
52
|
+
enumerable: false,
|
|
53
|
+
writable: false,
|
|
54
|
+
configurable: true,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return data;
|
|
58
|
+
}
|