[英]You need to provide explicit type for 'file' of 'InputType' class. | Type-graphql
I try to create a GraphQL endpoint, where I can upload a file.我尝试创建一个 GraphQL 端点,我可以在其中上传文件。
In my resolver I get as arguments context and data with a custom type在我的解析器中,我得到 arguments 上下文和自定义类型的数据
import { ReturnType, InputType } from '@pkg/schemas'
import { Context } from '@pkg/types'
import { GraphQLUpload } from 'graphql-upload'
...
@Mutation(() => ReturnType)
uploadFileAndData(
@Ctx() ctx: Context,
@Arg('data', () => GraphQLUpload, { description: 'File Upload' }) data: InputType,
): Promise<ReturnType> {
return functionWithMagic({ ctx, data })
}
My input type looks like:我的输入类型如下:
import { FileUpload } from 'graphql-upload'
...
@InputType({ description: 'Upload data input' })
export class InputType {
@Field({
nullable: true,
description: 'File upload',
})
@Joiful.any()
file: FileUpload
}
But when I try to run my code I get an error message:但是当我尝试运行我的代码时,我收到一条错误消息:
Error: Unable to infer GraphQL type from TypeScript reflection system. You need to provide explicit type for 'file' of 'InputType' class.
To fix this issue I changed following为了解决这个问题,我改变了以下
@Mutation(() => ReturnType)
uploadFileAndData(
@Ctx() ctx: Context,
@Arg('data', { description: 'File Upload' }) data: InputType,
): Promise<ReturnType> {
return functionWithMagic({ ctx, data })
}
and in my ReturnType I added在我的 ReturnType 我添加了
import { FileUpload, GraphQLUpload } from 'graphql-upload'
...
@InputType({ description: 'Upload data input' })
export class InputType {
@Field(() => GraphQLUpload)
@Joiful.any()
file: FileUpload
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.