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

Added custom cache option to MockedProvider #2142

Closed
wants to merge 4 commits into from

Conversation

JakeDawkins
Copy link
Contributor

Someone using MockedProvider in a project with fragments ran into an issue where they couldn't test a component, because of the default HeuristicFragmentMatcher. Since there was no way to control what cache was used with the original MockedProvider, I added a prop to it that allows a custom Cache to be passed in.

This also will allow people to preload caches, etc when testing components

I added an example in the tests

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests
  • If this was a change that affects the external API used in GitHunt-React, update GitHunt-React and post a link to the PR in the discussion.

@ghost ghost added the feature New addition or enhancement to existing solutions label Jun 27, 2018
Copy link
Contributor

@jbaxleyiii jbaxleyiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question, but dope!

@@ -18,7 +18,7 @@ export class MockedProvider extends React.Component<any, any> {
const link = new MockLink(this.props.mocks, this.props.addTypename);
this.client = new ApolloClient({
link,
cache: new Cache({ addTypename: this.props.addTypename }),
cache: this.props.cache || new Cache({ addTypename: this.props.addTypename }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JakeDawkins should we warn if you have a mismatch from addTypename as a prop vs in the cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but how do you think we could do that if they can pass in arbitrary caches?

@hwillson hwillson self-assigned this Jun 27, 2018
@williamboman
Copy link
Contributor

This seems to be a common issue (see #2254). Would be super awesome if we could merge this or #2254 soon!

@hwillson
Copy link
Member

Ooops - @JakeDawkins it looks like we've already merged this functionality in via #2142. Thanks for working on this! 🙇

@hwillson hwillson closed this Sep 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New addition or enhancement to existing solutions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants