Skip to content

Commit 38151e6

Browse files
committed
update docs for the conf field
1 parent d9a2bef commit 38151e6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,21 @@ const cache = new InMemoryCache({
276276
const mockClient = createMockClient({ cache });
277277
```
278278

279+
Additionally, you can specify a `missingHandlerPolicy` to define the behavior of the mock client when a request handler for a particular operation is not found.
280+
281+
The `missingHandlerPolicy` accepts one of three string values:
282+
- `'throw-error'`: The client throws an error when it encounters a missing handler.
283+
- `'warn-and-return-error'`: The client logs a warning message in the console and returns an error.
284+
- `'return-error'`: The client returns an error without any warning message.
285+
286+
Here's an example of how you can set the `missingHandlerPolicy`:
287+
288+
```typescript
289+
const mockClient = createMockClient({ missingHandlerPolicy: 'warn-and-return-error' });
290+
```
291+
292+
In this example, if a request handler for a given operation is not found, the client will log a warning message to the console and then return an error.
293+
279294
Note: it is not possible to specify the `link` to use as this is how `mock-apollo-client` injects its behaviour.
280295

281296
### Fragments

src/mockLink.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ describe('class MockLink', () => {
263263
expect(console.warn).toBeCalledWith(`Request handler not defined for query: ${print(queryOne)}`);
264264
});
265265

266-
it('when "ignore" returns an error when a handler is not defined for the query', async () => {
266+
it('when "return-error" returns an error when a handler is not defined for the query', async () => {
267267
mockLink = new MockLink({missingHandlerPolicy: 'return-error'})
268268

269269
const observable = mockLink.request(queryOneOperation);

0 commit comments

Comments
 (0)