From 8da6a7e7d96ba8deb2c31645a9055f3db8cfe806 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 28 Jan 2019 15:52:24 -0600 Subject: [PATCH 1/4] strict check for node version for uploads --- .../apollo-server-core/src/utils/supportsUploadsInNode.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/apollo-server-core/src/utils/supportsUploadsInNode.ts b/packages/apollo-server-core/src/utils/supportsUploadsInNode.ts index da5910a9476..98e379caf0a 100644 --- a/packages/apollo-server-core/src/utils/supportsUploadsInNode.ts +++ b/packages/apollo-server-core/src/utils/supportsUploadsInNode.ts @@ -13,9 +13,11 @@ const supportsUploadsInNode = (() => { if (nodeMajor < 8 || (nodeMajor === 8 && nodeMinor < 5)) { return false; } + return true; } - return true; + // not node + return false; })(); export default supportsUploadsInNode; From 367da838b6a5624029818a0650e56d52efc53eff Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Tue, 29 Jan 2019 11:15:30 +0200 Subject: [PATCH 2/4] Rename `supportsUploadsInNode` to `runtimeSupportsUploads`. Since this predicate is no longer Node-specific, this changes the name of (an internal API) to reflect its new nature. Follows-up: https://github.com/apollographql/apollo-server/pull/2235 cc @mrkurt --- packages/apollo-server-core/src/ApolloServer.ts | 6 +++--- packages/apollo-server-core/src/index.ts | 4 ++-- packages/apollo-server-core/src/processFileUploads.ts | 4 ++-- .../{supportsUploadsInNode.ts => runtimeSupportsUploads.ts} | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) rename packages/apollo-server-core/src/utils/{supportsUploadsInNode.ts => runtimeSupportsUploads.ts} (84%) diff --git a/packages/apollo-server-core/src/ApolloServer.ts b/packages/apollo-server-core/src/ApolloServer.ts index 8d81e2f0794..945476ea04d 100644 --- a/packages/apollo-server-core/src/ApolloServer.ts +++ b/packages/apollo-server-core/src/ApolloServer.ts @@ -14,7 +14,7 @@ import { GraphQLExtension } from 'graphql-extensions'; import { EngineReportingAgent } from 'apollo-engine-reporting'; import { InMemoryLRUCache } from 'apollo-server-caching'; import { ApolloServerPlugin } from 'apollo-server-plugin-base'; -import supportsUploadsInNode from './utils/supportsUploadsInNode'; +import runtimeSupportsUploads from './utils/runtimeSupportsUploads'; import { SubscriptionServer, @@ -90,7 +90,7 @@ function getEngineServiceId(engine: Config['engine']): string | undefined { } const forbidUploadsForTesting = - process && process.env.NODE_ENV === 'test' && !supportsUploadsInNode; + process && process.env.NODE_ENV === 'test' && !runtimeSupportsUploads; export class ApolloServerBase { public subscriptionsPath?: string; @@ -205,7 +205,7 @@ export class ApolloServerBase { if (uploads !== false && !forbidUploadsForTesting) { if (this.supportsUploads()) { - if (!supportsUploadsInNode) { + if (!runtimeSupportsUploads) { printNodeFileUploadsMessage(); throw new Error( '`graphql-upload` is no longer supported on Node.js < v8.5.0. ' + diff --git a/packages/apollo-server-core/src/index.ts b/packages/apollo-server-core/src/index.ts index a53b0e669e7..dd6015c4213 100644 --- a/packages/apollo-server-core/src/index.ts +++ b/packages/apollo-server-core/src/index.ts @@ -41,7 +41,7 @@ export const gql: ( ...substitutions: any[] ) => DocumentNode = gqlTag; -import supportsUploadsInNode from './utils/supportsUploadsInNode'; +import runtimeSupportsUploads from './utils/runtimeSupportsUploads'; import { GraphQLScalarType } from 'graphql'; export { default as processFileUploads } from './processFileUploads'; @@ -53,6 +53,6 @@ export { default as processFileUploads } from './processFileUploads'; // experimental ECMAScript modules), this conditional export is necessary // to avoid modern ECMAScript from failing to parse by versions of Node.js // which don't support it (yet — eg. Node.js 6 and async/await). -export const GraphQLUpload = supportsUploadsInNode +export const GraphQLUpload = runtimeSupportsUploads ? (require('graphql-upload').GraphQLUpload as GraphQLScalarType) : undefined; diff --git a/packages/apollo-server-core/src/processFileUploads.ts b/packages/apollo-server-core/src/processFileUploads.ts index 364848f406d..c2e0cb84808 100644 --- a/packages/apollo-server-core/src/processFileUploads.ts +++ b/packages/apollo-server-core/src/processFileUploads.ts @@ -1,6 +1,6 @@ /// -import supportsUploadsInNode from './utils/supportsUploadsInNode'; +import runtimeSupportsUploads from './utils/runtimeSupportsUploads'; // We'll memoize this function once at module load time since it should never // change during runtime. In the event that we're using a version of Node.js @@ -8,7 +8,7 @@ import supportsUploadsInNode from './utils/supportsUploadsInNode'; const processFileUploads: | typeof import('graphql-upload').processRequest | undefined = (() => { - if (supportsUploadsInNode) { + if (runtimeSupportsUploads) { return require('graphql-upload') .processRequest as typeof import('graphql-upload').processRequest; } diff --git a/packages/apollo-server-core/src/utils/supportsUploadsInNode.ts b/packages/apollo-server-core/src/utils/runtimeSupportsUploads.ts similarity index 84% rename from packages/apollo-server-core/src/utils/supportsUploadsInNode.ts rename to packages/apollo-server-core/src/utils/runtimeSupportsUploads.ts index 98e379caf0a..36e6cff7aa6 100644 --- a/packages/apollo-server-core/src/utils/supportsUploadsInNode.ts +++ b/packages/apollo-server-core/src/utils/runtimeSupportsUploads.ts @@ -1,4 +1,4 @@ -const supportsUploadsInNode = (() => { +const runtimeSupportsUploads = (() => { if ( process && process.release && @@ -20,4 +20,4 @@ const supportsUploadsInNode = (() => { return false; })(); -export default supportsUploadsInNode; +export default runtimeSupportsUploads; From d44798a9b7af13ebd082830d347f19a531f08797 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Tue, 29 Jan 2019 11:23:47 +0200 Subject: [PATCH 3/4] Clarify comment regarding false-y default of `runtimeSupportsUploads`. --- .../apollo-server-core/src/utils/runtimeSupportsUploads.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/apollo-server-core/src/utils/runtimeSupportsUploads.ts b/packages/apollo-server-core/src/utils/runtimeSupportsUploads.ts index 36e6cff7aa6..f1a50344a6d 100644 --- a/packages/apollo-server-core/src/utils/runtimeSupportsUploads.ts +++ b/packages/apollo-server-core/src/utils/runtimeSupportsUploads.ts @@ -16,7 +16,8 @@ const runtimeSupportsUploads = (() => { return true; } - // not node + // 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; })(); From d073d1d2d3890a2dc9e8b4ea4b364f15d77233ec Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Tue, 29 Jan 2019 11:25:24 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md for #2235. Ref: https://github.com/apollographql/apollo-server/pull/2235 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a494b08d537..bdba8f8695b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### vNEXT +- Avoid traversing `graphql-uploads` module tree in run-time environments which aren't Node.js. [PR #2235](https://github.com/apollographql/apollo-server/pull/2235) + ### v2.3.2 - Switch from `json-stable-stringify` to `fast-json-stable-stringify`. [PR #2065](https://github.com/apollographql/apollo-server/pull/2065)