Skip to content

query field not found in request.body #1165

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

Open
james-ff opened this issue Jul 2, 2020 · 2 comments
Open

query field not found in request.body #1165

james-ff opened this issue Jul 2, 2020 · 2 comments
Labels
plugin/prisma type/bug Something is not working the way it should

Comments

@james-ff
Copy link

james-ff commented Jul 2, 2020

Nexus Report

{
  "node": "v14.4.0",
  "os": {
    "platform": "darwin",
    "release": "19.5.0"
  },
  "nexus": "0.24.2",
  "plugins": [
    "nexus-plugin-prisma"
  ],
  "otherDependencies": {},
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "3.4.0",
    "@typescript-eslint/parser": "3.4.0",
    "eslint": "7.3.1",
    "eslint-config-prettier": "6.11.0",
    "eslint-plugin-prettier": "3.1.4",
    "prettier": "2.0.5"
  },
  "hasAppModule": true,
  "packageManager": "yarn",
  "errorsWhileGatheringReport": {
    "gettingLayout": null,
    "gettingPluginManifests": null
  }
}

Screenshot

Screen Shot 2020-07-02 at 03 08 35

Description

API setup (with schema.queryType and basic crud definitions added):

import { use } from 'nexus'
import { prisma } from 'nexus-plugin-prisma'

use(prisma({ features: { crud: true } }))

Nexus crud Queries run in GraphiQL or other clients works as expected.

However when called via a Next.js + ApolloClient SPA locally, nexus gives the error:

BadRequestError: request.body json expected to have a query field

But in the network inspector: the requesy.body query field does appear to be present:

Screen Shot 2020-07-02 at 03 17 33

Screen Shot 2020-07-02 at 03 17 43

And the ApolloClient responds with the following, as it doesn't get a json response from the 400:

JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

It's not clear to me if this is a nexus or an apollo issue, any clarificaiton or insight would be helpful!

Many Thanks,

James.

Repro

Follow nexus + prisma, and next.js + apollo, setup guides:
https://www.nexusjs.org/#/plugins/prisma
https://github.com/vercel/next.js/tree/canary/examples/with-typescript-graphql

@james-ff james-ff added plugin/prisma type/bug Something is not working the way it should labels Jul 2, 2020
@james-ff
Copy link
Author

james-ff commented Jul 5, 2020

Changed app.ts to this (and a few other changes in Apollo) seemed to fix the issue, not entirely sure why:

import { use, server } from 'nexus'
import { prisma } from 'nexus-plugin-prisma'

import cors from 'cors'

use(prisma({ features: { crud: true }, paginationStrategy: 'prisma' }))

server.express.use(cors())

Seemed to be down to cors not being configured, can we get cors support built in?

@jasonkuhrt
Copy link
Member

For built in cors support please +1 graphql-nexus/nexus#380

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

No branches or pull requests

2 participants