Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large request - bodyParser - missing query field #1313

Open
AliUP-sro opened this issue Jul 31, 2020 · 5 comments
Open

Large request - bodyParser - missing query field #1313

AliUP-sro opened this issue Jul 31, 2020 · 5 comments
Labels
type/bug Something is not working the way it should

Comments

@AliUP-sro
Copy link

AliUP-sro commented Jul 31, 2020

Sorry if it shouldn't be in this category.

Nexus Report

■ nexus:server:graphql BadRequestError: Invalid body: request entity too large.

Description

I am using graphql-upload and this error occurect. I tried to use bodyParser to solve it like so:
server.express.use(bodyParser.json({type: 'application/json', limit: '10mb'}))

but it throwed another error that
■ nexus:server:graphql BadRequestError: request.body json expected to have a query field

Any ideas how to make it work? Thanks

@AliUP-sro AliUP-sro added the type/bug Something is not working the way it should label Jul 31, 2020
@mipyykko
Copy link

Check that you're not using two different versions of graphql-upload. apollo-server-core bundles an older one.

@AliUP-sro
Copy link
Author

Check that you're not using two different versions of graphql-upload. apollo-server-core bundles an older one.

What exactly do you mean? I'am using just "graphql-upload": "^11.0.0". I don't have apollo-server-core nowhere installed.

"dependencies": {
	"@types/bcryptjs": "^2.4.2",
	"@types/graphql-upload": "^8.0.3",
	"@types/jsonwebtoken": "^8.5.0",
	"bcryptjs": "^2.4.3",
	"body-parser": "^1.19.0",
	"body-parser-graphql": "^1.1.0",
	"graphql-upload": "^11.0.0",
	"jsonwebtoken": "^8.5.1",
	"nexus": "0.25.0",
	"nexus-plugin-jwt-auth": "^1.2.0",
	"nexus-plugin-prisma": "0.16.1"
},

This is my app.ts

import { settings, use, server } from 'nexus'
import { prisma } from 'nexus-plugin-prisma'
import { auth } from 'nexus-plugin-jwt-auth'
import { PrismaClient } from 'nexus-plugin-prisma/client'
import { APP_SECRET } from './utils/index'
import * as bodyParser from 'body-parser'

const prismaClient = new PrismaClient()

server.express.use(bodyParser.json({type: 'application/json', limit: '1mb'}))

use(
	prisma({
		client: { instance: prismaClient },
		features: {
			crud: true,
		}
	})
)

use(
	auth({
		appSecret: APP_SECRET,
	})
)

settings.change({
	server: {
		startMessage: (info) => {
			settings.original.server.startMessage(info)
		},
	},
})

@mipyykko
Copy link

What exactly do you mean? I'am using just "graphql-upload": "^11.0.0". I don't have apollo-server-core nowhere installed.

Ah, sorry for being a bit unclear - I should've added that nexus in the next versions uses apollo-server-express and thus apollo-server-core which in turn uses an older graphql-upload. npm ls graphql-upload (or similar command with yarn) shows the installed versions.

@AliUP-sro
Copy link
Author

@mipyykko

I traced graphql-upload versions in the repository and there is just newest version installed. I have new version of nexus which use apollo-server-express.

yarn list v1.22.4
├─ @types/[email protected]
└─ [email protected]

By the look of it, it should be ok right? I still don't know where could be a problem. All packages are uptodate, all settings are correct(hopefully).

@AliUP-sro
Copy link
Author

Problem with bodyParser for file uploads is not resolved, but I probably found solution.

Use this middleware instead of bodyParser

import { graphqlUploadExpress } from 'graphql-upload'

server.express.use('/graphql', graphqlUploadExpress({
	maxFileSize: 50_000
}))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is not working the way it should
Projects
None yet
Development

No branches or pull requests

1 participant