Skip to content

Commit

Permalink
Lazy-load subscriptions-transport-ws and util.promisify polyfill. (
Browse files Browse the repository at this point in the history
…#2324)

* lazy load unused lambda packages in core

* Style adjustments plus changes to account for other PRs with similar motives.

The work in #2054 was
designed in a way that, irregardless of the environment, the
`graphql-upload` package would only be loaded if uploads were enabled.
Therefore, the guard which checks `process.env.AWS_EXECUTION_ENV` should no
longer be necessary.

Additionally, we don't need to prefix our type-only variables with
underscores, as that's not a style that we've otherwise adopted.

* The work in this was mostly also implemented by #2305, #2304 and #2054, but the remaining subscriptions-transport-ws and unnecessary util.promisify imports are still super worth addressing. So, thank you!
  • Loading branch information
kyeotic authored and abernix committed May 27, 2019
1 parent 3b5618e commit 1a4331d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- core: Expose SHA-256 hex hash digest of the Engine API key to plugins, when available, as `engine.apiKeyHash`. [PR# 2685](https://github.com/apollographql/apollo-server/pull/2685)
- `apollo-datasource-rest`: If another `Content-type` is already set on the response, don't overwrite it with `application/json`, allowing the user's initial `Content-type` to prevail. [PR #2520](https://github.com/apollographql/apollo-server/issues/2035)
- `apollo-cache-control`: Do not respond with `Cache-control` headers if the HTTP response contains `errors`. [PR #2715](https://github.com/apollographql/apollo-server/pull/2715)
- `apollo-server-core`: Skip loading `util.promifisy` polyfill in Node.js engines >= 8.0 [PR #2278](https://github.com/apollographql/apollo-server/pull/2278)
- `apollo-server-core`: Lazy load `subscriptions-transport-ws` in core [PR #2278](https://github.com/apollographql/apollo-server/pull/2278)
- `apollo-server-cache-redis`: **BREAKING FOR USERS OF `apollo-server-cache-redis`** (This is a package that must be updated separately but shares the same `CHANGELOG.md` with Apollo Server itself.) A new **major** version of this package has been published and updated to support Redis Standalone, Cluster and Sentinel modes. This is a breaking change since it is now based on [`ioredis`](https://github.com/luin/ioredis) instead of [`node_redis`](https://github.com/NodeRedis/node_redis). Although this update is compatible with the most common uses of `apollo-server-cache-redis`, please check the [options supported by `ioredis`](https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options) while updating to this version. The constructor options are passed directly from `RedisCache` to the new Redis adapter. The pre-1.0 versions should continue to work with Apollo Server without modification. [PR #1770](https://github.com/apollographql/apollo-server/pull/1770)

### v2.5.0
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export class ApolloServerBase {
);
}
}

const { SubscriptionServer } = require('subscriptions-transport-ws');
const {
onDisconnect,
onConnect,
Expand Down
6 changes: 5 additions & 1 deletion packages/apollo-server-env/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import './polyfills/Object.values';
import './polyfills/Object.entries';

require('util.promisify').shim();
import runtimeSupportsPromisify from './utils/runtimeSupportsPromisify';

if (!runtimeSupportsPromisify) {
require('util.promisify').shim();
}

export * from './polyfills/fetch';
export * from './polyfills/url';
24 changes: 24 additions & 0 deletions packages/apollo-server-env/src/utils/runtimeSupportsPromisify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const runtimeSupportsPromisify = (() => {
if (
process &&
process.release &&
process.release.name === 'node' &&
process.versions &&
typeof process.versions.node === 'string'
) {
const [nodeMajor] = process.versions.node
.split('.', 1)
.map(segment => parseInt(segment, 10));

if (nodeMajor >= 8) {
return true;
}
return false;
}

// If we haven't matched any of the above criteria, we'll remain unsupported
// for this mysterious environment until a pull-request proves us otherwise.
return false;
})();

export default runtimeSupportsPromisify;

0 comments on commit 1a4331d

Please sign in to comment.