Skip to content

Commit

Permalink
Revert "Expose composed middleware via getMiddleware()" (#3046)
Browse files Browse the repository at this point in the history
This reverts commit 4149a97 from #2435,
which has resulted in a change to middleware endpoints which could be
perceived as major and breaking.
  • Loading branch information
abernix committed Jul 16, 2019
1 parent c2b9071 commit 52ab22e
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 343 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Expand Up @@ -9,14 +9,12 @@ The version headers in this history reflect the versions of Apollo Server itself
- `apollo-engine-reporting`: **BEHAVIOR CHANGE**: If the error returned from the `engine.rewriteError` hook has an `extensions` property, that property will be used instead of the original error's extensions. Document that changes to most other `GraphQLError` fields by `engine.rewriteError` are ignored. [PR #2932](https://github.com/apollographql/apollo-server/pull/2932)
- `apollo-engine-reporting`: **BEHAVIOR CHANGE**: The `engine.maskErrorDetails` option, deprecated by `engine.rewriteError` in v2.5.0, now behaves a bit more like the new option: while all error messages will be redacted, they will still show up on the appropriate nodes in a trace. [PR #2932](https://github.com/apollographql/apollo-server/pull/2932)
- `apollo-engine-reporting`: **BEHAVIOR CHANGE**: By default, send no GraphQL variable values to Apollo's servers instead of sending all variable values. Adding the new EngineReportingOption `sendVariableValues` to send some or all variable values, possibly after transforming them. This replaces the `privateVariables` option, which is now deprecated. [PR #2931](https://github.com/apollographql/apollo-server/pull/2931)
- Update `graphql-playground` to resolve incorrect background color on tabs when using the `light` theme. [PR #2989](https://github.com/apollographql/apollo-server/pull/2989) [Issue #2979](https://github.com/apollographql/apollo-server/issues/2979)
- `apollo-server-express`, `apollo-server-koa`: A new `getMiddleware` method, which accepts the same parameters as `applyMiddleware` with the exception of the `app`, has been added. This allows implementors to obtain the composed middleware and "`use`" it within an existing `app`. This was previously only possible by passing an `app` to `applyMiddleware` or reaching into Apollo Server internals, but `getMiddleware` should allow a more natural method and will hopefully resolve many issues raised around the previous pattern. [PR #2435](https://github.com/apollographql/apollo-server/pull/2435)

> Note: In order to keep shipping all GraphQL variable values to Apollo Engine, pass in the option:
>
> `new ApolloServer({engine: {sendVariableValues: {all: true}}})`.

- Update `graphql-playground` to resolve incorrect background color on tabs when using the `light` theme. [PR #2989](https://github.com/apollographql/apollo-server/pull/2989) [Issue #2979](https://github.com/apollographql/apollo-server/issues/2979)
- `apollo-server-plugin-base`: Fix `GraphQLRequestListener` type definitions to allow `return void`. [PR #2368](https://github.com/apollographql/apollo-server/pull/2368)

### v2.6.7
Expand Down
10 changes: 1 addition & 9 deletions docs/source/api/apollo-server.md
Expand Up @@ -147,7 +147,7 @@ In `apollo-server`, the listen call starts the subscription server and passes th
* `subscriptionsPath`: <`String`>
* `server`: <[`http.Server`](https://nodejs.org/api/http.html#http_class_http_server)>

## `ApolloServer.applyMiddleware`
## ApolloServer.applyMiddleware

The `applyMiddleware` method is provided by the `apollo-server-{integration}` packages that use middleware, such as hapi and express. This function connects ApolloServer to a specific framework.

Expand Down Expand Up @@ -193,14 +193,6 @@ app.use('*', jwtCheck, requireAuth, checkScope);
server.applyMiddleware({ app, path: '/specialUrl' }); // app is from an existing express app. Mount Apollo middleware here. If no path is specified, it defaults to `/graphql`.
```

## `ApolloServer.getMiddleware`

Similar to the `applyMiddleware` method above, though rather than applying the composition of the various Apollo Server middlewares which comprise a full-featured Apollo Server deployment (e.g. middleware for HTTP body parsing, GraphQL Playground, uploads and subscriptions) the `getMiddleware` simply returns the middleware.

The `getMiddleware` method takes the same arguments as `applyMiddleware` **except** `app` should not be passed. Instead, the result of `getMiddleware` must be added as a middleware directly to an existing application (e.g. with `app.use(...)`).

For example, for `apollo-server-express`, this means that rather than passing `applyMiddleware` an `app` which was already initiated from calling `express()`, and `applyMiddleware` "using" (i.e. `app.use`), the implementor will instead call `app.use(...)` on the result of `getMiddleware` with the same arguments.

## `gql`

The `gql` is a [template literal tag](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates). Template literals were introduced in recent versions of ECMAScript to provide embedded expressions (i.e. `` `A string with interpolated ${variables}` ``) and template literal tags exist to provide additional functionality for what would otherwise be a normal template literal.
Expand Down

0 comments on commit 52ab22e

Please sign in to comment.