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

Remove typenames from MockedProvider #1001

Merged
merged 1 commit into from
Aug 24, 2017
Merged

Conversation

carlows
Copy link
Contributor

@carlows carlows commented Aug 19, 2017

This PR allows to pass a removeTypenames prop to the MockedProvider, this way there's no need to add the __typename field to the mocked data.

Right now, to add mocked data in tests, it's required to use addTypenameToDocument in all of the queries:

const query = addTypenameToDocument(HERO_QUERY);

Together with this, the mocked data needs to include the __typename field in all of the models:

export const hero_no_friends = {
  __typename: 'Droid',
  name: 'r2d2',
  id: '1',
  friends: null,
};

I find this a bit of a pain, and I would prefer not having to do this. As the apollo-client accepts an addTypename field, we can allow the MockedProvider to configure that option as we'd like.

This can be used this like this:

<MockedProvider mocks={mocks} removeTypename>

I didn't find any tests for test-utils, so I only added an example test within the base example.

@apollo-cla
Copy link

@carlows: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

@mention-bot
Copy link

@carlows, thanks for your PR! By analyzing the history of the files in this pull request, we identified @jbaxleyiii, @calebmer and @mmissey to be potential reviewers.

@apollo-cla
Copy link

apollo-cla commented Aug 19, 2017

Warnings
⚠️

There are library changes, but not tests. That's OK as long as you're refactoring existing code

Generated by 🚫 dangerJS

This commit allows to pass a removeTypenames prop to the MockedProvider,
this way there's no need to add the __typename field to the mocked data.
@jbaxleyiii
Copy link
Contributor

@carlows this is such a great addition 😍

Thank you! And congrats on your first contribution here!

@jbaxleyiii jbaxleyiii merged commit 3f4da58 into apollographql:master Aug 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants