Improve useSubscription hook types#277
Open
aleksandrlat wants to merge 1 commit intorelay-tools:masterfrom
Open
Improve useSubscription hook types#277aleksandrlat wants to merge 1 commit intorelay-tools:masterfrom
aleksandrlat wants to merge 1 commit intorelay-tools:masterfrom
Conversation
useSubscription allows to omit `config.subscription` and `config.variables` if `opts.skip` is literally true. I.e. `subscription` and `variables` are optional only when we explicitly pass true to skip option: `useSubscription(config, { skip: true })`.
But in reality we never do it like this `skip: true`. We always use some variable like this for example `useSubscription(config, { skip: !userId })`. But in this case with current typescript if we use `skip: !userId` subscription and variables are required.
This change makes `config.subscription` and `config.variables` whenever we provide skip option. The value of skip option can be known in runtime only
Member
|
@aleksandrlat sorry but this pr is not very clear to me. GraphQLSubscriptionConfig requires both subscription and variable and in the PR you only changed the behavior of the skip parameter. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
useSubscription allows to omit
config.subscriptionandconfig.variablesifopts.skipis literally true.I.e.
subscriptionandvariablesare optional only when we explicitly pass true to skip option:useSubscription(config, { skip: true }).But in reality we never do it like this
skip: true. We always use some variable. For example like thisuseSubscription(config, { skip: !userId }).But in this case with current typescript type if we use
skip: !userIdsubscription and variables are required.This PR makes
config.subscriptionandconfig.variablesoptional whenever we provide skip option. The value of skip option can be known in runtime only.The problem code example:
With a fix I think code can be clearer:
@morrys I'm not sure what test to write for this, there is no runtime changes. Please let me know if it makes sense at all.
I made a change in our project and there was only 1 typescript error because in that place we didn't use generic param with useSubscription.
Thanks,
Aleksandr