-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Docs: Mocking Page edits #6026
Docs: Mocking Page edits #6026
Conversation
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.
Looking good overall. I tried to look for semantic issues (Stephen's suggestions are of course great).
docs/source/testing/mocking.md
Outdated
|
||
By default, the functions in `mocks` will overwrite any currently defined resolvers. In the below example, both `hello` and `resolved` will return `Hello`. | ||
By default, the functions in `mocks` will take precedence over any currently defined resolvers. In the below example, both `hello` and `resolved` return `Hello`. |
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.
Cut "will"
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.
For an abundance of clarity, I might say "both Query.hello
and Query.resolved
"
docs/source/testing/mocking.md
Outdated
|
||
In the below example, take note that our `mocks`' `Person` object will invoke a function returning an object with fields pointing at more functions: | ||
In the below example, note that our mocked `Person` object calls a function returning an object with fields pointing at _other_ functions: |
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.
On second pass I guess we don't typically use "pointing at", and I might recommend something like:
"with fields that contain other functions"
docs/source/testing/mocking.md
Outdated
@@ -93,11 +171,11 @@ const mocks = { | |||
}; | |||
``` | |||
|
|||
The previous example uses [casual](https://github.com/boo1ean/casual), a fake data generator for JavaScript, which returns a different result every time the function is called. In other scenarios, such as testing, a collection of fake objects or a generator that always uses a consistent seed are often necessary to provide consistent data. | |||
The previous example uses [casual](https://github.com/boo1ean/casual), a fake data generator for JavaScript which returns a different result every time the function is called. In other scenarios, such as testing, a collection of fake objects or a generator that always uses a consistent seed are often necessary to provide consistent data. |
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.
"which" -> "that"
docs/source/testing/mocking.md
Outdated
@@ -152,13 +230,13 @@ server.listen().then(({ url }) => { | |||
}); | |||
``` | |||
|
|||
Running the above example, with the `mockEntireSchema` option set to false, `resolved` will now return the string `Resolved`. | |||
Running the above example with the `mockEntireSchema` option set to false, the `resolved` field now returns the string `Resolved`. |
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.
codefont false
here as well
docs/source/testing/mocking.md
Outdated
@@ -183,7 +261,7 @@ server.listen().then(({ url }) => { | |||
|
|||
Under the hood, Apollo Server's mocking functionality is provided by the function [`addMocksToSchema`](https://www.graphql-tools.com/docs/mocking/) from the `@graphql-tools/mock` package. The `mocks` object is passed directly to the `addMocksToSchema` function, and `preserveResolvers` is the inverse of `mockEntireSchema`. | |||
|
|||
Apollo Server does not support all of the arguments to `addMocksToSchema`, such as `resolvers`. If you'd like to use the features of `@graphql-tools/mock` that aren't supported by Apollo Server, you can use `@graphql-tools/mock` directly: | |||
Apollo Server does not support all of the arguments to `addMocksToSchema`, such as `resolvers`. If you'd like to use the features of `@graphql-tools/mock` that aren't supported by Apollo Server, you can install and use `@graphql-tools/mock` directly: |
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.
"If you'd like to use the features" -> "To use features"
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.
Text approved with a last few tiny edits, whenever @glasser thinks it's ✅ !
docs/source/testing/mocking.md
Outdated
</tbody> | ||
</table> | ||
|
||
By default when using mocks, your existing resolvers are **ignored** in favor of `mocks`. To configure this behavior, see [Using existing resolvers with mocks](#using-existing-resolvers-with-mocks). |
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.
maybe be even more explicit, more like:
When using mocks, you don't have to specify `resolvers` at all. In fact, by default any `resolvers` you specify will be **ignored** when you enable `mocks`. To configure...
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.
Other than that (and Stephen's notes), looks good.
Note that we are considering removing these options from ApolloServer in AS4, though we probably would still document how to use @graphql-tools/mock
directly. #6063
Took a pass at editing the
Mocking
article. Didn't change any of the code, just tweaked and elaborated on the text.