UNPKG

graphlit-client

Version:
48 lines (47 loc) 1.63 kB
/** * Partial GraphQL error surfacing. * * When a GraphQL response contains both `data` and `errors`, the SDK returns * the partial data so callers don't break. This module lets callers opt-in to * inspecting the errors that came alongside that partial data. * * Errors are attached as a non-enumerable, Symbol-keyed property so they are * invisible to JSON.stringify, Object.keys, for…in, and spread — no breaking * changes for any existing consumer. */ export declare const PARTIAL_ERRORS_KEY: unique symbol; /** * Simplified representation of a GraphQL error that doesn't require consumers * to depend on the `graphql` package. */ export interface PartialGraphQLError { message: string; path?: ReadonlyArray<string | number>; extensions?: Record<string, unknown>; } /** * Retrieve partial errors attached to an SDK result, if any. * * @returns The array of errors, or `undefined` if the result had no errors. * * @example * ```ts * const result = await client.queryGitHubRepositories(input); * const errors = getPartialErrors(result); * if (errors) { * console.warn("Partial errors:", errors); * } * ``` */ export declare function getPartialErrors(result: unknown): PartialGraphQLError[] | undefined; /** * Attach partial errors to an SDK result object. The property is * non-enumerable so it won't appear in serialisation or iteration. * * @internal — only called from client.ts */ export declare function attachPartialErrors<T>(data: T, errors: ReadonlyArray<{ message: string; path?: ReadonlyArray<string | number>; extensions?: Record<string, unknown>; }>): T;