prisma-labs / graphql-framework-experiment

Code-First Type-Safe GraphQL Framework
https://nexusjs.org
MIT License
673 stars 66 forks source link

query field not found in request.body #1165

Open james-ff opened 4 years ago

james-ff commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

For built in cors support please +1 https://github.com/graphql-nexus/nexus/issues/380