documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Add note to body middleware, and write GraphQL body parser docs

Open rajaomariajaona opened this issue 3 years ago • 14 comments

Bug report

Describe the bug

The request returns 413 Payload too large error when make graphql mutation with large String value (with base64)

Steps to reproduce the behavior

  • Create in content-builder an entity
  • Activate graphql
  • make mutation request with huge string value more than 1mb (with base64 for example)

Expected behavior

The request should return 200 and the mutation should be successful

Code snippets

My config (config/middleware.js)

module.exports = {
  settings: {
    parser: {
      formLimit: '10mb', // modify here limit of the form body
      jsonLimit: '10mb', // modify here limit of the JSON body
      textLimit: '10mb', // modify here limit of the text body
      formidable: {
        maxFileSize: 100 * 1024 * 1024, // multipart data, modify here limit of uploaded file size
      },
    },
  },
}

System

  • Node.js version: 14.18.1
  • NPM version: 6.14.15
  • Strapi version: 3.6.8
  • Database: Postgresql
  • Operating system: Ubuntu
  • Mode : dev (local)

Context

This config fixed the issue

Config in (config/plugins.js)

module.exports = {
  graphql: {
    endpoint: "/graph"
  }
};

Walking track

May be this condition is the problem parser#L43

rajaomariajaona avatar Nov 12 '21 17:11 rajaomariajaona

Need more information about configuration, environment (local/deployed, if deployed where) ect. Give us examples of your current configurations, response messages from client logs, ect.

The template has multiple areas to provide as much information as possible, please do so and once you have respond back and we will reopen the issue.


This is a templated message

Hello, please follow the issue template.

A proper issue submission let's us better understand the origin of your bug and therefore help you.

I will reopen your issue when we receive the issue following the template guidelines and properly fill out the template. You can see the template guidelines for bug reports here.

Please update the issue with the template and we can reopen this report.

Thank you.

derrickmehaffy avatar Nov 12 '21 20:11 derrickmehaffy

Need more information about configuration, environment (local/deployed, if deployed where) ect. Give us examples of your current configurations, response messages from client logs, ect.

The template has multiple areas to provide as much information as possible, please do so and once you have respond back and we will reopen the issue.

This is a templated message

Hello, please follow the issue template.

A proper issue submission let's us better understand the origin of your bug and therefore help you.

I will reopen your issue when we receive the issue following the template guidelines and properly fill out the template. You can see the template guidelines for bug reports here.

Please update the issue with the template and we can reopen this report.

Thank you.

@derrickmehaffy Could you re-open the issue please?

rajaomariajaona avatar Nov 14 '21 04:11 rajaomariajaona

@rajaomariajaona what is the size of the file that you were trying to upload? Can you share a sample of the file? What are the circumstances of your upload? Is it a custom query or is it a built-in CRUD query that's failing? Please provide as much information as possible detailing your problem. It'll only increase the odds of us tracking down the issue sooner.

kasonde avatar Nov 15 '21 12:11 kasonde

@rajaomariajaona what is the size of the file that you were trying to upload? Can you share a sample of the file? What are the circumstances of your upload? Is it a custom query or is it a built-in CRUD query that's failing? Please provide as much information as possible detailing your problem. It'll only increase the odds of us tracking down the issue sooner.

@kasonde I think that the section Step to reproduce contains all step I did. It's a built-in CRUD query. I didn't upload files but an huge String (containing base64). And the 413 payload error happened

rajaomariajaona avatar Nov 16 '21 12:11 rajaomariajaona

Something strange is that it's work if I change the graphql endpoint. I tried to setting the graphql plugins into this:

graphql: {
    endpoint: "/graph"
  }

And it fixed the issue... May be this condition is the problem? parser#L43

rajaomariajaona avatar Nov 16 '21 12:11 rajaomariajaona

We are having the same issue. We are sending base64 encoded files as a request property (for reasons unrelated to Strapi), through our Strapi GraphQL endpoint, and the parser: { jsonLimit: '50mb' } option in config/middleware.js is not being picked up. According to older issues, it used to be picked up and passed into koa-bodyparser.

