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) 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 58% rename from packages/apollo-server-core/src/utils/supportsUploadsInNode.ts rename to packages/apollo-server-core/src/utils/runtimeSupportsUploads.ts index da5910a9476..f1a50344a6d 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 && @@ -13,9 +13,12 @@ const supportsUploadsInNode = (() => { if (nodeMajor < 8 || (nodeMajor === 8 && nodeMinor < 5)) { return false; } + return true; } - return true; + // 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 supportsUploadsInNode; +export default runtimeSupportsUploads;