Add proper type inference by way of Subscription and SubscriptionWithHandler. #82
+199
−52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR would close #70 and #72 and, in my opinion, should be the feature cap for
v1
🎉 After @gugahoa's awesome GADT approach foruseSubscription
, I was really excited to port it over to theSubscription
component. However, as this issue demonstrates (thanks for opening @gugahoa) the@react.component
PPX has no idea what to do w/ locally abstract types. Bummer.I don't expect to see a fix for that in the near future, so, in the interest of getting
v1
out, I decided to expand the API surface to includeSubscription
andSubscriptionWithHandler
. The former will inferData(d)
as the parsed result of the subscription, while the latter will infer it as the accumulator'acc
type inferred through use of thehandler
prop. I hate that we have to increase API surface to get proper type inference, but I also think it's small enough (and likely not used a ton in comparison to the hook) that I can live with it.I added an example of using
SubscriptionWithHandler
to our subscription example to demonstrate usage. I had to create a new subscription type and resolver on the server sincesubscription-transport-ws
has memory leek issues with multiple clients using the same subscription: apollographql/subscriptions-transport-ws#433But hey, now we have some rad abstract art 😂
cc/ @Schmavery @gugahoa