From bff2ccf700eba8355c4e7469ee3b02e0c808f5bd Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Thu, 23 Jul 2020 00:18:52 +1000 Subject: [PATCH] Switch to a manual graphql-upload setup. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows the current graphql-upload version to be used instead of the outdated version shipped with Apollo Server, which doesn’t support recent Node.js versions. See https://github.com/apollographql/apollo-server/issues/3508#issuecomment-662371289 . --- api/package-lock.json | 38 +++++++++++++++++++++++++++++++------- api/package.json | 1 + api/schema/MutationType.js | 2 +- api/server.js | 16 +++++++++++----- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/api/package-lock.json b/api/package-lock.json index 46d902b..415c07e 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -578,6 +578,24 @@ "sha.js": "^2.4.11", "subscriptions-transport-ws": "^0.9.11", "ws": "^6.0.0" + }, + "dependencies": { + "fs-capacitor": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/fs-capacitor/-/fs-capacitor-2.0.4.tgz", + "integrity": "sha512-8S4f4WsCryNw2mJJchi46YgB6CR5Ze+4L1h8ewl9tEpL4SJ3ZO+c/bS4BWhB8bK+O3TMqhuZarTitd0S0eh2pA==" + }, + "graphql-upload": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/graphql-upload/-/graphql-upload-8.1.0.tgz", + "integrity": "sha512-U2OiDI5VxYmzRKw0Z2dmfk0zkqMRaecH9Smh1U277gVgVe9Qn+18xqf4skwr4YJszGIh7iQDZ57+5ygOK9sM/Q==", + "requires": { + "busboy": "^0.3.1", + "fs-capacitor": "^2.0.4", + "http-errors": "^1.7.3", + "object-path": "^0.11.4" + } + } } }, "apollo-server-env": { @@ -1823,9 +1841,9 @@ "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, "fs-capacitor": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/fs-capacitor/-/fs-capacitor-2.0.4.tgz", - "integrity": "sha512-8S4f4WsCryNw2mJJchi46YgB6CR5Ze+4L1h8ewl9tEpL4SJ3ZO+c/bS4BWhB8bK+O3TMqhuZarTitd0S0eh2pA==" + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/fs-capacitor/-/fs-capacitor-6.2.0.tgz", + "integrity": "sha512-nKcE1UduoSKX27NSZlg879LdQc94OtbOsEmKMN2MBNudXREvijRKx2GEBsTMTfws+BrbkJoEuynbGSVRSpauvw==" }, "fs.realpath": { "version": "1.0.0", @@ -1979,13 +1997,14 @@ } }, "graphql-upload": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/graphql-upload/-/graphql-upload-8.1.0.tgz", - "integrity": "sha512-U2OiDI5VxYmzRKw0Z2dmfk0zkqMRaecH9Smh1U277gVgVe9Qn+18xqf4skwr4YJszGIh7iQDZ57+5ygOK9sM/Q==", + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/graphql-upload/-/graphql-upload-11.0.0.tgz", + "integrity": "sha512-zsrDtu5gCbQFDWsNa5bMB4nf1LpKX9KDgh+f8oL1288ijV4RxeckhVozAjqjXAfRpxOHD1xOESsh6zq8SjdgjA==", "requires": { "busboy": "^0.3.1", - "fs-capacitor": "^2.0.4", + "fs-capacitor": "^6.1.0", "http-errors": "^1.7.3", + "isobject": "^4.0.0", "object-path": "^0.11.4" } }, @@ -2279,6 +2298,11 @@ "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, + "isobject": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-4.0.0.tgz", + "integrity": "sha512-S/2fF5wH8SJA/kmwr6HYhK/RI/OkhD84k8ntalo0iJjZikgq1XFvR5M8NPT1x5F7fBwCG3qHfnzeP/Vh/ZxCUA==" + }, "iterall": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.3.0.tgz", diff --git a/api/package.json b/api/package.json index 36a1302..ccf3b76 100644 --- a/api/package.json +++ b/api/package.json @@ -14,6 +14,7 @@ "apollo-server-koa": "^2.16.0", "dotenv": "^8.2.0", "graphql": "^15.3.0", + "graphql-upload": "^11.0.0", "koa": "^2.13.0", "lowdb": "^1.0.0", "mkdirp": "^1.0.4", diff --git a/api/schema/MutationType.js b/api/schema/MutationType.js index 78e368e..42c7586 100644 --- a/api/schema/MutationType.js +++ b/api/schema/MutationType.js @@ -1,7 +1,7 @@ 'use strict'; -const { GraphQLUpload } = require('apollo-server-koa'); const { GraphQLList, GraphQLObjectType, GraphQLNonNull } = require('graphql'); +const { GraphQLUpload } = require('graphql-upload'); const FileType = require('./FileType'); module.exports = new GraphQLObjectType({ diff --git a/api/server.js b/api/server.js index 28dd4dd..c7fc2ea 100644 --- a/api/server.js +++ b/api/server.js @@ -2,6 +2,7 @@ const { createWriteStream, unlink } = require('fs'); const { ApolloServer } = require('apollo-server-koa'); +const { graphqlUploadKoa } = require('graphql-upload'); const Koa = require('koa'); const lowdb = require('lowdb'); const FileSync = require('lowdb/adapters/FileSync'); @@ -62,17 +63,22 @@ const storeUpload = async (upload) => { return file; }; -const app = new Koa(); - -new ApolloServer({ - uploads: { +const app = new Koa().use( + graphqlUploadKoa({ // Limits here should be stricter than config for surrounding // infrastructure such as Nginx so errors can be handled elegantly by // `graphql-upload`: // https://github.com/jaydenseric/graphql-upload#type-processrequestoptions maxFileSize: 10000000, // 10 MB maxFiles: 20, - }, + }) +); + +new ApolloServer({ + // Disable the built in file upload implementation that uses an outdated + // `graphql-upload` version, see: + // https://github.com/apollographql/apollo-server/issues/3508#issuecomment-662371289 + uploads: false, schema, context: { db, storeUpload }, }).applyMiddleware({ app });