Skip to content

Commit 97b9d75

Browse files
authored
Merge pull request #4210 from prugit/patch-2
part 8e: Subscriptions on the client - update client setup for Apollo/client v4
2 parents 67c66df + c150430 commit 97b9d75

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/content/8/en/part8e.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -646,19 +646,19 @@ The configuration in <i>main.jsx</i> has to be modified like so:
646646

647647
```js
648648
import {
649-
ApolloClient, InMemoryCache, createHttpLink,
650-
split // highlight-line
649+
ApolloClient, InMemoryCache, HttpLink,
650+
ApolloLink // highlight-line
651651
} from '@apollo/client'
652652
import { ApolloProvider } from '@apollo/client/react'
653-
import { setContext } from '@apollo/client/link/context'
653+
import { SetContextLink } from '@apollo/client/link/context'
654654

655655
// highlight-start
656656
import { getMainDefinition } from '@apollo/client/utilities'
657657
import { GraphQLWsLink } from '@apollo/client/link/subscriptions'
658658
import { createClient } from 'graphql-ws'
659659
// highlight-end
660660

661-
const authLink = setContext((_, { headers }) => {
661+
const authLink = new SetContextLink((_, { headers }) => {
662662
const token = localStorage.getItem('phonenumbers-user-token')
663663
return {
664664
headers: {
@@ -668,7 +668,7 @@ const authLink = setContext((_, { headers }) => {
668668
}
669669
})
670670

671-
const httpLink = createHttpLink({ uri: 'http://localhost:4000' })
671+
const httpLink = new HttpLink({ uri: 'http://localhost:4000' })
672672

673673
// highlight-start
674674
const wsLink = new GraphQLWsLink(
@@ -677,7 +677,7 @@ const wsLink = new GraphQLWsLink(
677677
// highlight-end
678678

679679
// highlight-start
680-
const splitLink = split(
680+
const splitLink = ApolloLink.split(
681681
({ query }) => {
682682
const definition = getMainDefinition(query)
683683
return (
@@ -711,7 +711,7 @@ npm install graphql-ws
711711
The new configuration is due to the fact that the application must have an HTTP connection as well as a WebSocket connection to the GraphQL server.
712712

713713
```js
714-
const httpLink = createHttpLink({ uri: 'http://localhost:4000' })
714+
const httpLink = new HttpLink({ uri: 'http://localhost:4000' })
715715

716716
const wsLink = new GraphQLWsLink(
717717
createClient({

0 commit comments

Comments
 (0)