Update API dependencies and migrate to Apollo Server v3.

This commit is contained in:
Jayden Seric 2021-08-03 11:00:31 +10:00
parent 4b8ab99a11
commit aed05449dc
3 changed files with 918 additions and 1071 deletions

1928
api/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -20,24 +20,24 @@
"npm": ">= 7"
},
"dependencies": {
"apollo-server-koa": "^2.25.1",
"apollo-server-koa": "^3.1.1",
"dotenv": "^10.0.0",
"graphql": "^15.5.0",
"graphql": "^15.5.1",
"graphql-upload": "^12.0.0",
"koa": "^2.13.1",
"make-dir": "^3.1.0",
"shortid": "^2.2.16"
},
"devDependencies": {
"eslint": "^7.28.0",
"eslint-config-env": "^21.0.0",
"eslint": "^7.32.0",
"eslint-config-env": "^22.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.3.0",
"eslint-plugin-jsdoc": "^36.0.6",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"nodemon": "^2.0.7",
"prettier": "^2.3.1"
"nodemon": "^2.0.12",
"prettier": "^2.3.2"
},
"scripts": {
"test": "npm run test:eslint && npm run test:prettier",

View File

@ -6,25 +6,6 @@ import makeDir from 'make-dir';
import UPLOAD_DIRECTORY_URL from './config/UPLOAD_DIRECTORY_URL.mjs';
import schema from './schema/index.mjs';
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,
}).applyMiddleware({ app });
/**
* Starts the API server.
*/
@ -32,13 +13,29 @@ async function startServer() {
// Ensure the upload directory exists.
await makeDir(fileURLToPath(UPLOAD_DIRECTORY_URL));
app.listen(process.env.PORT, (error) => {
if (error) throw error;
const apolloServer = new ApolloServer({ schema });
console.info(
`Serving http://localhost:${process.env.PORT} for ${process.env.NODE_ENV}.`
);
});
await apolloServer.start();
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,
})
)
.use(apolloServer.getMiddleware())
.listen(process.env.PORT, (error) => {
if (error) throw error;
console.info(
`Serving http://localhost:${process.env.PORT} for ${process.env.NODE_ENV}.`
);
});
}
startServer();