I was facing the same issue. You have to define your own Upload type, define a custom scalar in your codegen.yml
config file, and some other things.
# codegen.yml
config:
scalars:
Date: Date
Upload: FileUpload
You can import your custom FileUpload type in your generated files with the plugin add-content of graphql-codegen (@graphql-codegen/add
):
# codegen.yml
generates:
# Schema ans resolvers types
./src/graphql/generated/schema.types.ts:
plugins:
- add:
content: "import { FileUpload } from \"path/to/your/type/file\""
- typescript
import { ReadStream } from "fs"
export interface FileUpload {
filename: string
mimetype: string
encoding: string
createReadStream(): ReadStream
}
BTW, you should install @types/node
.
And, in order to make things simpler, you must define a scalar in your graphql schema (otherwise graphl-cogeden will tell you that Upload
is unknown.
So:
# schema.graphql
scalar Upload
And, if you use Apollo Server 2, the default Apollo's behaviour is to automatically add scalar Upload
in your schema, so you need to use the makeExecutableSchema
from, graphql-tools
!
const server = new ApolloServer({
schema: makeExecutableSchema({
typeDefs: schema,
resolvers,
})
Enjoy!