Skip to content

Commit

Permalink
Re-land "Expose composed middleware via getMiddleware()"
Browse files Browse the repository at this point in the history
This reverts commit d05aceb which was
originally #2435, but was
reverted in 52ab22e (#3046) as a
precaution, prior to releasing 2.7.0.  This attempts to reland it.
  • Loading branch information
abernix committed Jul 16, 2019
1 parent b236cf5 commit d24be2d
Show file tree
Hide file tree
Showing 9 changed files with 343 additions and 265 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The version headers in this history reflect the versions of Apollo Server itself

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the the appropriate changes within that release will be moved into the new section.
- _Nothing yet! Stay tuned!_
- `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)


### v2.7.0
Expand Down
8 changes: 8 additions & 0 deletions docs/source/api/apollo-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ 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
Loading

0 comments on commit d24be2d

Please sign in to comment.