feat: Add graphql proxy endpoint

This commit is contained in:
Yarmo Mackenbach 2023-03-27 19:27:07 +02:00
parent 8a311f5dc6
commit eadf5c14c3
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1

View file

@ -277,4 +277,26 @@ router.get(
}
)
// GraphQL route
router.get(
'/graphql',
query('url').isURL(),
query('query').isString(),
async (req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
fetcher.graphql
.fn(req.query, opts)
.then((data) => {
return res.status(200).send(data)
})
.catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err })
})
}
)
export default router