如何创建一条接收非graphql发布请求的路由?
我有我的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.query
或ctx.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
答案 0 :(得分:1)
您可以使用在上下文中传递的相同变量:
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)
})