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

More strict check for node version for graphql-upload #2235

Merged
merged 4 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;