Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Context Types #12104

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
57 changes: 30 additions & 27 deletions .api-reports/api-report-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class ApolloClient<TCacheShape> implements DataProxy {
getResolvers(): Resolvers;
// (undocumented)
link: ApolloLink;
mutate<TData = any, TVariables extends OperationVariables = OperationVariables, TContext extends Record<string, any> = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>>(options: MutationOptions<TData, TVariables, TContext>): Promise<FetchResult<TData>>;
mutate<TData = any, TVariables extends OperationVariables = OperationVariables, TContext extends OperationContext = Partial<DefaultContext>, TCache extends ApolloCache<any> = ApolloCache<any>>(options: MutationOptions<TData, TVariables, TContext>): Promise<FetchResult<TData>>;
onClearStore(cb: () => Promise<any>): () => void;
onResetStore(cb: () => Promise<any>): () => void;
query<T = any, TVariables extends OperationVariables = OperationVariables>(options: QueryOptions<TVariables, T>): Promise<ApolloQueryResult<T>>;
Expand All @@ -133,7 +133,7 @@ export class ApolloClient<TCacheShape> implements DataProxy {
setLocalStateFragmentMatcher(fragmentMatcher: FragmentMatcher): void;
setResolvers(resolvers: Resolvers | Resolvers[]): void;
stop(): void;
subscribe<T = any, TVariables extends OperationVariables = OperationVariables>(options: SubscriptionOptions<TVariables, T>): Observable<FetchResult<T>>;
subscribe<T = any, TVariables extends OperationVariables = OperationVariables, TContext extends OperationContext = Partial<DefaultContext>>(options: SubscriptionOptions<TVariables, T, TContext>): Observable<FetchResult<T>>;
// (undocumented)
readonly typeDefs: ApolloClientOptions<TCacheShape>["typeDefs"];
// (undocumented)
Expand All @@ -153,7 +153,7 @@ export interface ApolloClientOptions<TCacheShape> {
// (undocumented)
credentials?: string;
// (undocumented)
defaultContext?: Partial<DefaultContext>;
defaultContext?: DefaultContext;
defaultOptions?: DefaultOptions;
devtools?: DevtoolsOptions;
// (undocumented)
Expand Down Expand Up @@ -565,7 +565,7 @@ type DeepPartialReadonlySet<T> = {} & ReadonlySet<DeepPartial<T>>;
type DeepPartialSet<T> = {} & Set<DeepPartial<T>>;

// @public (undocumented)
export interface DefaultContext extends Record<string, any> {
export interface DefaultContext extends OperationContext {
}

// Warning: (ae-forgotten-export) The symbol "KeyFieldsContext" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -812,9 +812,9 @@ export interface FetchMoreOptions<TData = any, TVariables = OperationVariables>
}

// @public (undocumented)
export interface FetchMoreQueryOptions<TVariables, TData = any> {
export interface FetchMoreQueryOptions<TVariables, TData = any, TContext extends OperationContext = Partial<DefaultContext>> {
// (undocumented)
context?: DefaultContext;
context?: TContext;
query?: DocumentNode | TypedDocumentNode<TData, TVariables>;
variables?: Partial<TVariables>;
}
Expand All @@ -823,7 +823,7 @@ export interface FetchMoreQueryOptions<TVariables, TData = any> {
export type FetchPolicy = "cache-first" | "network-only" | "cache-only" | "no-cache" | "standby";

// @public (undocumented)
export type FetchResult<TData = Record<string, any>, TContext = Record<string, any>, TExtensions = Record<string, any>> = SingleExecutionResult<TData, TContext, TExtensions> | ExecutionPatchResult<TData, TExtensions>;
export type FetchResult<TData = Record<string, any>, TContext extends OperationContext = DefaultContext, TExtensions = Record<string, any>> = SingleExecutionResult<TData, TContext, TExtensions> | ExecutionPatchResult<TData, TExtensions>;

// @public (undocumented)
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVars = Record<string, any>> {
Expand Down Expand Up @@ -992,9 +992,9 @@ const getInMemoryCacheMemoryInternals: (() => {
export { gql }

// @public (undocumented)
export interface GraphQLRequest<TVariables = Record<string, any>> {
export interface GraphQLRequest<TVariables = Record<string, any>, TContext extends OperationContext = Partial<DefaultContext>> {
// (undocumented)
context?: DefaultContext;
context?: TContext;
// (undocumented)
extensions?: Record<string, any>;
// (undocumented)
Expand Down Expand Up @@ -1386,7 +1386,7 @@ type Modifiers<T extends Record<string, any> = Record<string, unknown>> = Partia
}>;

// @public (undocumented)
interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> {
interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TContext extends OperationContext = Partial<DefaultContext>, TCache extends ApolloCache<any> = ApolloCache<any>> {
awaitRefetchQueries?: boolean;
context?: TContext;
errorPolicy?: ErrorPolicy;
Expand All @@ -1407,7 +1407,7 @@ export type MutationFetchPolicy = Extract<FetchPolicy, "network-only" | "no-cach
// Warning: (ae-forgotten-export) The symbol "MutationSharedOptions" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export interface MutationOptions<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> extends MutationSharedOptions<TData, TVariables, TContext, TCache> {
export interface MutationOptions<TData = any, TVariables = OperationVariables, TContext extends OperationContext = Partial<DefaultContext>, TCache extends ApolloCache<any> = ApolloCache<any>> extends MutationSharedOptions<TData, TVariables, TContext, TCache> {
mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;
}

Expand All @@ -1428,7 +1428,7 @@ export type MutationQueryReducersMap<T = {
// Warning: (ae-forgotten-export) The symbol "MutationBaseOptions" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
interface MutationSharedOptions<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> extends MutationBaseOptions<TData, TVariables, TContext, TCache> {
interface MutationSharedOptions<TData = any, TVariables = OperationVariables, TContext extends OperationContext = Partial<DefaultContext>, TCache extends ApolloCache<any> = ApolloCache<any>> extends MutationBaseOptions<TData, TVariables, TContext, TCache> {
fetchPolicy?: MutationFetchPolicy;
keepRootFields?: boolean;
}
Expand Down Expand Up @@ -1618,6 +1618,9 @@ export interface Operation {
variables: Record<string, any>;
}

// @public (undocumented)
export type OperationContext = Record<string, any>;

// @public (undocumented)
export type OperationVariables = Record<string, any>;

Expand All @@ -1629,7 +1632,7 @@ export type OptimisticStoreItem = {
};

// @public (undocumented)
type OptionsUnion<TData, TVariables extends OperationVariables, TContext> = WatchQueryOptions<TVariables, TData> | QueryOptions<TVariables, TData> | MutationOptions<TData, TVariables, TContext, any>;
type OptionsUnion<TData, TVariables extends OperationVariables, TContext extends OperationContext = Partial<DefaultContext>> = WatchQueryOptions<TVariables, TData> | QueryOptions<TVariables, TData> | MutationOptions<TData, TVariables, TContext, any>;

// @public (undocumented)
export function parseAndCheckHttpResponse(operations: Operation | Operation[]): (response: Response) => Promise<any>;
Expand Down Expand Up @@ -1838,7 +1841,7 @@ class QueryManager<TStore> {
keepRootFields?: boolean;
}, cache?: ApolloCache<TStore>): Promise<FetchResult<TData>>;
// (undocumented)
mutate<TData, TVariables extends OperationVariables, TContext extends Record<string, any>, TCache extends ApolloCache<any>>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TContext>): Promise<FetchResult<TData>>;
mutate<TData, TVariables extends OperationVariables, TContext extends OperationContext, TCache extends ApolloCache<any>>({ mutation, variables, optimisticResponse, updateQueries, refetchQueries, awaitRefetchQueries, update: updateWithProxyFn, onQueryUpdated, fetchPolicy, errorPolicy, keepRootFields, context, }: MutationOptions<TData, TVariables, TContext>): Promise<FetchResult<TData>>;
// (undocumented)
mutationStore?: {
[mutationId: string]: MutationStoreValue;
Expand All @@ -1858,7 +1861,7 @@ class QueryManager<TStore> {
// (undocumented)
readonly ssrMode: boolean;
// (undocumented)
startGraphQLSubscription<T = any>({ query, fetchPolicy, errorPolicy, variables, context, extensions, }: SubscriptionOptions): Observable<FetchResult<T>>;
startGraphQLSubscription<T = any, TVariables extends OperationVariables = OperationVariables, TContext extends OperationContext = Partial<DefaultContext>>({ query, fetchPolicy, errorPolicy, variables, context, extensions, }: SubscriptionOptions<TVariables, T, TContext>): Observable<FetchResult<T>>;
stop(): void;
// (undocumented)
stopQuery(queryId: string): void;
Expand Down Expand Up @@ -1897,10 +1900,10 @@ interface QueryManagerOptions<TStore> {
}

// @public
interface QueryOptions<TVariables = OperationVariables, TData = any> {
interface QueryOptions<TVariables = OperationVariables, TData = any, TContext extends OperationContext = Partial<DefaultContext>> {
// @deprecated
canonizeResults?: boolean;
context?: DefaultContext;
context?: TContext;
errorPolicy?: ErrorPolicy;
fetchPolicy?: FetchPolicy;
notifyOnNetworkStatusChange?: boolean;
Expand Down Expand Up @@ -2082,10 +2085,10 @@ export type ServerParseError = Error & {
export { setLogVerbosity }

// @public (undocumented)
interface SharedWatchQueryOptions<TVariables extends OperationVariables, TData> {
interface SharedWatchQueryOptions<TVariables extends OperationVariables, TData, TContext extends OperationContext = Partial<DefaultContext>> {
// @deprecated
canonizeResults?: boolean;
context?: DefaultContext;
context?: TContext;
errorPolicy?: ErrorPolicy;
fetchPolicy?: WatchQueryFetchPolicy;
initialFetchPolicy?: WatchQueryFetchPolicy;
Expand All @@ -2102,7 +2105,7 @@ interface SharedWatchQueryOptions<TVariables extends OperationVariables, TData>
}

// @public (undocumented)
export interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> {
export interface SingleExecutionResult<TData = Record<string, any>, TContext extends OperationContext = DefaultContext, TExtensions = Record<string, any>> {
// (undocumented)
context?: TContext;
// (undocumented)
Expand Down Expand Up @@ -2150,17 +2153,17 @@ class Stump extends Layer {
}

// @public (undocumented)
export type SubscribeToMoreOptions<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData> = {
export type SubscribeToMoreOptions<TData = any, TSubscriptionVariables = OperationVariables, TSubscriptionData = TData, TContext extends OperationContext = Partial<DefaultContext>> = {
document: DocumentNode | TypedDocumentNode<TSubscriptionData, TSubscriptionVariables>;
variables?: TSubscriptionVariables;
updateQuery?: UpdateQueryFn<TData, TSubscriptionVariables, TSubscriptionData>;
onError?: (error: Error) => void;
context?: DefaultContext;
context?: TContext;
};

// @public (undocumented)
export interface SubscriptionOptions<TVariables = OperationVariables, TData = any> {
context?: DefaultContext;
export interface SubscriptionOptions<TVariables = OperationVariables, TData = any, TContext extends OperationContext = Partial<DefaultContext>> {
context?: TContext;
errorPolicy?: ErrorPolicy;
extensions?: Record<string, any>;
fetchPolicy?: FetchPolicy;
Expand Down Expand Up @@ -2319,9 +2322,9 @@ interface WriteContext extends ReadMergeModifyContext {
// src/cache/inmemory/types.ts:139:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:116:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:117:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:138:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:382:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:139:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:383:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:287:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)
Expand Down
14 changes: 9 additions & 5 deletions .api-reports/api-report-errors.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export interface ApolloErrorOptions {
}>;
}

// Warning: (ae-forgotten-export) The symbol "OperationContext" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
interface DefaultContext extends Record<string, any> {
interface DefaultContext extends OperationContext {
}

// Warning: (ae-forgotten-export) The symbol "ExecutionPatchResultBase" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -100,11 +102,12 @@ interface ExecutionPatchResultBase {
hasNext?: boolean;
}

// Warning: (ae-forgotten-export) The symbol "DefaultContext" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "SingleExecutionResult" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ExecutionPatchResult" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type FetchResult<TData = Record<string, any>, TContext = Record<string, any>, TExtensions = Record<string, any>> = SingleExecutionResult<TData, TContext, TExtensions> | ExecutionPatchResult<TData, TExtensions>;
type FetchResult<TData = Record<string, any>, TContext extends OperationContext = DefaultContext, TExtensions = Record<string, any>> = SingleExecutionResult<TData, TContext, TExtensions> | ExecutionPatchResult<TData, TExtensions>;

// Warning: (ae-forgotten-export) The symbol "FetchResult" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -143,6 +146,9 @@ export function isApolloError(err: Error): err is ApolloError;
// @public (undocumented)
export type NetworkError = Error | ServerParseError | ServerError | null;

// @public (undocumented)
type OperationContext = Record<string, any>;

// @public (undocumented)
type Path = ReadonlyArray<string | number>;

Expand All @@ -163,10 +169,8 @@ type ServerParseError = Error & {
bodyText: string;
};

// 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>> {
interface SingleExecutionResult<TData = Record<string, any>, TContext extends OperationContext = DefaultContext, TExtensions = Record<string, any>> {
// (undocumented)
context?: TContext;
// (undocumented)
Expand Down
18 changes: 11 additions & 7 deletions .api-reports/api-report-link_batch-http.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ class BatchLink extends ApolloLink {
request(operation: Operation, forward?: NextLink): Observable<FetchResult> | null;
}

// Warning: (ae-forgotten-export) The symbol "OperationContext" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
interface DefaultContext extends Record<string, any> {
interface DefaultContext extends OperationContext {
}

// Warning: (ae-forgotten-export) The symbol "ExecutionPatchResultBase" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -135,18 +137,17 @@ interface ExecutionPatchResultBase {
hasNext?: boolean;
}

// Warning: (ae-forgotten-export) The symbol "DefaultContext" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "SingleExecutionResult" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ExecutionPatchResult" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type FetchResult<TData = Record<string, any>, TContext = Record<string, any>, TExtensions = Record<string, any>> = SingleExecutionResult<TData, TContext, TExtensions> | ExecutionPatchResult<TData, TExtensions>;
type FetchResult<TData = Record<string, any>, TContext extends OperationContext = DefaultContext, TExtensions = Record<string, any>> = SingleExecutionResult<TData, TContext, TExtensions> | ExecutionPatchResult<TData, TExtensions>;

// @public (undocumented)
interface GraphQLRequest<TVariables = Record<string, any>> {
// Warning: (ae-forgotten-export) The symbol "DefaultContext" needs to be exported by the entry point index.d.ts
//
interface GraphQLRequest<TVariables = Record<string, any>, TContext extends OperationContext = Partial<DefaultContext>> {
// (undocumented)
context?: DefaultContext;
context?: TContext;
// (undocumented)
extensions?: Record<string, any>;
// (undocumented)
Expand Down Expand Up @@ -211,6 +212,9 @@ interface Operation {
variables: Record<string, any>;
}

// @public (undocumented)
type OperationContext = Record<string, any>;

// @public (undocumented)
type Path = ReadonlyArray<string | number>;

Expand All @@ -231,7 +235,7 @@ 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>> {
interface SingleExecutionResult<TData = Record<string, any>, TContext extends OperationContext = DefaultContext, TExtensions = Record<string, any>> {
// (undocumented)
context?: TContext;
// (undocumented)
Expand Down
Loading