Reputation: 10183
How to create one route for receiving non graphql post requests?
I have my graphql server, and want to receive some non graphql data on it.
const server = new GraphQLServer({ ... })
server.express.get('/route', async (req, res, done) => {
const params = req.body;
// do some actions with ctx..
})
How can we access to ctx.db.query
or ctx.db.mutation
from this route?
Thanks!
Related question: 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
Upvotes: 0
Views: 323
Reputation: 2469
You can use the same variable you passed in the context:
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)
})
Upvotes: 1