Passing request parameter into middleware which uses ‘createHandler’ function of ‘graphql-http’

Passing request parameter into middleware which uses ‘createHandler’ function of ‘graphql-http’


0

I have created an express server which uses GraphQL for handling requests over HTTP. Among others, the express server has the two middlewares below.

app.use(authenticate);

app.use('/graphql', createHandler({ schema }));

The authenticate middleware invokes a function which has req, res and next as parameters and in certain conditions assigns a value to req.user.

How can I pass the req object into the next middleware which is responsible for handling GraphQL requests?

I’ve searched for it in graphql-http’s documentation but no luck. Any help will be appreciated.
Link to the package’s documentation: https://github.com/graphql/graphql-http#with-express

New contributor

Kristian Golemi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

  • Please share enough code. Otherwise we have to guess what exactly you are doing here

    – pierpy

    4 hours ago

  • I'll try to be more explanatory. In the authenticate middleware I'm checking if the incoming request contains a session parameter in it's headers. If it does, I search in the db for that user and if I find him, I set req.user = userFound and call next(). What I want to do, is pass the request object in the next middleware in the chain, which is the one handling GraphQL requests. Thanks in advance.

    – Kristian Golemi

    2 hours ago


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *