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

Conversation

henryqdineen
Copy link
Contributor

I noticed couple issues with the Operation.setContext() types that I try to fix in this PR:

  • The function is a void and does not return DefaultContext
  • The type was missing an override where it accepts an updater function.

Copy link

netlify bot commented Apr 5, 2024

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit d2c81dc
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/66294b43876f0b0009bc2bb9
😎 Deploy Preview https://deploy-preview-11756--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

changeset-bot bot commented Apr 5, 2024

🦋 Changeset detected

Latest commit: d2c81dc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

src/link/core/types.ts Outdated Show resolved Hide resolved
@phryneas
Copy link
Member

phryneas commented Apr 5, 2024

While we're at it, could you please also add these adjustments?

--- a/src/link/utils/createOperation.ts
+++ b/src/link/utils/createOperation.ts
@@ -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,

Copy link
Member

@phryneas phryneas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, this is a great improvement!

Just so you're prepared for it: This PR will probably sit for a week or two, since we're essentially in a code freeze on the 3.9 branch as 3.10 is currently in RC state.

Co-authored-by: Lenz Weber-Tronic <mail@lenzw.de>
@henryqdineen
Copy link
Contributor Author

Just made the adjustments. Thanks! No rush.

@phryneas phryneas added the auto-cleanup 🤖 label Apr 15, 2024
@phryneas phryneas merged commit 60592e9 into apollographql:main Apr 24, 2024
33 checks passed
@github-actions github-actions bot mentioned this pull request Apr 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants