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

Expose composed middleware via getMiddleware(). #2435

Merged
merged 28 commits into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
46dd9d3
Expose koa middleware via server.getMiddleware() function
Mar 12, 2019
824e7b0
Update changelog
Mar 12, 2019
1e56d56
Merge branch 'master' into master
ganemone Mar 12, 2019
bd6f5bd
Merge branch 'master' into master
ganemone Mar 13, 2019
dc3be30
Merge branch 'master' into master
ganemone Mar 13, 2019
ea1722e
Merge branch 'master' into master
ganemone Mar 14, 2019
2e053bc
Merge branch 'master' into master
ganemone Mar 15, 2019
158ccca
Merge branch 'master' into master
ganemone Mar 18, 2019
f571731
Merge branch 'master' into master
ganemone Mar 20, 2019
5f49ed2
Merge branch 'master' into master
ganemone Apr 2, 2019
a557937
Merge branch 'master' into master
ganemone Apr 8, 2019
50f7ba4
savepoint
abernix Apr 10, 2019
f2d9c04
savepoint: req required.
abernix Apr 10, 2019
5582308
express
abernix Apr 12, 2019
5cca1e2
koa
abernix Apr 12, 2019
bfde5d7
Add getMiddleware functions for apollo-server-express and apollo-serv…
Jun 28, 2019
9d8e170
Update linting and deps
Jun 28, 2019
ed13205
Update lockfile
Jun 28, 2019
e248a03
Revert "Update lockfile"
Jun 28, 2019
ab6e2d3
Revert "Revert "Update lockfile""
Jun 28, 2019
7ea0d53
Update lockfile
Jun 28, 2019
027b002
Merge branch 'master' into master
Jun 28, 2019
ba740af
Adjust install location of `parseurl` to be within `apollo-server-exp…
abernix Jun 30, 2019
240c02b
docs: Adjust formatting of `applyMiddleware` header to be in gave acc…
abernix Jun 30, 2019
4c8c3fb
docs: Add documentation for `getMiddleware`.
abernix Jun 30, 2019
254971e
Merge remote-tracking branch 'origin/master' into HEAD
abernix Jun 30, 2019
e68cf95
Merge branch 'release-2.7.0' into HEAD
abernix Jun 30, 2019
c3a23e7
Add CHANGELOG.md for #2435.
abernix Jun 30, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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)
- `apollo-server-express`, `apollo-server-koa`, `apollo-server-hapi`: 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:
>
Expand Down
10 changes: 9 additions & 1 deletion docs/source/api/apollo-server.md
Original file line number Diff line number Diff line change
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,6 +193,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