PRISMA:如何接收 REST API post 请求(非 GraphQL)?

PRISMA: How to receive REST API post requests (non GraphQL)?

如何创建一个路由来接收非 graphql post 请求?

我有自己的 graphql 服务器,想在上面接收一些非 graphql 数据。

const server = new GraphQLServer({ ... })

server.express.get('/route', async (req, res, done) => {
  const params = req.body;
  // do some actions with ctx..
})

我们如何从这条路线访问 ctx.db.queryctx.db.mutation? 谢谢!

相关问题:https://github.com/prisma/graphql-yoga/issues/482 https://www.prisma.io/forum/t/how-to-create-one-route-for-receiving-rest-api-post-requests/7239

您可以使用在上下文中传递的相同变量:

const { prisma } = require('./generated/prisma-client')
const { GraphQLServer } = require('graphql-yoga')

const server = new GraphQLServer({
  typeDefs: './schema.graphql',
  resolvers,
  context: {
    prisma,
  },
})

server.express.get('/route', async (req, res, done) => {
  const params = req.body;
  const user = prisma.user({where: {id: params.id} })

  res.send(user)
})