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

Upgrade to graphql-upload v8, dropping upload support for Node.js v6. #2054

Merged
merged 11 commits into from Dec 4, 2018
Merged
12 changes: 11 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,16 @@
# Changelog

### vNEXT
### v2.3.0-alpha

- **BREAKING FOR NODE.JS <= 8.5.0 ONLY**: To continue using Apollo Server 2.x in versions of Node.js prior to v8.5.0, file uploads must be disabled by setting `uploads: false` on the `ApolloServer` constructor options. Without explicitly disabling file-uploads, the server will `throw` at launch (with instructions and a link to our documentation).

This early deprecation is due to changes in the third-party `graphql-upload` package which Apollo Server utilizes to implement out-of-the-box file upload functionality. While, in general, Apollo Server 2.x aims to support all Node.js versions which were under an LTS policy at the time of its release, we felt this required an exception. By `throw`-ing when `uploads` is not explicitly set to `false`, we aim to make it clear immediately (rather than surprisingly) that this deprecation has taken effect.

While Node.js 6.x is covered by a [Long Term Support agreement by the Node.js Foundation](https://github.com/nodejs/Release#release-schedule) until April 2019, there are substantial performance (e.g. [V8](https://v8.dev/) improvements) and language changes (e.g. "modern" ECMAScript support) offered by newer Node.js engines (e.g. 8.x, 10.x). We encourage _all users_ of Apollo Server to update to newer LTS versions of Node.js prior to the "end-of-life" dates for their current server version.

**We intend to drop support for Node.js 6.x in the next major version of Apollo Server.**

### v2.2.7-beta.0

- `apollo-engine-reporting`: When multiple instances of `apollo-engine-reporting` are loaded (an uncommon edge case), ensure that `encodedTraces` are handled only once rather than once per loaded instance. [PR #2040](https://github.com/apollographql/apollo-server/pull/2040)

Expand Down
1 change: 1 addition & 0 deletions docs/_config.yml
Expand Up @@ -44,6 +44,7 @@ sidebar_categories:
Migration:
- migration-two-dot
- migration-engine
- migration-file-uploads

github_repo: apollographql/apollo-server
content_root: docs/source
Expand Down
29 changes: 29 additions & 0 deletions docs/source/migration-file-uploads.md
@@ -0,0 +1,29 @@
---
title: File uploads in Node.js < v8.5.0
---

File uploads are supported in Apollo Server 2.x through the third-party [`graphql-upload`](https://npm.im/graphql-upload/) package. While Apollo Server 2.x aims to support Node.js LTS versions prior to v8.5.0, the `graphql-upload` project no longer supports file uploads on versions of Node.js prior to v8.5.0 due to changes in the underlying architecture.

While Node.js versions prior to v8.5.0 are still under [_Long Term Support_ (LTS) agreements](https://github.com/nodejs/Release#release-schedule) from the Node.js Foundation, **we encourage _all users_ of Apollo Server to update to newer LTS versions of Node.js** prior to the "end-of-life" dates for their current server version.

For example, while Node.js 6.x is covered by Long Term Support until April 2019, there are substantial performance (e.g. [V8](https://v8.dev/) improvements) and language changes (e.g. "modern" ECMAScript support) offered by newer Node.js engines (e.g. 8.x, 10.x). Switching to newer Long Term Support versions of Node.js comes with long-term benefits; Node.js 10.x LTS releases are covered by the Node.js Foundation through April 2021.

Since file upload support for Node.js versions prior to v8.5.0 is no longer offered by `graphql-upload`, users of those versions must disable file uploads to continue using newer Apollo Server 2.x versions.

**To disable file uploads and continue using Apollo Server 2.x on Node.js 6.x**, add the `uploads: false` setting to the options when constructing the server. For example:

```js
const { typeDefs, resolvers } = require('./anOutsideDependency');
const server = new ApolloServer({
/* Existing Apollo Server settings — e.g. type definitions */
typeDefs,
resolvers,

/* Add this line to disable upload support! */
uploads: false,

/* ... other Apollo Server settings ... */
})
```

For additional assistance, please [search for existing issues](https://github.com/apollographql/apollo-server/issues?q=uploads) or file a [new issue](https://github.com/apollographql/apollo-server/issues/new) on the Apollo Server GitHub repository.
2 changes: 1 addition & 1 deletion docs/source/whats-new.md
Expand Up @@ -246,7 +246,7 @@ const resolvers = {
Mutation: {
singleUpload: (parent, args) => {
return args.file.then(file => {
//Contents of Upload scalar: https://github.com/jaydenseric/apollo-upload-server#upload-scalar
//Contents of Upload scalar: https://github.com/jaydenseric/graphql-upload#class-graphqlupload
//file.stream is a node stream that contains the contents of the uploaded file
//node stream api: https://nodejs.org/api/stream.html
return file;
Expand Down
105 changes: 53 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/apollo-server-core/package.json
Expand Up @@ -25,7 +25,6 @@
},
"dependencies": {
"@apollographql/apollo-tools": "^0.2.6",
"@apollographql/apollo-upload-server": "^5.0.3",
"@apollographql/graphql-playground-html": "^1.6.6",
"@types/ws": "^6.0.0",
"apollo-cache-control": "file:../apollo-cache-control",
Expand All @@ -40,6 +39,7 @@
"graphql-subscriptions": "^1.0.0",
"graphql-tag": "^2.9.2",
"graphql-tools": "^4.0.0",
"graphql-upload": "^8.0.2",
"json-stable-stringify": "^1.0.1",
"lodash": "^4.17.10",
"subscriptions-transport-ws": "^0.9.11",
Expand Down
47 changes: 43 additions & 4 deletions packages/apollo-server-core/src/ApolloServer.ts
Expand Up @@ -14,6 +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 {
SubscriptionServer,
Expand Down Expand Up @@ -88,6 +89,9 @@ function getEngineServiceId(engine: Config['engine']): string | undefined {
return;
}

const forbidUploadsForTesting =
process && process.env.NODE_ENV === 'test' && !supportsUploadsInNode;

export class ApolloServerBase {
public subscriptionsPath?: string;
public graphqlPath: string = '/graphql';
Expand Down Expand Up @@ -199,8 +203,16 @@ export class ApolloServerBase {
this.requestOptions = requestOptions as GraphQLOptions;
this.context = context;

if (uploads !== false) {
if (uploads !== false && !forbidUploadsForTesting) {
if (this.supportsUploads()) {
if (!supportsUploadsInNode) {
printNodeFileUploadsMessage();
throw new Error(
'`graphql-upload` is no longer supported on Node.js < v8.5.0. ' +
'See https://bit.ly/gql-upload-node-6.',
);
}

if (uploads === true || typeof uploads === 'undefined') {
this.uploadsConfig = {};
} else {
Expand Down Expand Up @@ -249,9 +261,7 @@ export class ApolloServerBase {
);

if (this.uploadsConfig) {
const {
GraphQLUpload,
} = require('@apollographql/apollo-upload-server');
const { GraphQLUpload } = require('graphql-upload');
if (resolvers && !resolvers.Upload) {
resolvers.Upload = GraphQLUpload;
}
Expand Down Expand Up @@ -542,3 +552,32 @@ export class ApolloServerBase {
return processGraphQLRequest(options, requestCtx);
}
}

function printNodeFileUploadsMessage() {
console.error(
[
'*****************************************************************',
'* *',
'* ERROR! Manual intervention is necessary for Node.js < v8.5.0! *',
'* *',
'*****************************************************************',
'',
'The third-party `graphql-upload` package, which is used to implement',
'file uploads in Apollo Server 2.x, no longer supports Node.js LTS',
'versions prior to Node.js v8.5.0.',
'',
'Deployments which NEED file upload capabilities should update to',
'Node.js >= v8.5.0 to continue using uploads.',
'',
'If this server DOES NOT NEED file uploads and wishes to continue',
'using this version of Node.js, uploads can be disabled by adding:',
'',
' uploads: false,',
'',
'...to the options for Apollo Server and re-deploying the server.',
'',
'For more information, see https://bit.ly/gql-upload-node-6.',
'',
].join('\n'),
);
}
16 changes: 14 additions & 2 deletions packages/apollo-server-core/src/index.ts
Expand Up @@ -41,6 +41,18 @@ export const gql: (
...substitutions: any[]
) => DocumentNode = gqlTag;

import supportsUploadsInNode from './utils/supportsUploadsInNode';
import { GraphQLScalarType } from 'graphql';
import { GraphQLUpload as UploadScalar } from '@apollographql/apollo-upload-server';
export const GraphQLUpload = UploadScalar as GraphQLScalarType;
export { default as processFileUploads } from './processFileUploads';

// This is a conditional export intended to avoid traversing the
// entire module tree of `graphql-upload`. This only defined if the
// version of Node.js is >= 8.5.0 since those are the only Node.js versions
// which are supported by `graphql-upload@8`. Since the source of
// `graphql-upload` is not transpiled for older targets (in fact, it includes
// experimental ECMAScript modules), this conditional export is necessary
abernix marked this conversation as resolved.
Show resolved Hide resolved
// 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
? (require('graphql-upload').GraphQLUpload as GraphQLScalarType)
: undefined;
16 changes: 16 additions & 0 deletions packages/apollo-server-core/src/processFileUploads.ts
@@ -0,0 +1,16 @@
import supportsUploadsInNode from './utils/supportsUploadsInNode';

// 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) {
return require('graphql-upload')
.processRequest as typeof import('graphql-upload').processRequest;
}
return undefined;
})();

export default processFileUploads;