From eadf5c14c331bb83e5abac2237abeea51a8a4d87 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Mon, 27 Mar 2023 19:27:07 +0200 Subject: [PATCH] feat: Add graphql proxy endpoint --- src/api/v2/proxy_get.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/api/v2/proxy_get.js b/src/api/v2/proxy_get.js index 51a08db..e31e992 100644 --- a/src/api/v2/proxy_get.js +++ b/src/api/v2/proxy_get.js @@ -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