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

Commit

Permalink
Allow resolvers to be passed into MockedProvider and set a default
Browse files Browse the repository at this point in the history
After the changes in apollographql/apollo-client#4499,
when `MockedProvider` is currently used it doesn't have any
`resolvers` set. This means `@client` directives are passed into
the link chain. Since we don't currently allow people to modify the
link chain that `MockedProvider` uses, it's safe to assume people won't
want this behaviour, as they can't test things like `apollo-link-state`
this way. This commit sets a default `resolvers` value of `{}` to
enable AC 2.5's new local state handling, and opens the door for
passing custom resolvers into the `MockedProvider` via props.

Helps fix apollographql/fullstack-tutorial#73.
  • Loading branch information
hwillson committed Feb 27, 2019
1 parent 7801b79 commit 6632862
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit 6632862

Please sign in to comment.