I need to configure readiness and liveness probes ...
# orm-help
y
I need to configure readiness and liveness probes for my kubernetes cluster. Mainly because the yoga server only handles post request and hence the std way using get requests is not working, Therefore i was wondering if any of you have tried to use lightship (https://github.com/gajus/lightship#using-with-expressjs) with graphql-yoga? Looks very simple with express server but I do not know how to do it with yoga? I see that I can "eject" (https://github.com/prisma/graphql-yoga#how-to-eject-from-the-standard-express-setup) the express setup but I do not understand what that means to be honest πŸ™‚
h
Isnt server.express exposes the whole express api
I guess you should be able to create '/live' endpoint from it
yoga also return the server instance so that you can use that
so you can get the
const s = await server.start(....)
I guess
and do
s.close()
later
and for any
app.use
or equivalent calls you wanna make you can use
server.express.use()
y
thank you. I am a total js, node, web, ts newbie πŸ™‚ The other dude found another job πŸ™‚ server.express exposes the Application but i need something else i think? This is the example I am trying to replicate inthe yoga app
Copy code
import express from 'express';
import {
  createLightship
} from 'lightship';

const app = express();

app.get('/', (req, res) => {
  res.send('Hello, World!');
});

const server = app.listen(8080);

const lightship = createLightship();

lightship.registerShutdownHandler(() => {
  server.close();
});

// Lightship default state is "SERVER_IS_NOT_READY". Therefore, you must signal
// that the server is now ready to accept connections.
lightship.signalReady();
h
☺️
y
so app.listen in the example above returns a http.Server object.
h
Yes!
On a lower level express is basically a wrapper on top of http package
y
but in the yoga code the GraphQlServer class returns something else?
i.e. when
Copy code
const server = new GraphQLServer({
  typeDefs: './src/schema.graphql',
  resolvers,
  context: {
    db: prisma,
  },
} as any)

.........
server.start(options, ({ port, ...otherArgs }) => {
  console.log(
    `Server is running on <http://localhost:${port}${>
      process.env.GRAPHQL_SERVER_ENDPOINT
    }`,
  )
  console.log(`Playground is running on <http://localhost:${port}${playground}`>)
})
h
Graphql server is wrapper on top of express
So it returns the same thing
y
I have some other issues with my code at the moment but with help from a colleague I now do something in line with
Copy code
const yoga_server_promise: Promise<HttpServer | HttpsServer> = server.start(options, ({ port, ...otherArgs }) => {
  console.log(
    `Server is running on <http://localhost:${port}${>
      process.env.GRAPHQL_SERVER_ENDPOINT
    }`,
  )
  console.log(`Playground is running on <http://localhost:${port}${playground}`>)
})

//for k8s readiness and liveness probes
const lightship = createLightship()

lightship.registerShutdownHandler(async () => {
  const server = await yoga_server_promise
  server.close()
})

// Lightship default state is "SERVER_IS_NOT_READY". Therefore, you must signal
// that the server is now ready to accept connections.
lightship.signalReady()