Search code examples
graphqlapolloapollo-server

Apollo Server Health Check custom response


I am currently looking to provide more information to the health check other than status: pass. Is this possible? I tried sending test strings unfortunately, I am still seeing the same response json. Thank you in advance!

Code:

       onHealthCheck: (req) => {
            return new Promise((resolve, reject) => {
                if(true) {
                    console.log(req);
                    resolve(req);
                    //resolve("test")
                } else {
                    reject();
                }
            })
        }

Solution

  • onHealthCheck implementation looks like this (express is used):

        if (onHealthCheck) {
          onHealthCheck(req)
            .then(() => {
              res.json({ status: 'pass' });
            })
            .catch(() => {
              res.status(503).json({ status: 'fail' });
            });
        }
    

    so as you can see, it returns hardcoded value.

    You can always implement your custom health check also using express.