Some background: The koa-bodyparser module has a jsonLimit setting, that it passes as the limit setting for the co-body module.

However Strapi appears to no longer be passing the jsonLimit setting to koa-bodyparser for GraphQL requests.

This problem does not arise with REST calls, therefore @rajaomariajaona 's workaround make sense. The condition @rajaomariajaona mentions is tucked away deep in a core Strapi library, costing us many hours to find.

We have chosen to do file uploads via REST instead, but this is not very nice for our service architecture.

Until this is fixed, the docs should really state that parser settings will not be used for GraphQL requests. https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#middlewares

jorisw avatar Nov 18 '21 10:11 jorisw

This issue has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/unable-to-post-content-to-strapi-which-is-more-than-1-mb-in-size/4895/11

derrickmehaffy avatar Nov 18 '21 11:11 derrickmehaffy

A community star mentioned this in Discord yesterday. It seems the parser ignores these settings if you are using GraphQL:

v3: https://github.com/strapi/strapi/blob/077741b03725cc981bc984399d553df8a12d89d0/packages/strapi/lib/middlewares/parser/index.js#L40-L45

v4: https://github.com/strapi/strapi/blob/dc9c0f434c3df5efb4a637b4c1bd4d5d2d4e7cee/packages/core/strapi/lib/middlewares/body.js#L17-L21

derrickmehaffy avatar Nov 18 '21 18:11 derrickmehaffy

Hi, You must use the bodyParserConfig in apollo server itself to change the behaviour. Reference documentation: https://www.apollographql.com/docs/apollo-server/api/apollo-server/#bodyparserconfig

alexandrebodin avatar Nov 19 '21 17:11 alexandrebodin

Hi, You must use the bodyParserConfig in apollo server itself to change the behaviour. Reference documentation: https://www.apollographql.com/docs/apollo-server/api/apollo-server/#bodyparserconfig

We need to document this then, moving this issue over to documentation so we can make a note on the primary body middleware and write documentation for the GraphQL side.

derrickmehaffy avatar Nov 19 '21 19:11 derrickmehaffy

Hi, You must use the bodyParserConfig in apollo server itself to change the behaviour. Reference documentation: https://www.apollographql.com/docs/apollo-server/api/apollo-server/#bodyparserconfig

This doesn't work for us:

config/plugins.js

image

image

jorisw avatar Dec 01 '21 16:12 jorisw

Just hit the same problem. @jorisw did you manage to set the limit option for co-body?

vinzenzweber avatar May 11 '22 11:05 vinzenzweber

Apparently this was fixed only very recently: fix: ApolloServer middleware CORS issue

I am on 3.6.9 where this issue still exists in strapi-plugin-graphql

vinzenzweber avatar May 11 '22 12:05 vinzenzweber

Thank you for opening this issue, and sorry for not replying earlier. The documentation team, unfortunately, didn't have time to focus on issues before now.

We recently updated the body middleware documentation.

Does that answer your questions, or is there something in particular you think is missing from that documentation?

pwizla avatar Jun 21 '22 10:06 pwizla

I resolved payload is too large issue on strapi graphql , in REST apis after I configure json limit and formlimit its working but not in graphql strapi in new version. so I find out the solution. and its working great.

config/plugins.js

module.exports = {
  graphql: {
    config: {
      endpoint: "/graphql",
      shadowCRUD: true,
      playgroundAlways: false,
      depthLimit: 7,
      amountLimit: 2000,
      apolloServer: {
        tracing: false,
        bodyParserConfig: {
          // koa-bodyparser/node_modules/co-body/lib/json.js#36
          limit: "256mb",
          // koa-bodyparser/index.js#69
          formLimit: "256mb",
          jsonLimit: "256mb",
          textLimit: "256mb",
          xmlLimit: "256mb",
        },
      },
    },
  },
};

tejasghlade avatar Dec 01 '22 08:12 tejasghlade

Hello. I'm sorry that you were having troubles and that this issue didn't get more attention sooner. I'm cleaning up old documentation issues and I will close this issue now. Feel free to open a new issue if you're still having trouble with the documentation for Strapi v4.11+

pwizla avatar Jul 10 '23 15:07 pwizla