如何将Next.js与graphql-yoga结合?我想将一条路线“ / graphql”专用于瑜伽,将其余路线用于next.js。我已经尝试过了,但是它没有返回这样的错误代码。
import { GraphQLServer } from 'graphql-yoga'
import { permissions } from '../permissions'
import { schema } from '../schema'
import { createContext } from '../context'
import { parse } from 'url'
import next from 'next'
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const server = new GraphQLServer({
schema,
context: createContext,
middlewares: [permissions],
})
server.express.get('/', (req, res) => {
const parsedUrl = parse(req.url!, true)
handle(req, res, parsedUrl)
})
server.start(() =>
console.log(`? Server ready at: ${process.env.PORT ?? 4000}\n⭐️`),
)