-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate apollo-server-testing; allow ASTs for executeOperation (#5238)
The `apollo-server-testing` package exports one small function which is just a tiny wrapper around `server.executeOperation`. The one main advantage it provides is that you can pass in operations as ASTs rather than only as strings. This extra layer doesn't add much value but does require us to update things in two places (which cross a package barrier and thus can be installed at skewed versions). So for example when adding the second argument to `executeOperation` in #4166 I did not bother to add it to `apollo-server-testing` too. We've also found that users have been confused by the `createTestClient` API (eg #5111) and that some linters get confused by the unbound methods it returns (#4724). So the simplest thing is to just teach people how to use the real `ApolloServer` method instead of an unrelated API. This PR allows you to pass an AST to `server.executeOperation` (just like with the `apollo-server-testing` API), and changes the docs to recommend `executeOperation` instead of `apollo-server-testing`. It also makes some other suggestions about how to test Apollo Server code in a more end-to-end fashion, and adds some basic tests for `executeOperation`. Fixes #4952.
- Loading branch information
Showing
5 changed files
with
146 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
# apollo-server-testing | ||
|
||
[![npm version](https://badge.fury.io/js/apollo-server-testing.svg)](https://badge.fury.io/js/apollo-server-testing) | ||
[![Build Status](https://circleci.com/gh/apollographql/apollo-server/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-server) | ||
This deprecated package contains a function `createTestClient` which is a very thin wrapper around the Apollo Server `server.executeOperation` method. | ||
|
||
This is the testing module of the Apollo community GraphQL Server. [Read the docs.](https://www.apollographql.com/docs/apollo-server/) | ||
[Read the CHANGELOG.](https://github.com/apollographql/apollo-server/blob/main/CHANGELOG.md) | ||
Code that uses this package looks like the following, where `server` is an `ApolloServer`: | ||
|
||
```js | ||
const { createTestClient } = require('apollo-server-testing'); | ||
|
||
const { query, mutate } = createTestClient(server); | ||
|
||
await query({ query: QUERY }); | ||
await mutate({ mutation: MUTATION }); | ||
``` | ||
|
||
We recommend you stop using this package and replace the above code with the equivalent: | ||
|
||
```js | ||
await server.executeOperation({ query: QUERY }); | ||
await server.executeOperation({ query: MUTATION }); | ||
``` | ||
|
||
This package will not be distributed as part of Apollo Server 3. |