Skip to content

Commit 55c1524

Browse files
update Apollo Client imports to v4 (latest)
1 parent 396ca2c commit 55c1524

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

src/content/8/en/part8b.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ We'll start with the following code for our application:
3535
import ReactDOM from 'react-dom/client'
3636
import App from './App'
3737

38-
import { ApolloClient, InMemoryCache, gql } from '@apollo/client'
38+
import { ApolloClient, HttpLink, InMemoryCache, gql } from '@apollo/client';
3939

4040
const client = new ApolloClient({
41-
uri: 'http://localhost:4000',
41+
link: new HttpLink({ uri: 'http://localhost:4000' }),
4242
cache: new InMemoryCache(),
4343
})
4444

@@ -84,14 +84,11 @@ The application can communicate with a GraphQL server using the *client* object.
8484
import ReactDOM from 'react-dom/client'
8585
import App from './App'
8686

87-
import {
88-
ApolloClient,
89-
ApolloProvider, // highlight-line
90-
InMemoryCache,
91-
} from '@apollo/client'
87+
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client';
88+
import { ApolloProvider } from '@apollo/client/react'; // highlight-line
9289

9390
const client = new ApolloClient({
94-
uri: 'http://localhost:4000',
91+
link: new HttpLink({ uri: 'http://localhost:4000' }),
9592
cache: new InMemoryCache(),
9693
})
9794

@@ -112,7 +109,8 @@ Currently, the use of the hook function [useQuery](https://www.apollographql.com
112109
The query is made by the <i>App</i> component, the code of which is as follows:
113110

114111
```js
115-
import { gql, useQuery } from '@apollo/client'
112+
import { gql } from '@apollo/client';
113+
import { useQuery } from '@apollo/client/react';
116114

117115
const ALL_PERSONS = gql`
118116
query {
@@ -245,7 +243,8 @@ The solution is as follows:
245243

246244
```js
247245
import { useState } from 'react'
248-
import { gql, useQuery } from '@apollo/client'
246+
import { gql } from '@apollo/client';
247+
import { useQuery } from '@apollo/client/react';
249248

250249
const FIND_PERSON = gql`
251250
query findPersonByName($nameToSearch: String!) {
@@ -401,7 +400,8 @@ Let's create a new component for adding a new person to the directory:
401400

402401
```js
403402
import { useState } from 'react'
404-
import { gql, useMutation } from '@apollo/client'
403+
import { gql } from '@apollo/client';
404+
import { useMutation } from '@apollo/client/react';
405405

406406
const CREATE_PERSON = gql`
407407
// ...
@@ -686,7 +686,7 @@ Interesting lines on the code have been highlighted.
686686
687687
```js
688688
import { useState } from 'react'
689-
import { useMutation } from '@apollo/client'
689+
import { useMutation } from '@apollo/client/react';
690690

691691
import { EDIT_NUMBER } from '../queries'
692692

src/content/8/en/part8d.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Interesting lines in the code have been highlighted:
5555

5656
```js
5757
import { useState, useEffect } from 'react'
58-
import { useMutation } from '@apollo/client'
58+
import { useMutation } from '@apollo/client/react';
5959
import { LOGIN } from '../queries'
6060

6161
const LoginForm = ({ setError, setToken }) => {
@@ -164,7 +164,8 @@ const App = () => {
164164
After the backend changes, creating new persons requires that a valid user token is sent with the request. In order to send the token, we have to change the way we define the *ApolloClient* object in <i>main.jsx</i> a little.
165165

166166
```js
167-
import { ApolloClient, InMemoryCache, ApolloProvider, createHttpLink } from '@apollo/client' // highlight-line
167+
import { ApolloClient, InMemoryCache, createHttpLink } from '@apollo/client' // highlight-line
168+
import { ApolloProvider } from '@apollo/client/react';
168169
import { setContext } from '@apollo/client/link/context' // highlight-line
169170

170171
// highlight-start

src/content/8/en/part8e.md

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

647647
```js
648648
import {
649-
ApolloClient, InMemoryCache, ApolloProvider, createHttpLink,
649+
ApolloClient, InMemoryCache, createHttpLink,
650650
split // highlight-line
651651
} from '@apollo/client'
652+
import { ApolloProvider } from '@apollo/client/react';
652653
import { setContext } from '@apollo/client/link/context'
653654

654655
// highlight-start
@@ -739,7 +740,7 @@ and do the subscription in the App component:
739740

740741
```js
741742

742-
import { useQuery, useMutation, useSubscription } from '@apollo/client' // highlight-line
743+
import { useQuery, useMutation, useSubscription } from '@apollo/client/react' // highlight-line
743744

744745

745746
const App = () => {

0 commit comments

Comments
 (0)