Skip to content

How can I increase max body size?(413 Payload Too Large) #771

Closed

Description

@xero0001

I'm building online text editor and it uploads image which is converted into base64, so text size is little bit large.

this is the error message. it happend on "update mutaiton"

...
"statusCode": 413,
  "statusMessage": "Payload Too Large",
...

I already increased graphql server payload limit like this.

(index.ts)

server.start(
  {
    endpoint: "/graphql",
    playground: "/graphql",
    subscriptions: false,
    cors: {
      credentials: true,
      origin: ...
    },
    bodyParserOptions: { limit: "64mb", type: "application/json" }
  },
  () =>
    console.log(
      `🚀 Server ready at: http://localhost:4000\n⭐️ See sample queries: http://pris.ly/e/ts/graphql-auth#6-using-the-graphql-api`
    )
);

but sadly it doesn't work.

Activity

  1. pantharshit00 commented on Oct 17, 2019

    @pantharshit00
    Contributor

    Hi,

    Are you using photon in your setup? With the current information, it is not very clear that you are using photon in your setup.

    This looks like more of a GraphQL Yoga issue to me. Try using the body-parser middleware itself instead of the bodyParserOptions. Maybe use apollo-server-express if graphql-yoga is not working for you.

  2. added
    bug/0-unknown
    kind/bug
    on Oct 17, 2019
  3. xero0001 commented on Oct 17, 2019

    @xero0001
    Author

    Oh hi. I'm using photonjs to set up my project based on "prisma2 init" with typescript, Auth example, and mysql.

    I'm planning to start my project with body-parser middleware and apollo-server-express. Then I'll share my results (with some feedback) soon.

    Thank you so much for your support!

  4. xero0001 commented on Oct 21, 2019

    @xero0001
    Author

    Firstly, it doesn't work on graphql-yoga with body-parser middleware.
    (With "prisma2 preview014.2 initialization", Typescript, Auth Example, MySQL)

    Following code is from my server.ts

    const server = new GraphQLServer({
      schema,
      context: createContext,
      middlewares: [permissions],
    })
    
    server.express.use(bodyParser.json({ limit: '1mb' }))
    
    server.start(
      {
        endpoint: '/graphql',
        playground: '/graphql',
        subscriptions: false,
        cors: {
          credentials: true,
          origin: 'http://localhost:3000',
        },
      },
      () =>
        console.log(
          `🚀 Server ready at: http://localhost:4000/graphql\n⭐️ See sample queries: http://pris.ly/e/ts/graphql-auth#5-using-the-graphql-api`,
        ),
    )
    

    Following error is from backend console.

    ...
    
        "method": "POST"
      },
      "statusCode": 413,
      "statusMessage": "Payload Too Large",
      "headers": {
        "connection": "close",
        "content-length": "0",
        "date": "Sun, 20 Oct 2019 23:53:36 GMT"
      },
      "body": ""
    }
    
        at PhotonFetcher.<anonymous> (/Users/arais/workspace/araisdraft/backend-latest/node_modules/@generated/photon/index.js:47:27)
        at Generator.throw (<anonymous>)
        at rejected (/Users/arais/workspace/araisdraft/backend-latest/node_modules/@generated/photon/index.js:6:65)
        at process._tickCallback (internal/process/next_tick.js:68:7)
    

    I will try "apollo-server-express" and comment again.

  5. xero0001 commented on Oct 21, 2019

    @xero0001
    Author

    I found that "apollo-server-express" also doesn't resolve this.

    I used "graphql-apollo-server" example to setup, and replaced "apollo-server" module with "apollo-server-express" module. Also added "express" module and modified code a little bit to set the limitation up to '50mb'.

    import { ApolloServer } from 'apollo-server-express'
    import express from 'express'
    import { schema } from './schema'
    import { createContext } from './context'
    import bodyParser from 'body-parser'
    
    const app = express()
    app.use('/graphql', bodyParser.json({ limit: '50mb' }))
    
    const server = new ApolloServer({
      schema,
      context: createContext,
    })
    
    server.applyMiddleware({ app, path: '/graphql' })
    
    app.listen(4000, () =>
      console.log(
        `🚀 Server ready at: http://localhost:4000\n⭐️ See sample queries: http://pris.ly/e/ts/graphql-apollo-server#5-using-the-graphql-api`,
      ),
    )
    

    Error message is just exactly same with the one from "graphql-yoga" trial.

    captured from Safari.

    �[31m    "method": "POST"�[39m
    �[31m  },�[39m
    �[31m  "statusCode": 413,�[39m
    �[31m  "statusMessage": "Payload Too Large",�[39m
    �[31m  "headers": {�[39m
    �[31m    "connection": "close",�[39m
    �[31m    "content-length": "0",�[39m
    �[31m    "date": "Mon, 21 Oct 2019 20:26:16 GMT"�[39m
    �[31m  },�[39m
    �[31m  "body": ""�[39m
    �[31m}�[39m
    �[31m�[39m, Location: [object Object], Path: updateText
    

    Querying over 200kb doesn't generates error at all.
    But updating large data produces "Payload too large" error.

    And I found that this error is referred to be not caused by GraphQL Yoga or Apollo Server, but by Photonjs.

    prisma/prisma-client-js#246

    So should I go there and ask help to resolve this?

    But difference is that in my case, I didn't get the error when payload size was less than around 200kb. On the other hand, photon is said to have 32kb limitation(according to prisma/prisma-client-js#246).

  6. pantharshit00 commented on Oct 22, 2019

    @pantharshit00
    Contributor

    If there is already a photonjs issue for this, we will address this.

    I will close this as a duplicate of prisma/prisma-client-js#246 for now. Can you please provide me with the exact queries and maybe a git repository of the code for reproduction(post it in the other issue)? That would help us a ton as the other bug is not confirmed.

  7. xero0001 commented on Oct 22, 2019

    @xero0001
    Author

    I shared my repository at the other issue.
    prisma/prisma-client-js#246

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/0-unknownkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions