Skip to content

Commit

Permalink
Change usages of the GraphQLError type to GraphQLFormattedError. (#…
Browse files Browse the repository at this point in the history
…11789)

* post-process errors received from responses into GraphQLError instances

* adjust types, add test

* fixing more types

* Clean up Prettier, Size-limit, and Api-Extractor

* remove runtime components

* add eslint rule

* Clean up Prettier, Size-limit, and Api-Extractor

* adjust some more

* adjustments

* change patch level

---------

Co-authored-by: phryneas <[email protected]>
  • Loading branch information
phryneas and phryneas authored Jul 9, 2024
1 parent 1b23337 commit 5793301
Show file tree
Hide file tree
Showing 39 changed files with 442 additions and 345 deletions.
35 changes: 17 additions & 18 deletions .api-reports/api-report-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { disableExperimentalFragmentVariables } from 'graphql-tag';
import { disableFragmentWarnings } from 'graphql-tag';
import type { DocumentNode } from 'graphql';
import { enableExperimentalFragmentVariables } from 'graphql-tag';
import type { ExecutionResult } from 'graphql';
import type { FieldNode } from 'graphql';
import type { FormattedExecutionResult } from 'graphql';
import type { FragmentDefinitionNode } from 'graphql';
import { gql } from 'graphql-tag';
import type { GraphQLError } from 'graphql';
import type { GraphQLErrorExtensions } from 'graphql';
import type { GraphQLFormattedError } from 'graphql';
import type { InlineFragmentNode } from 'graphql';
import { InvariantError } from 'ts-invariant';
import { Observable } from 'zen-observable-ts';
Expand Down Expand Up @@ -94,7 +94,7 @@ export class ApolloClient<TCacheShape> implements DataProxy {
__actionHookForDevTools(cb: () => any): void;
constructor(options: ApolloClientOptions<TCacheShape>);
// (undocumented)
__requestRaw(payload: GraphQLRequest): Observable<ExecutionResult>;
__requestRaw(payload: GraphQLRequest): Observable<FormattedExecutionResult>;
addResolvers(resolvers: Resolvers | Resolvers[]): void;
// (undocumented)
cache: ApolloCache<TCacheShape>;
Expand Down Expand Up @@ -179,17 +179,15 @@ export class ApolloError extends Error {
// Warning: (ae-forgotten-export) The symbol "ApolloErrorOptions" needs to be exported by the entry point index.d.ts
constructor({ graphQLErrors, protocolErrors, clientErrors, networkError, errorMessage, extraInfo, }: ApolloErrorOptions);
cause: ({
message: string;
extensions?: GraphQLErrorExtensions[];
} & Partial<Error>) | null;
readonly message: string;
extensions?: GraphQLErrorExtensions[] | GraphQLFormattedError["extensions"];
} & Omit<Partial<Error> & Partial<GraphQLFormattedError>, "extensions">) | null;
// (undocumented)
clientErrors: ReadonlyArray<Error>;
// (undocumented)
extraInfo: any;
// Warning: (ae-forgotten-export) The symbol "GraphQLErrors" needs to be exported by the entry point index.d.ts
//
// (undocumented)
graphQLErrors: GraphQLErrors;
graphQLErrors: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
message: string;
// (undocumented)
Expand All @@ -212,7 +210,7 @@ interface ApolloErrorOptions {
// (undocumented)
extraInfo?: any;
// (undocumented)
graphQLErrors?: ReadonlyArray<GraphQLError>;
graphQLErrors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
networkError?: Error | ServerParseError | ServerError | null;
// (undocumented)
Expand Down Expand Up @@ -266,7 +264,7 @@ export interface ApolloQueryResult<T> {
// (undocumented)
data: T;
error?: ApolloError;
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
loading: boolean;
// (undocumented)
Expand Down Expand Up @@ -776,7 +774,7 @@ export interface ExecutionPatchInitialResult<TData = Record<string, any>, TExten
// (undocumented)
data: TData | null | undefined;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -993,9 +991,6 @@ const getInMemoryCacheMemoryInternals: (() => {

export { gql }

// @public (undocumented)
type GraphQLErrors = ReadonlyArray<GraphQLError>;

// @public (undocumented)
export interface GraphQLRequest<TVariables = Record<string, any>> {
// (undocumented)
Expand Down Expand Up @@ -1080,7 +1075,7 @@ export interface IncrementalPayload<TData, TExtensions> {
// (undocumented)
data: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -1712,7 +1707,7 @@ class QueryInfo {
// (undocumented)
getDiff(): Cache_2.DiffResult<any>;
// (undocumented)
graphQLErrors?: ReadonlyArray<GraphQLError>;
graphQLErrors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
init(query: {
document: DocumentNode;
Expand Down Expand Up @@ -2089,11 +2084,15 @@ interface SharedWatchQueryOptions<TVariables extends OperationVariables, TData>
}

// @public (undocumented)
export interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> extends ExecutionResult<TData, TExtensions> {
export interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> {
// (undocumented)
context?: TContext;
// (undocumented)
data?: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
}

// @public (undocumented)
Expand Down
24 changes: 14 additions & 10 deletions .api-reports/api-report-errors.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
```ts

import type { ExecutionResult } from 'graphql';
import type { GraphQLError } from 'graphql';
import type { GraphQLErrorExtensions } from 'graphql';
import type { GraphQLFormattedError } from 'graphql';

// @public (undocumented)
export class ApolloError extends Error {
constructor({ graphQLErrors, protocolErrors, clientErrors, networkError, errorMessage, extraInfo, }: ApolloErrorOptions);
cause: ({
message: string;
extensions?: GraphQLErrorExtensions[];
} & Partial<Error>) | null;
readonly message: string;
extensions?: GraphQLErrorExtensions[] | GraphQLFormattedError["extensions"];
} & Omit<Partial<Error> & Partial<GraphQLFormattedError>, "extensions">) | null;
// (undocumented)
clientErrors: ReadonlyArray<Error>;
// (undocumented)
extraInfo: any;
// (undocumented)
graphQLErrors: GraphQLErrors;
graphQLErrors: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
message: string;
// (undocumented)
Expand All @@ -46,7 +46,7 @@ export interface ApolloErrorOptions {
// (undocumented)
extraInfo?: any;
// (undocumented)
graphQLErrors?: ReadonlyArray<GraphQLError>;
graphQLErrors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
networkError?: Error | ServerParseError | ServerError | null;
// (undocumented)
Expand Down Expand Up @@ -81,7 +81,7 @@ interface ExecutionPatchInitialResult<TData = Record<string, any>, TExtensions =
// (undocumented)
data: TData | null | undefined;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -113,7 +113,7 @@ type FetchResultWithSymbolExtensions<T> = FetchResult<T> & {
extensions: Record<string | symbol, any>;
};

// @public (undocumented)
// @public @deprecated (undocumented)
export type GraphQLErrors = ReadonlyArray<GraphQLError>;

// Warning: (ae-forgotten-export) The symbol "FetchResultWithSymbolExtensions" needs to be exported by the entry point index.d.ts
Expand All @@ -126,7 +126,7 @@ interface IncrementalPayload<TData, TExtensions> {
// (undocumented)
data: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -166,11 +166,15 @@ type ServerParseError = Error & {
// Warning: (ae-forgotten-export) The symbol "DefaultContext" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> extends ExecutionResult<TData, TExtensions> {
interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> {
// (undocumented)
context?: TContext;
// (undocumented)
data?: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
}

// (No @packageDocumentation comment for this package)
Expand Down
13 changes: 8 additions & 5 deletions .api-reports/api-report-link_batch-http.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import type { ASTNode } from 'graphql';
import type { DocumentNode } from 'graphql';
import type { ExecutionResult } from 'graphql';
import type { GraphQLError } from 'graphql';
import type { GraphQLFormattedError } from 'graphql';
import { Observable } from 'zen-observable-ts';
import type { Observer } from 'zen-observable-ts';

Expand Down Expand Up @@ -117,7 +116,7 @@ interface ExecutionPatchInitialResult<TData = Record<string, any>, TExtensions =
// (undocumented)
data: TData | null | undefined;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -179,7 +178,7 @@ interface IncrementalPayload<TData, TExtensions> {
// (undocumented)
data: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -232,11 +231,15 @@ interface Printer {
type RequestHandler = (operation: Operation, forward: NextLink) => Observable<FetchResult> | null;

// @public (undocumented)
interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> extends ExecutionResult<TData, TExtensions> {
interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> {
// (undocumented)
context?: TContext;
// (undocumented)
data?: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
}

// @public (undocumented)
Expand Down
13 changes: 8 additions & 5 deletions .api-reports/api-report-link_batch.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
```ts

import type { DocumentNode } from 'graphql';
import type { ExecutionResult } from 'graphql';
import type { GraphQLError } from 'graphql';
import type { GraphQLFormattedError } from 'graphql';
import { Observable } from 'zen-observable-ts';
import type { Observer } from 'zen-observable-ts';

Expand Down Expand Up @@ -107,7 +106,7 @@ interface ExecutionPatchInitialResult<TData = Record<string, any>, TExtensions =
// (undocumented)
data: TData | null | undefined;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -153,7 +152,7 @@ interface IncrementalPayload<TData, TExtensions> {
// (undocumented)
data: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -208,11 +207,15 @@ type Path = ReadonlyArray<string | number>;
type RequestHandler = (operation: Operation, forward: NextLink) => Observable<FetchResult> | null;

// @public (undocumented)
interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> extends ExecutionResult<TData, TExtensions> {
interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> {
// (undocumented)
context?: TContext;
// (undocumented)
data?: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
}

// (No @packageDocumentation comment for this package)
Expand Down
13 changes: 8 additions & 5 deletions .api-reports/api-report-link_context.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
```ts

import type { DocumentNode } from 'graphql';
import type { ExecutionResult } from 'graphql';
import type { GraphQLError } from 'graphql';
import type { GraphQLFormattedError } from 'graphql';
import { Observable } from 'zen-observable-ts';
import type { Observer } from 'zen-observable-ts';

Expand Down Expand Up @@ -80,7 +79,7 @@ interface ExecutionPatchInitialResult<TData = Record<string, any>, TExtensions =
// (undocumented)
data: TData | null | undefined;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -124,7 +123,7 @@ interface IncrementalPayload<TData, TExtensions> {
// (undocumented)
data: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -169,11 +168,15 @@ type RequestHandler = (operation: Operation, forward: NextLink) => Observable<Fe
export function setContext(setter: ContextSetter): ApolloLink;

// @public (undocumented)
interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> extends ExecutionResult<TData, TExtensions> {
interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> {
// (undocumented)
context?: TContext;
// (undocumented)
data?: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
}

// (No @packageDocumentation comment for this package)
Expand Down
13 changes: 8 additions & 5 deletions .api-reports/api-report-link_core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
```ts

import type { DocumentNode } from 'graphql';
import type { ExecutionResult } from 'graphql';
import type { GraphQLError } from 'graphql';
import type { GraphQLFormattedError } from 'graphql';
import { Observable } from 'zen-observable-ts';
import type { Observer } from 'zen-observable-ts';

Expand Down Expand Up @@ -83,7 +82,7 @@ export interface ExecutionPatchInitialResult<TData = Record<string, any>, TExten
// (undocumented)
data: TData | null | undefined;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -126,7 +125,7 @@ export interface IncrementalPayload<TData, TExtensions> {
// (undocumented)
data: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
// (undocumented)
Expand Down Expand Up @@ -164,11 +163,15 @@ export type Path = ReadonlyArray<string | number>;
export type RequestHandler = (operation: Operation, forward: NextLink) => Observable<FetchResult> | null;

// @public (undocumented)
export interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> extends ExecutionResult<TData, TExtensions> {
export interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> {
// (undocumented)
context?: TContext;
// (undocumented)
data?: TData | null;
// (undocumented)
errors?: ReadonlyArray<GraphQLFormattedError>;
// (undocumented)
extensions?: TExtensions;
}

// @public (undocumented)
Expand Down
Loading

0 comments on commit 5793301

Please sign in to comment.