Skip to content

Commit

Permalink
Step 7.1: Add Apollo client
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB authored and Urigo committed May 20, 2020
1 parent 5a0d2e3 commit f18e424
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"@types/react-dom": "16.9.8",
"@types/react-router-dom": "5.1.5",
"@types/styled-components": "5.1.0",
"apollo-cache-inmemory": "1.6.6",
"apollo-client": "2.6.10",
"apollo-link": "1.2.14",
"apollo-link-http": "1.5.17",
"history": "4.10.1",
"jest-environment-jsdom-sixteen": "1.0.3",
"jest-fetch-mock": "3.0.3",
Expand Down
16 changes: 16 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';

const httpUri = process.env.REACT_APP_SERVER_URL + '/graphql';

const httpLink = new HttpLink({
uri: httpUri,
});

const inMemoryCache = new InMemoryCache();

export default new ApolloClient({
link: httpLink,
cache: inMemoryCache,
});

1 comment on commit f18e424

@JP-1997
Copy link

@JP-1997 JP-1997 commented on f18e424 Mar 2, 2021

Choose a reason for hiding this comment

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

If you getting this

Property 'setLink' is missing in type 'ApolloClient' but required in type 'ApolloClient'. TS2741
or
Property 'setLink' is missing in type 'ApolloClient' but required in type 'ApolloClient'. TS2741

This happens if your import looks like this:
import { InMemoryCache } from 'apollo-cache-inmemory'; import { ApolloClient } from 'apollo-client'; import { HttpLink } from 'apollo-link-http';

Switch to this code:
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client";

Please sign in to comment.