Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faq: update apollo client cache suggestions #393

Merged
merged 2 commits into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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