Skip to content

Commit

Permalink
faq: update apollo client cache suggestions (#393)
Browse files Browse the repository at this point in the history
Co-authored-by: Artem Zakharchenko <[email protected]>
  • Loading branch information
alessbell and kettanaito authored May 3, 2024
1 parent c1f32b5 commit 8319a7c
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/content/docs/faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Info } from '../../components/react/info'

{/* prettier-ignore */}
<Info>
Have a question not present in the list? Open a [Discussion](https://github.com/mswjs/msw/discussions/new) on GitHub and get help from our community.
Have a question not present in the list? Open a [Discussion](https://github.com/mswjs/msw/discussions/new) on GitHub and get help from our community.
</Info>

## How is it different than library XYZ?
Expand Down Expand Up @@ -120,14 +120,36 @@ beforeEach(() => {

### Apollo Client

```js
import { client } from './apolloClient'
The Apollo Client team recommends creating a new client instance for each test.

beforeEach(() => {
return client.cache.reset()
```js {8-13}
// src/apollo-client.js
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'

const httpLink = new HttpLink({
uri: 'https://example.com/graphql',
})

export function makeClient() {
return new ApolloClient({
cache: new InMemoryCache(),
link: httpLink,
})
}
```

```js /makeClient/
// test/Component.test.jsx
import { makeClient } from '../src/apollo-client'

it('renders the component', async () => {
const client = makeClient()
// ...use your client in test.
})
```

> Learn more in the [Apollo Client documentation](https://www.apollographql.com/docs/react/development-testing/schema-driven-testing/#should-i-share-a-single-apolloclient-instance-between-tests).
## Light theme when?

Whenever you have time to [open a pull request](https://github.com/mswjs/mswjs.io).
Expand Down

0 comments on commit 8319a7c

Please sign in to comment.