How to create one route for receiving REST API post requests?


#1

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 i access the ctx.db.query or ctx.db.mutation from this route?
Thanks!

Related question: https://github.com/prisma/graphql-yoga/issues/482


#2

You may try the following idea

const prismaClient = new Prisma({
  typeDefs: path.join(__dirname, './generated-schema.graphql'),
  endpoint: 'http://localhost:4466/nacho/prod',
});

const server = new GraphQLServer({
  typeDefs,
  resolvers,
  directiveResolvers,
  context: req => ({
...req,
db: prismaClient,
  }),
})

server.express.get('/route', async (req, res, done) => {
const params = req.body;
// Invoke prisma from here
let smth = await prismaClient.query.users(...);
});