johnkueh / nextjs9-apollo

0 stars 1 forks source link

POST /api/apollo-server-micro doesn't work locally #2

Open konsumer opened 4 years ago

konsumer commented 4 years ago

I dunno if this is a problem elsewhere, but if I run dev-server, I can GET the playground, but all POSTs just stay "Pending".

git clone https://github.com/yoongfook/nextjs9-apollo.git
cd nextjs9-apollo
npm i
npm run dev

Screenshot from 2019-11-18 16-37-10

Screenshot from 2019-11-18 16-36-47

/api/basic and /api/micro work fine, though.

node: v12.13.0
npm: 6.12.0
ubuntu: 19.10
konsumer commented 4 years ago

I ended up just making my own graphql server:

import { makeExecutableSchema } from 'graphql-tools'

// const typeDefs = ...
// const resolvers = ...
// const playground = `STRING OF PLAYGROUND MINIMAL HTML`

const schema = makeExecutableSchema({ typeDefs,  resolvers})

export default async function handle (req, res) {
  if (req.method === 'GET') {
    return res.send(playground)
  }

  const { query, variables, operationName } = req.body
  const root = {}
  const context = { cookies: req.cookies, body: req.body, query: req.query }
  const out = await graphql(schema, query, root, context, variables, operationName)
  res.json(out)
}