Using upload as argument (graphql type) for mutation
See original GitHub issueI have already successfully implemented uploading files successfully in nexus framework - but with schema I ran out of ideas.
According to the docs (https://nexusjs.org/docs/api/scalar-type) this was my approach:
import { arg, extendType } from '@nexus/schema'
import { GraphQLUpload } from 'apollo-server-express'
export const Upload = GraphQLUpload
extendType({
type: 'Mutation',
definition(t) {
t.crud.deleteOneDocument(),
t.field('uploadSingleDocument', {
type: 'Document',
args: {
file: arg({ type: "Upload", required: true }) //here gives me "Type '"Upload"' is not assignable to type 'NexusArgConfigType"
},
async resolve (_root, args, ctx) {
// ....
},
})
},
})
I`ve also tried some of the solutions from issue #441 but seems like they are not working for my environment.
This is my package.json:
{ "name": "test", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "dev": "ts-node-dev --transpile-only --no-notify api/app.ts", "build": "tsc" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@nexus/schema": "^0.16.0", "@prisma/client": "^2.9.0", "apollo-server": "^2.18.2", "apollo-server-express": "^2.18.2", "express": "^4.17.1", "graphql": "^15.3.0", "graphql-scalars": "^1.4.0", "nexus-plugin-prisma": "^0.21.0" }, "devDependencies": { "@prisma/cli": "^2.9.0", "ts-node-dev": "^1.0.0-pre.65", "typescript": "^4.0.3" } }
I am running npm run dev
while in the code window. Server is running on apollo-express.
This was my working solution with nexus framework (mutation had same code) for binary/multipart upload:
import { GraphQLUpload } from 'apollo-server-core';
import type { FileUpload } from 'graphql-upload';
export type UploadRoot = Promise<FileUpload>;
schema.scalarType({
// Why we need the bang: https://github.com/apollographql/apollo-server/blob/570f548b88750a06fbf5f67a4abe78fb0f870ccd/packages/apollo-server-core/src/index.ts#L49-L56
...GraphQLUpload!,
rootTyping: 'UploadRoot',
})
Please help!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6
Thanks for the awesome help @bkiac!
However we will need to register the Upload scalar alongside the resolvers to the
makeSchema -> type
field.In case anyone wants to centralize your Upload handling you could use the
scalarType
insteadofasNexusMethod
:This works for me with
nexus@^1.0.0
,apollo-server-express@^2.19.0