Skip to content

Commit

Permalink
More strict check for node version for graphql-upload (#2235)
Browse files Browse the repository at this point in the history
Stop traversing the `graphql-upload` module tree in all non-Node.js environments, to support subset-V8 runtimes like Fly.io.
  • Loading branch information
mrkurt authored and abernix committed Jan 29, 2019
1 parent 25028e3 commit cd674aa
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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. ' +
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-server-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
4 changes: 2 additions & 2 deletions packages/apollo-server-core/src/processFileUploads.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/// <reference path="./types/graphql-upload.d.ts" />

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
// less than 8.5.0, we'll
const processFileUploads:
| typeof import('graphql-upload').processRequest
| undefined = (() => {
if (supportsUploadsInNode) {
if (runtimeSupportsUploads) {
return require('graphql-upload')
.processRequest as typeof import('graphql-upload').processRequest;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const supportsUploadsInNode = (() => {
const runtimeSupportsUploads = (() => {
if (
process &&
process.release &&
Expand All @@ -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;

0 comments on commit cd674aa

Please sign in to comment.