question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to create one route for receiving non graphql post requests?

See original GitHub issue

And configure body-parser for it, to access req.body params? So i have my graphql server, and want to receive some non graphql data on it, and get req.body.

server.express.post('/rout',bodyParser.json(), bodyParser.urlencoded({ extended: true }), function(err, req, res, next){
  const params = req.body;
})

I can accesss req.body like in the code sample. But what if i want to enable the bodyParser to several routes?

How can i access the ctx.db.query or ctx.db.mutation from this route?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:10

github_iconTop GitHub Comments

7reactions
yss14commented, Mar 2, 2019

@triesa @mubaidr For me registering custom express router(s) after the graphql server has started works.

await graphQLServer.start(serverOptions);

const customRouter = Express.Router();
customRouter.use(BodyParser());
customRouter.post('/some/other/router', handler);

graphQLServer.express.use(customRouter);
4reactions
peterrogovcommented, Jun 13, 2019

Perhaps this is going to help someone

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

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(...);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create one route for receiving non graphql post ...
So i have my graphql server, and want to receive some non graphql data on it, and get req.body. server.express.post('/rout',bodyParser.json(), ...
Read more >
Serving over HTTP - GraphQL
Your GraphQL HTTP server should handle the HTTP GET and POST methods. GET request#. When receiving an HTTP GET request, the GraphQL query...
Read more >
How to create one route for receiving REST API 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' ......
Read more >
How to receive REST API post requests (non GraphQL)?
How to create one route for receiving non graphql post requests ? I have my graphql server, and want to receive some non...
Read more >
4 Simple Ways to Call a GraphQL API
Let's check out the code: require('isomorphic-fetch'); fetch('http://localhost:4000', { method: 'POST', headers: { 'Content-Type': 'application ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found