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 handler names for useSubscription hook #10134

Merged
merged 9 commits into from Sep 28, 2022

Conversation

jerelmiller
Copy link
Member

Closes #10116

With the addition of onError (#9495), the names of the other on* methods (onSubscriptionData and onSubscriptionComplete) are in a bit of misalignment with each other. This PR seeks to unify the names of the other two on* methods with onError to feel cohesive. This PR deprecates the onSubscriptionData and onSubscriptionComplete functions with a warning. Passing both onSubscriptionData and onData or onSubscriptionComplete and onComplete will also result in a warning explaining that only one of them will be used.

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@apollo-cla
Copy link

@jerelmiller: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@jerelmiller jerelmiller changed the title Issue 10116 update hook names Issue 10116 update handler names Sep 27, 2022
@jerelmiller jerelmiller changed the title Issue 10116 update handler names Update handler names for useSubscription hook Sep 27, 2022
@jerelmiller
Copy link
Member Author

I'm not sure what the release strategy is for this, but since onError was added for 3.7, I figured I'd start with opening this PR against that branch. Feel free to update if this feels like something that should be in a followup version.

@jerelmiller
Copy link
Member Author

Should I consider updating documentation for useSubscription as part of this PR as well?

Copy link
Member

@alessbell alessbell left a comment

Choose a reason for hiding this comment

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

I like this approach (and three cheers for first PR!! 🎉)

Do we already have a separate ticket for updating the docs? Seems like it shouldn't be a big diff so feel free to include it here or we can take care of it in a follow-up, e.g. copying the way Resolvers is marked as deprecated in the testing API docs. (Incidentally it looks like onSubscriptionComplete is currently missing.)

@@ -202,6 +202,11 @@ export type MutationTuple<

/* Subscription types */

export interface OnDataOptions<TData = any> {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: could also have OnDataOptions extend OnSubscriptionDataOptions until the latter is removed to ensure the types don't diverge before intended.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's not a bad idea, though I go back and forth on this. I hesitate changing it only because we call these separately, so a divergence might be natural. In fact, one tweak I made from onSubscriptionData is that I called the option data instead of subscriptionData to better align with the updated name of the function.

It's a coin toss, so let me know if you feel strongly and I'd be happy to update.

@jerelmiller
Copy link
Member Author

@alessbell I'll go ahead and include it in this PR. Doesn't look like it will be much to change it. Plus it gives me a chance to add another commit to hopefully kick off the tests again 😆 (I'm hoping me logging in fixed that).

@jerelmiller
Copy link
Member Author

@alessbell looks like that fixed it! Tests are now running. Turns out there is also the Subscription component to worry about, so this gave me a chance to add tests for that as well. This should be good to go otherwise. Thanks so much for reviewing!

@jerelmiller jerelmiller force-pushed the issue-10116-update-hook-names branch 2 times, most recently from d652257 to 6573551 Compare September 27, 2022 21:50
@jerelmiller
Copy link
Member Author

I seem to be victim to some flaky tests or something 🤔 . Seems a test or two times out when running the full suite, but it seems to change each run. Any ideas on how I might be able to get these to pass? I'm able to run the full suite locally with success which makes this a tad harder to debug.

@alessbell
Copy link
Member

I seem to be victim to some flaky tests or something 🤔 . Seems a test or two times out when running the full suite, but it seems to change each run. Any ideas on how I might be able to get these to pass? I'm able to run the full suite locally with success which makes this a tad harder to debug.

Now that I've merged #10140 (thanks for the review!) and merged main into release-3.7 (+ fixed some conflicts), I'm hoping that when you rebase/do a merge commit here the tests turn green 🤞

@jerelmiller
Copy link
Member Author

@alessbell woohoo! Looks like that did it. This should be ready to go. Thanks for getting that in!

@@ -202,6 +202,11 @@ export type MutationTuple<

/* Subscription types */

export interface OnDataOptions<TData = any> {
client: ApolloClient<object>;
data: SubscriptionResult<TData>;
Copy link
Member Author

Choose a reason for hiding this comment

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

Something I discovered when writing tests for the Subscription component is that this has a data property on it, which means accessing that data is via options.data.data. Do we feel the double data.data is too weird? This was called subscriptionData in onSubscriptionData, but I changed it to better align with the new name of the hook.

Example usage:

useSubscription(subscription, {
  onData: ({ data }) => {
    console.log(data.data)
  }
})

Thoughts on this? Are we ok with this?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like a potential future refinement - I don't mind creating an issue for visibility if you haven't already 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do!

Copy link
Member Author

Choose a reason for hiding this comment

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

Added this issue in #10142

@alessbell
Copy link
Member

@jerelmiller great! This is good to squash+merge in that case 🎉

@jerelmiller jerelmiller merged commit 184ebc0 into release-3.7 Sep 28, 2022
@jerelmiller jerelmiller deleted the issue-10116-update-hook-names branch September 28, 2022 18:19
jerelmiller added a commit that referenced this pull request Sep 30, 2022
jerelmiller added a commit that referenced this pull request Sep 30, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

change onSubscriptionData and onSubscriptionComplete to onData and onComplete
3 participants