-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
@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/ |
I'm not sure what the release strategy is for this, but since |
Should I consider updating documentation for |
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@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). |
@alessbell looks like that fixed it! Tests are now running. Turns out there is also the |
d652257
to
6573551
Compare
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. |
904793a
to
ca9efd9
Compare
Now that I've merged #10140 (thanks for the review!) and merged |
…ptionComplete' option (#10116)
ca9efd9
to
2c61dca
Compare
@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>; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
There was a problem hiding this comment.
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
@jerelmiller great! This is good to squash+merge in that case 🎉 |
Closes #10116
With the addition of
onError
(#9495), the names of the other on* methods (onSubscriptionData
andonSubscriptionComplete
) are in a bit of misalignment with each other. This PR seeks to unify the names of the other two on* methods withonError
to feel cohesive. This PR deprecates theonSubscriptionData
andonSubscriptionComplete
functions with a warning. Passing bothonSubscriptionData
andonData
oronSubscriptionComplete
andonComplete
will also result in a warning explaining that only one of them will be used.Checklist: