Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Allow resolvers to be passed into MockedProvider and set a default #2825

Merged
merged 2 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change log

## 2.5.1

### Bug Fixes

- Make sure `MockedProvider` enables Apollo Client 2.5's local state handling,
and allow custom / mocked resolvers to be passed in as props, and used with
the created test `ApolloClient` instance. <br/>
[@hwillson](https://github.com/hwillson) in [#2825](https://github.com/apollographql/react-apollo/pull/2825)


## 2.5.0

### Improvements
Expand Down
12 changes: 10 additions & 2 deletions src/test-utils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import ApolloClient from 'apollo-client';
import { DefaultOptions } from 'apollo-client';
import { DefaultOptions, Resolvers } from 'apollo-client';
import { InMemoryCache as Cache } from 'apollo-cache-inmemory';

import { ApolloProvider } from './index';
Expand All @@ -13,6 +13,7 @@ export interface MockedProviderProps<TSerializedCache = {}> {
addTypename?: boolean;
defaultOptions?: DefaultOptions;
cache?: ApolloCache<TSerializedCache>;
resolvers?: Resolvers;
}

export interface MockedProviderState {
Expand All @@ -27,11 +28,18 @@ export class MockedProvider extends React.Component<MockedProviderProps, MockedP
constructor(props: MockedProviderProps) {
super(props);

const { mocks, addTypename, defaultOptions, cache } = this.props;
const {
mocks,
addTypename,
defaultOptions,
cache,
resolvers = {},
} = this.props;
const client = new ApolloClient({
cache: cache || new Cache({ addTypename }),
defaultOptions,
link: new MockLink(mocks || [], addTypename),
resolvers,
});

this.state = { client };
Expand Down