jaydenseric / graphql-upload

Middleware and a scalar Upload 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 132 forks source link

Exceeding maxFieldSize generates unhelpful error message #159

Closed sgehrman closed 5 years ago

sgehrman commented 5 years ago

I've noticed that some jpgs I upload, I get this error: BadRequestError: Invalid JSON in the ‘operations’ multipart field (https://github.com/jaydenseric/graphql-multipart-request-spec).

Some jpgs work fine, also noticed gifs give the same error.

sgehrman commented 5 years ago

After googling for a few hours, I figured it out. The docs aren't great.

const fileUploadOptions = {
    maxFieldSize: 1024 * 1024 * 10
};

const server = new ApolloServer({
    uploads: fileUploadOptions
});
mike-marcacci commented 5 years ago

@sgehrman - thanks for the report. Not sure how I missed this (my GitHub notifications have been having problems). This sounds like a bug in the sense that the error message is incorrect, even if the behavior (error if the field is too large) is correct.

@JacobT14 there are essentially 2 possibilities:

  1. The request is in fact invalid.
  2. You are hitting the max field size. It looks like we have a poor error message, but the actual behavior is correct. To eliminate this as a possibility, set maxFieldSize to Infinity.