Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make mocking configuration less confusing. #1835

Merged
merged 5 commits into from
Oct 30, 2018

Conversation

deftomat
Copy link
Contributor

@deftomat deftomat commented Oct 19, 2018

We had a few WTF? situations 😉 with the following Apollo server config:

const config = {
  typeDefs,
  resolvers,
  mocks: false,
  mockEntireSchema: false,
}

Everyone in our team assumed that you can disable the mocks by setting the mocks property to false.
However, according to:

if (mocks || typeof mockEntireSchema !== 'undefined') {

The mocks will be enabled when you provide mocksEntireSchema together with mocks. It doesn't matter if mocks is true or false or an object.

I'm not sure if this is an intended behaviour but I can definitely say that it is really confusing.
Can we update it to disable mocks when mocks property is false?

(Feel free to close this PR if the current behaviour is an intended behaviour)

Setting mocks to false will always disable mocking.
@apollo-cla
Copy link

@deftomat: 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/

@ghost ghost added the ⛲️ feature New addition or enhancement to existing solutions label Oct 19, 2018
@@ -254,7 +254,7 @@ export class ApolloServerBase {
});
}

if (mocks || typeof mockEntireSchema !== 'undefined') {
if (mocks || (typeof mockEntireSchema !== 'undefined' && mocks !== false)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @deftomat Thanks for looking into this! I've been meaning to look at it. Question: wouldn't this end up doing the same thing?

Suggested change
if (mocks || (typeof mockEntireSchema !== 'undefined' && mocks !== false)) {
if (mocks) {

Copy link
Contributor

Choose a reason for hiding this comment

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

To my understanding, this is the current intended behavior:

mocks: false

  • no matter what, no mocks get added

mocks: true

  • by default, mocks all resolvers
  • mockEntireSchema: false to overwrite this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, in my code, you can enable mocks by setting mockEntireSchema without bothering about mocks property.
By looking at the next lines, you can see that it is an intended behaviour to be able to enable mocks just by using mockEntireSchema.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep! That makes more sense actually 👌 Thanks for clarifying @deftomat

@JakeDawkins
Copy link
Contributor

@deftomat Can you add this line to CHANGELOG.md for me? FYI, you may need to pull first also, since I updated the branch

- Fix mocks configuration to allow disabling of mocks by using `mocks: false`, even if `mockEntireSchema` is `true` [PR #1835](https://github.com/apollographql/apollo-server/pull/1835)

@deftomat
Copy link
Contributor Author

@JakeDawkins done!

@JakeDawkins JakeDawkins merged commit abbe382 into apollographql:master Oct 30, 2018
@JakeDawkins
Copy link
Contributor

Thanks for the help @deftomat!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2023
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.

3 participants