graphql-framework-experiment icon indicating copy to clipboard operation
graphql-framework-experiment copied to clipboard

Large request - bodyParser - missing query field

Open AliUP-sro opened this issue 5 years ago • 5 comments

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 avatar Jul 31 '20 17:07 AliUP-sro

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

mipyykko avatar Jul 31 '20 18:07 mipyykko

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)
		},
	},
})

AliUP-sro avatar Jul 31 '20 21:07 AliUP-sro

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.

mipyykko avatar Jul 31 '20 21:07 mipyykko

@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 avatar Jul 31 '20 22:07 AliUP-sro

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
}))

AliUP-sro avatar Aug 04 '20 07:08 AliUP-sro