jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 131 forks source link

Can't upload on Nest.js #301

Closed Sydwelll closed 2 years ago

Sydwelll commented 2 years ago

Here is my mutation :

@Mutation(() => Boolean)
  async uploadProfilePicture(
    @Args('attachment', { type: () => GraphQLUpload }) attachment: FileUpload,
  ) {
    await this.uploadService.uploadPublicFile(attachment);
  }

Here is my GraphQLModule configuration :

GraphQLModule.forRootAsync<ApolloDriverConfig>({
          driver: ApolloDriver,
          imports: [ConfigModule],
          inject: [ConfigService],
          useFactory: (configService: ConfigService) => {
            return {
              .....
              uploads: false,
              path: '/graphql',
              ....

and in my AppModule i added :

export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(graphqlUploadExpress()).forRoutes('graphql');
  }
}

Here's my package.json

....
"@nestjs/graphql": "^10.0.8",
"apollo-server-express": "^3.6.7",
"graphql": "^15",
"graphql-upload": "^13.0.0",
......

And i'm getting this error : (i tried with my Next.js frontend and Postman)

Missing multipart field ‘operations’ (https://github.com/jaydenseric/graphql-multipart-request-spec).

jaydenseric commented 2 years ago

I'm not a Nest.js user so it's better to ask the Nest.js community for help with Nest.js.

In this case though, maybe the error is legit? Maybe the problem is the front end is not sending a valid GraphQL multipart request due to the missing multipart field operations.

Sydwelll commented 2 years ago

As i said, i also tried it with Postman with the 'operations' field