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

How should I import WebSocketLink ? #6732

Closed
ArnaudBarre opened this issue Jul 29, 2020 · 3 comments
Closed

How should I import WebSocketLink ? #6732

ArnaudBarre opened this issue Jul 29, 2020 · 3 comments

Comments

@ArnaudBarre
Copy link
Contributor

ArnaudBarre commented Jul 29, 2020

In beta, I was importing it from @apollo/link-ws": "^2.0.0-beta.3" and it was working find.

In 3.1.1, I got a typing issue, because ApolloLink from @apollo/link-ws -> apollo-link-ws does not match the one from @apollo/client.

I can get it work by importing from "@apollo/client/link/ws".

Is a re-export missing somewhere ?

@benjamn
Copy link
Member

benjamn commented Jul 29, 2020

This should work (although it was improved in v3.1.0 by #6656):

import { WebSocketLink } from "@apollo/client/link/ws"

However, you will probably want to avoid using @apollo/link-ws or apollo-link-ws at the same time, since they may have their own implementations of WebSocketLink (depending on which versions of those packages you're using).

Happy to answer follow-up questions, of course.

@ArnaudBarre
Copy link
Contributor Author

Is it to simplify work of tree shaking that we cannot do import { WebSocketLink } from "@apollo/client" ?

@ArnaudBarre ArnaudBarre changed the title How should I import of WebSocketLink ? How should I import WebSocketLink ? Jul 30, 2020
@benjamn
Copy link
Member

benjamn commented Jul 30, 2020

It's also to avoid cluttering the available top-level imports, and to avoid importing the entire library when using CommonJS (which Node.js still does in most cases). Any use of @apollo/client without a bundler benefits from having narrowly-scoped entry points for optional parts of the library, because there's no opportunity for tree-shaking without a bundler like Rollup or Webpack.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 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

No branches or pull requests

2 participants