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

Docs: Mocking Page edits #6026

Merged
merged 8 commits into from
Jan 27, 2022
Merged

Docs: Mocking Page edits #6026

merged 8 commits into from
Jan 27, 2022

Conversation

rkoron007
Copy link
Contributor

Took a pass at editing the Mocking article. Didn't change any of the code, just tweaked and elaborated on the text.

@rkoron007 rkoron007 added the 📝 documentation Focuses on changes to the documentation (docs) label Jan 25, 2022
@rkoron007 rkoron007 added the size/small Estimated to take LESS THAN A DAY label Jan 25, 2022
Copy link
Member

@glasser glasser left a 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 Show resolved Hide resolved
docs/source/testing/mocking.md Outdated Show resolved Hide resolved
docs/source/testing/mocking.md Outdated Show resolved Hide resolved

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`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Cut "will"

Copy link
Contributor

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"


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:
Copy link
Contributor

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"

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

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

"which" -> "that"

@@ -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`.
Copy link
Contributor

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

@@ -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:
Copy link
Contributor

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"

Copy link
Contributor

@StephenBarlow StephenBarlow left a 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 ✅ !

</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).
Copy link
Member

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...

Copy link
Member

@glasser glasser left a 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

@rkoron007 rkoron007 self-assigned this Jan 27, 2022
@StephenBarlow StephenBarlow merged commit f742c89 into main Jan 27, 2022
@StephenBarlow StephenBarlow deleted the RK/docs-mocking-edits branch January 27, 2022 23:33
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📝 documentation Focuses on changes to the documentation (docs) size/small Estimated to take LESS THAN A DAY
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants