-
-
Notifications
You must be signed in to change notification settings - Fork 818
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
State-full mocking #2229
State-full mocking #2229
Conversation
🦋 Changeset detectedLatest commit: a1cc0fb The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
export const randomListLength = () => { | ||
// Mocking has always returned list of length 2 by default | ||
// return 1 + Math.round(Math.random() * 10) | ||
return 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice this: for backward compatibility, i make it return 2 - but it would be richer if we'd truly return a random number.
Waiting for maintainers directions on what I should do with test cases failing because of breaking changes |
@yaacovCR What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not used the mock package to much, but in getting the general idea, I think this is fantastic. Do we want to revisit when more of the existing tests have parallels in the new setup? Should we have a migration guide?
All right! I can follow these steps:
|
} | ||
} | ||
}) | ||
}); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome stuff. Huge improvement over current mocking package, which I actually don’t find to be more useful than just simple resolvers plugged into an executable schema.
This looks like a great addition to v8
I'm having an issue with the test "can support explicit UnionType mock": the test is expecting I call (and get values) from an union mock while I'm getting a field value for a type that, in some cases, is a member of a this union. I can't do it with current impl and don't see any way to do it. Except this, the rest is ready for review. |
Awesome! Could you rebase conflicts and add a changeset? I think |
This is fantastic stuff as far as I can tell from afar. I am not a user, however, of the current mock package so I am not personally in best place to review. :) Just in general, I personally dont think we need absolutely every existing test to pass -- we just want to give users a better mocking experience, and can make breaking changes as long as we semver right. I think you had the best possible approach in trying to preserve as much of the old functionality as possible -- but may be ok to merge without every old test.... I may have some time over the weekend to take a look at what's failing in more detail and add more thoughts, but like I said I am not too familiar right now with the mock code base... Will defer to others :) |
…cause it's now supported
it leads to useles test caeses
6233e92
to
a1cc0fb
Compare
@alexstrat Skipped the failing test for now! This is awesome feature! Would you like to write a blog post about new mocking features in our blog? cc @Urigo |
@ardatan yes, I can submit a draft. Any particular objective for the blog post, or approach? |
@alexstrat You can just mention new changes, covered use cases and maybe a comparison between old approach and the new one :) After you submit a draft, we can help you before publishing it. |
* Replace old by new implementation * Move old test suite to retro-compatibility test suite * Add documenation * Make randomListLength always return 2 for retro-compatibility * Fix enum mocking * Make error messages backward compatible * Fix mockResolver to give priority to default resolved value * Complete arrays of non composite types with values * Add argument validation thrown errors * Remove test about mockFunctionMap containing a non-function thingy because it's now supported * Add support for subscription * Better support for inserting lists of lists * Deep resolve mock list to better suport MockList of MockList * Adapt test 'can mock Interfaces by default' * Fix support for explicit Interface * Added doc about MockStore * Added a migration paragraph * Fix typo * Fix setting id in union mocks Backport of alexstrat/graphql-stateful-mock#6 * Expose schema in IMockStore Backport of alexstrat/graphql-stateful-mock#5 * Remove test because irrelevant * Removed test because irrelevant * Removed tests because irrelevant * Adapt 2 tetsts on root fields it leads to useles test caeses * Add changeset * Fix typo * Fix GraphQL 14 compability issue * Skip failing test Co-authored-by: Arda TANRIKULU <[email protected]>
This PR re-implements
mock
package to add state to mocking via aMockStore
, an accessible and editable store of all mocked values.The reasons that motivate this change are exposed in #1682. In brief: a "real" graphql schema is state-full: in most cases, a same query will return the same result. Adding a state adds realism, by default and thanks to user's customizations.
API changes
resolvers
option to add resolvers (see example in doc Handling*byId
fields)Ref
that can be used to query the store. If you used__resolveType
resolver for mocking interfaces and union, rather use__typename
directly in mocks (see doc Abstract types).MockList
is deprecated, use plain arrays instead (see doc Using lists in mocks)mocking-compatibility.spec.ts
to verify backward compatibly, potentially reveal other breaking changes or catch bugs. I had a look at each one by one:TODOs
docs/mocking.md