Update the example API.

This commit is contained in:
Jayden Seric 2021-12-06 23:18:50 +11:00
parent e1131d21b5
commit 826f838df5
6 changed files with 1210 additions and 1700 deletions

2856
api/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -16,34 +16,34 @@
"bugs": "https://github.com/jaydenseric/apollo-upload-examples/issues",
"funding": "https://github.com/sponsors/jaydenseric",
"engines": {
"node": "^12.20 || >= 14.13",
"node": "^12.22.0 || ^14.17.0 || >= 16.0.0",
"npm": ">= 7"
},
"dependencies": {
"apollo-server-koa": "^3.1.2",
"apollo-server-koa": "^3.5.0",
"dotenv": "^10.0.0",
"graphql": "^15.5.1",
"graphql-upload": "^12.0.0",
"koa": "^2.13.1",
"graphql": "^16.0.1",
"graphql-upload": "^13.0.0",
"koa": "^2.13.4",
"make-dir": "^3.1.0",
"shortid": "^2.2.16"
},
"devDependencies": {
"eslint": "^7.32.0",
"eslint-config-env": "^22.0.0",
"eslint": "^8.4.0",
"eslint-config-env": "^23.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-jsdoc": "^36.0.7",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsdoc": "^37.1.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"nodemon": "^2.0.12",
"prettier": "^2.3.2"
"eslint-plugin-prettier": "^4.0.0",
"nodemon": "^2.0.15",
"prettier": "^2.5.1"
},
"scripts": {
"test": "npm run test:eslint && npm run test:prettier",
"test:eslint": "eslint .",
"test:prettier": "prettier -c .",
"dev": "nodemon",
"start": "node -r dotenv/config server.mjs"
"start": "node -r dotenv/config server.mjs",
"eslint": "eslint .",
"prettier": "prettier -c .",
"test": "npm run eslint && npm run prettier"
}
}

View File

@ -7,17 +7,17 @@ export default new GraphQLObjectType({
fields: () => ({
id: {
description: 'Unique ID.',
type: GraphQLNonNull(GraphQLString),
type: new GraphQLNonNull(GraphQLString),
resolve: (storedFileName) => storedFileName,
},
name: {
description: 'File name.',
type: GraphQLNonNull(GraphQLString),
type: new GraphQLNonNull(GraphQLString),
resolve: (storedFileName) => storedFileName,
},
url: {
description: 'File URL.',
type: GraphQLNonNull(GraphQLString),
type: new GraphQLNonNull(GraphQLString),
resolve: (storedFileName) =>
new URL(storedFileName, UPLOAD_DIRECTORY_URL),
},

View File

@ -1,5 +1,5 @@
import { GraphQLList, GraphQLNonNull, GraphQLObjectType } from 'graphql';
import { GraphQLUpload } from 'graphql-upload';
import GraphQLUpload from 'graphql-upload/public/GraphQLUpload.js';
import storeUpload from '../storeUpload.mjs';
import FileType from './FileType.mjs';
@ -8,22 +8,24 @@ export default new GraphQLObjectType({
fields: () => ({
singleUpload: {
description: 'Stores a single file.',
type: GraphQLNonNull(FileType),
type: new GraphQLNonNull(FileType),
args: {
file: {
description: 'File to store.',
type: GraphQLNonNull(GraphQLUpload),
type: new GraphQLNonNull(GraphQLUpload),
},
},
resolve: (parent, { file }) => storeUpload(file),
},
multipleUpload: {
description: 'Stores multiple files.',
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(FileType))),
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(FileType))),
args: {
files: {
description: 'Files to store.',
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLUpload))),
type: new GraphQLNonNull(
new GraphQLList(new GraphQLNonNull(GraphQLUpload))
),
},
},
async resolve(parent, { files }) {

View File

@ -8,7 +8,7 @@ export default new GraphQLObjectType({
fields: () => ({
uploads: {
description: 'All stored files.',
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(FileType))),
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(FileType))),
resolve: () => fs.promises.readdir(UPLOAD_DIRECTORY_URL),
},
}),

View File

@ -1,6 +1,6 @@
import { fileURLToPath } from 'url';
import { ApolloServer } from 'apollo-server-koa';
import { graphqlUploadKoa } from 'graphql-upload';
import graphqlUploadKoa from 'graphql-upload/public/graphqlUploadKoa.js';
import Koa from 'koa';
import makeDir from 'make-dir';
import UPLOAD_DIRECTORY_URL from './config/UPLOAD_DIRECTORY_URL.mjs';