Skip to content

Commit

Permalink
fixing more types
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Jul 8, 2024
1 parent 5e6b51d commit 6f005eb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/core/ApolloClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { invariant, newInvariantError } from "../utilities/globals/index.js";

import type { ExecutionResult, DocumentNode } from "graphql";
import type { DocumentNode, FormattedExecutionResult } from "graphql";

import type { FetchResult, GraphQLRequest } from "../link/core/index.js";
import { ApolloLink, execute } from "../link/core/index.js";
Expand Down Expand Up @@ -571,7 +571,9 @@ export class ApolloClient<TCacheShape> implements DataProxy {
this.devToolsHookCb = cb;
}

public __requestRaw(payload: GraphQLRequest): Observable<ExecutionResult> {
public __requestRaw(
payload: GraphQLRequest
): Observable<FormattedExecutionResult> {
return execute(this.link, payload);
}

Expand Down
6 changes: 3 additions & 3 deletions src/link/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GraphQLError, GraphQLFormattedError } from "graphql";
import type { GraphQLFormattedError } from "graphql";
import type { DocumentNode } from "graphql";
import type { DefaultContext } from "../../core/index.js";
export type { DocumentNode };
Expand All @@ -18,7 +18,7 @@ export interface ExecutionPatchInitialResult<
// if data is present, incremental is not
data: TData | null | undefined;
incremental?: never;
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
extensions?: TExtensions;
}

Expand All @@ -28,7 +28,7 @@ export interface IncrementalPayload<TData, TExtensions> {
data: TData | null;
label?: string;
path: Path;
errors?: ReadonlyArray<GraphQLError>;
errors?: ReadonlyArray<GraphQLFormattedError>;
extensions?: TExtensions;
}

Expand Down
4 changes: 2 additions & 2 deletions src/link/error/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ExecutionResult, GraphQLFormattedError } from "graphql";
import type { FormattedExecutionResult, GraphQLFormattedError } from "graphql";

import type { NetworkError } from "../../errors/index.js";
import { Observable } from "../../utilities/index.js";
Expand All @@ -8,7 +8,7 @@ import { ApolloLink } from "../core/index.js";
export interface ErrorResponse {
graphQLErrors?: ReadonlyArray<GraphQLFormattedError>;
networkError?: NetworkError;
response?: ExecutionResult;
response?: FormattedExecutionResult;
operation: Operation;
forward: NextLink;
}
Expand Down
13 changes: 8 additions & 5 deletions src/link/persisted-queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { invariant } from "../../utilities/globals/index.js";
import { print } from "../../utilities/index.js";
import type {
DocumentNode,
ExecutionResult,
FormattedExecutionResult,
GraphQLError,
GraphQLFormattedError,
} from "graphql";
Expand All @@ -28,7 +28,7 @@ export const VERSION = 1;
export interface ErrorResponse {
graphQLErrors?: ReadonlyArray<GraphQLFormattedError>;
networkError?: NetworkError;
response?: ExecutionResult;
response?: FormattedExecutionResult;
operation: Operation;
meta: ErrorMeta;
}
Expand Down Expand Up @@ -173,7 +173,7 @@ export const createPersistedQueryLink = (

const { query } = operation;

return new Observable((observer: Observer<ExecutionResult>) => {
return new Observable((observer: Observer<FormattedExecutionResult>) => {
let subscription: ObservableSubscription;
let retried = false;
let originalFetchOptions: any;
Expand All @@ -182,7 +182,10 @@ export const createPersistedQueryLink = (
{
response,
networkError,
}: { response?: ExecutionResult; networkError?: ServerError },
}: {
response?: FormattedExecutionResult;
networkError?: ServerError;
},
cb: () => void
) => {
if (!retried && ((response && response.errors) || networkError)) {
Expand Down Expand Up @@ -251,7 +254,7 @@ export const createPersistedQueryLink = (
cb();
};
const handler = {
next: (response: ExecutionResult) => {
next: (response: FormattedExecutionResult) => {
maybeRetry({ response }, () => observer.next!(response));
},
error: (networkError: ServerError) => {
Expand Down
6 changes: 4 additions & 2 deletions src/link/subscriptions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
// THE SOFTWARE.

import { print } from "../../utilities/index.js";
import type { Client } from "graphql-ws";
import type { Client, Sink } from "graphql-ws";

import type { Operation, FetchResult } from "../core/index.js";
import { ApolloLink } from "../core/index.js";
import { isNonNullObject, Observable } from "../../utilities/index.js";
import { ApolloError } from "../../errors/index.js";
import type { FormattedExecutionResult } from "graphql";

// https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close_event
function isLikeCloseEvent(val: unknown): val is CloseEvent {
Expand Down Expand Up @@ -80,7 +81,8 @@ export class GraphQLWsLink extends ApolloLink {
})
);
},
}
// casting around a wrong type in graphql-ws, which incorrectly expects `Sink<ExecutionResult>`
} satisfies Sink<FormattedExecutionResult> as any
);
});
}
Expand Down

0 comments on commit 6f005eb

Please sign in to comment.