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

Fix operation.setContext() type #11756

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .api-reports/api-report-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,10 @@ export interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_batch-http.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_batch.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_core.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ export interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_error.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_http.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_persisted-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_remove-typename.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_retry.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-link_ws.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: Context) => Context;
setContext: {
(context: Partial<Context>): void;
(updateContext: (previousContext: Context) => Partial<Context>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-react_components.md
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-react_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-react_hoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-react_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-react_internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-react_ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-testing_core.md
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report-utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,10 @@ interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 4 additions & 1 deletion .api-reports/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,10 @@ export interface Operation {
// (undocumented)
query: DocumentNode;
// (undocumented)
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(updateContext: (previousContext: DefaultContext) => Partial<DefaultContext>): void;
};
// (undocumented)
variables: Record<string, any>;
}
Expand Down
5 changes: 5 additions & 0 deletions .changeset/strange-needles-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Fix operation.setContext() type
9 changes: 8 additions & 1 deletion src/link/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ export interface Operation {
variables: Record<string, any>;
operationName: string;
extensions: Record<string, any>;
setContext: (context: DefaultContext) => DefaultContext;
setContext: {
(context: Partial<DefaultContext>): void;
(
updateContext: (
previousContext: DefaultContext
) => Partial<DefaultContext>
): void;
};
getContext: () => DefaultContext;
}

Expand Down
4 changes: 2 additions & 2 deletions src/link/utils/createOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ export function createOperation(
operation: GraphQLRequest
): Operation {
let context = { ...starting };
const setContext = (next: any) => {
const setContext: Operation["setContext"] = (next) => {
if (typeof next === "function") {
context = { ...context, ...next(context) };
} else {
context = { ...context, ...next };
}
};
const getContext = () => ({ ...context });
const getContext: Operation["getContext"] = () => ({ ...context });

Object.defineProperty(operation, "setContext", {
enumerable: false,
Expand Down
Loading