As a newbie in NestJS + GraphQL, I'm having trouble with uploading files through GraphQL. I have such resolver:
@Mutation(() => Group)
async sendMessageToGroup(
@AuthToken() token: string,
@Args('input') message: CreateMessageInput,
@Args({ name: 'files', type: () => [UploadFileScalar], nullable: true })
files?: FileUpload[],
) {
const payload = this.tokenService.decodeToken(token);
return this.messageService.sendMessageToGroup(
{ ...message, files: files },
payload.sub,
);
}
UploadFileScalar class:
@Scalar('UploadFileScalar')
export class UploadFileScalar {
description = 'File upload scalar type';
parseValue(value: any): any {
return value;
}
serialize(value: any): any {
return value;
}
parseLiteral(ast: any): any {
return ast.value;
}
}
FileUpload interface:
export interface FileUpload {
filename: string;
mimetype: string;
encoding: string;
createReadStream(): ReadStream;
}
Since the apollo client doesn't support uploading files, I tried to do it through Altair, but I keep getting this error. I suppose, error is somehow related to the "Content-Type" header, which is set to "multipart/form-data" by default, but i don't see other options for this. Would be very grateful if someone could help solve this problem.