Use graphql-upload instead of the outdated apollo-server setup.
For context see: https://github.com/jaydenseric/graphql-upload/issues/109.
This commit is contained in:
parent
6b56aa3819
commit
921aa517ba
16
api/package-lock.json
generated
16
api/package-lock.json
generated
@ -1952,6 +1952,11 @@
|
|||||||
"integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=",
|
"integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"fs-capacitor": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/fs-capacitor/-/fs-capacitor-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-XdZK0Q78WP29Vm3FGgJRhRhrBm51PagovzWtW2kJ3Q6cYJbGtZqWSGTSPwvtEkyjIirFd7b8Yes/dpOYjt4RRQ=="
|
||||||
|
},
|
||||||
"fs.realpath": {
|
"fs.realpath": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||||
@ -2653,6 +2658,17 @@
|
|||||||
"uuid": "^3.1.0"
|
"uuid": "^3.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"graphql-upload": {
|
||||||
|
"version": "8.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/graphql-upload/-/graphql-upload-8.0.0.tgz",
|
||||||
|
"integrity": "sha512-DlEi6+Kblj6gAAA5XJahJl1+UfcXICiFypJYIxd4zK26W2/LKm6nwLmSWjECwbAkz/OtB+oSWGb5gqXCDQOLqg==",
|
||||||
|
"requires": {
|
||||||
|
"busboy": "^0.2.14",
|
||||||
|
"fs-capacitor": "^1.0.0",
|
||||||
|
"http-errors": "^1.7.1",
|
||||||
|
"object-path": "^0.11.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"has": {
|
"has": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
"apollo-server-koa": "^2.1.0",
|
"apollo-server-koa": "^2.1.0",
|
||||||
"dotenv": "^6.1.0",
|
"dotenv": "^6.1.0",
|
||||||
"graphql": "^14.0.2",
|
"graphql": "^14.0.2",
|
||||||
|
"graphql-upload": "^8.0.0",
|
||||||
"koa": "^2.6.1",
|
"koa": "^2.6.1",
|
||||||
"lowdb": "^1.0.0",
|
"lowdb": "^1.0.0",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
import { GraphQLUpload } from 'graphql-upload'
|
||||||
import promisesAll from 'promises-all'
|
import promisesAll from 'promises-all'
|
||||||
import mkdirp from 'mkdirp'
|
import mkdirp from 'mkdirp'
|
||||||
import shortid from 'shortid'
|
import shortid from 'shortid'
|
||||||
@ -39,12 +40,14 @@ const storeDB = file =>
|
|||||||
.write()
|
.write()
|
||||||
|
|
||||||
const processUpload = async upload => {
|
const processUpload = async upload => {
|
||||||
const { stream, filename, mimetype } = await upload
|
const { createReadStream, filename, mimetype } = await upload
|
||||||
|
const stream = createReadStream()
|
||||||
const { id, path } = await storeFS({ stream, filename })
|
const { id, path } = await storeFS({ stream, filename })
|
||||||
return storeDB({ id, filename, mimetype, path })
|
return storeDB({ id, filename, mimetype, path })
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
Upload: GraphQLUpload,
|
||||||
Query: {
|
Query: {
|
||||||
uploads: () => db.get('uploads').value()
|
uploads: () => db.get('uploads').value()
|
||||||
},
|
},
|
||||||
|
|||||||
@ -2,14 +2,28 @@ import Koa from 'koa'
|
|||||||
import apolloServerKoa from 'apollo-server-koa'
|
import apolloServerKoa from 'apollo-server-koa'
|
||||||
import typeDefs from './types.mjs'
|
import typeDefs from './types.mjs'
|
||||||
import resolvers from './resolvers.mjs'
|
import resolvers from './resolvers.mjs'
|
||||||
|
import { graphqlUploadKoa } from 'graphql-upload'
|
||||||
|
|
||||||
const app = new Koa()
|
const app = new Koa().use(
|
||||||
const server = new apolloServerKoa.ApolloServer({ typeDefs, resolvers })
|
graphqlUploadKoa({
|
||||||
|
maxFileSize: 10000000, // 10 MB
|
||||||
|
maxFiles: 20
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const server = new apolloServerKoa.ApolloServer({
|
||||||
|
typeDefs,
|
||||||
|
resolvers,
|
||||||
|
|
||||||
|
// Disable outdated built in uploads, to setup graphql-upload instead.
|
||||||
|
uploads: false
|
||||||
|
})
|
||||||
|
|
||||||
server.applyMiddleware({ app })
|
server.applyMiddleware({ app })
|
||||||
|
|
||||||
app.listen(process.env.PORT, error => {
|
app.listen(process.env.PORT, error => {
|
||||||
if (error) throw error
|
if (error) throw error
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.info(
|
console.info(
|
||||||
`Serving http://localhost:${process.env.PORT} for ${process.env.NODE_ENV}.`
|
`Serving http://localhost:${process.env.PORT} for ${process.env.NODE_ENV}.`
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
export default /* GraphQL */ `
|
export default /* GraphQL */ `
|
||||||
|
scalar Upload
|
||||||
|
|
||||||
type File {
|
type File {
|
||||||
id: ID!
|
id: ID!
|
||||||
path: String!
|
path: String!
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user