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

feat: skip option for subscription #1229

Merged
merged 4 commits into from
Jan 7, 2025

Conversation

brianjd
Copy link
Contributor

@brianjd brianjd commented Jan 7, 2025

What does this PR do?

Add skip option for subscriptions, making the creation of subscription conditional.

Related issues

Closes #1225

Checklist

  • I have checked the contributing document
  • I have added or updated any relevant documentation
  • I have added or updated any relevant tests

Copy link

netlify bot commented Jan 7, 2025

👷 Deploy request for graphql-hooks-cra pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c05dda8

@simoneb simoneb requested a review from Copilot January 7, 2025 19:35

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

@@ -22,6 +22,10 @@ function useSubscription<
const contextClient = useContext(ClientContext)
const client = options.client || contextClient

if (options.skip) {
return
Copy link
Member

Choose a reason for hiding this comment

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

although tests are passing, I believe that returning early from a hook violates React's rules of hooks, specifically:

🔴 Do not call Hooks after a conditional return statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, you are correct. I have now moved the skip check inside of the useDeepCompareEffect.

@simoneb simoneb requested a review from Copilot January 7, 2025 20:35

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

@simoneb simoneb force-pushed the subscription-skip branch from 3f8c561 to db10fdf Compare January 7, 2025 20:40
@simoneb
Copy link
Member

simoneb commented Jan 7, 2025

Can you please update the docs to document the option?

https://github.com/nearform/graphql-hooks/?tab=readme-ov-file#useSubscription

@brianjd
Copy link
Contributor Author

brianjd commented Jan 7, 2025

@simoneb Done

README.md Outdated
@@ -419,11 +419,12 @@ To use subscription you can use either [subscriptions-transport-ws](https://gith

`useSubscription(operation, callback)`

- `operation`: Object - The GraphQL operation has the following properties:
- `options`: Object - The GraphQL operation has the following properties:
Copy link
Member

@simoneb simoneb Jan 7, 2025

Choose a reason for hiding this comment

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

why did you rename this? for consistency, you may want to rename it above as well, and see if it's defined as "operation" elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed because it didn't feel accurate calling it operation as it represents more than just the gql operation now. It was a bit hasty though. I'll rename it back to operation.

Copy link
Member

Choose a reason for hiding this comment

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

options is also fine, but let's keep it consistent!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted to operation since options is being used in other contexts and changing would require more adjustments.

@simoneb simoneb merged commit bb2183b into nearform:master Jan 7, 2025
1 check passed
@brianjd
Copy link
Contributor Author

brianjd commented Jan 8, 2025

@simoneb Will you be able to craft a release this week with the new option?

@simoneb
Copy link
Member

simoneb commented Jan 8, 2025

@brianjd done

@brianjd
Copy link
Contributor Author

brianjd commented Jan 8, 2025

Thanks @simoneb!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "skip" option to subscription hook
2 participants