Created
June 4, 2020 02:04
-
-
Save raphox/893f3bbf560e840f4e6356f144a99d2b to your computer and use it in GitHub Desktop.
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
| // ... | |
| // Create an http link: | |
| const httpLink = new HttpLink({ | |
| uri: "http://localhost:4000/graphql", | |
| }); | |
| // Create a WebSocket link: | |
| const wsLink = new WebSocketLink({ | |
| uri: `ws://localhost:4000/graphql`, | |
| options: { | |
| reconnect: true, | |
| }, | |
| }); | |
| // using the ability to split links, you can send data to each link | |
| // depending on what kind of operation is being sent | |
| const link = split( | |
| // split based on operation type | |
| ({ query }) => { | |
| const definition = getMainDefinition(query); | |
| return ( | |
| definition.kind === "OperationDefinition" && | |
| definition.operation === "subscription" | |
| ); | |
| }, | |
| wsLink, | |
| httpLink | |
| ); | |
| const client = new ApolloClient({ link, cache: new InMemoryCache() }); | |
| // ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment