ardatan / graphql-mesh

πŸ•ΈοΈ GraphQL Federation Framework for any API services such as REST, OpenAPI, Swagger, SOAP, gRPC and more...
https://the-guild.dev/graphql/mesh
MIT License
3.27k stars 339 forks source link

Service Polling / Live Schema Updates - Possible? #1142

Open ajzozakiewicz opened 3 years ago

ajzozakiewicz commented 3 years ago

It is possible to have the mesh gateway poll running services for schema changes? Or trigger it to reload its sources somehow?

Current code snippet I am experimenting with:

const { ApolloServer } = require('apollo-server')
const { findAndParseConfig } = require('@graphql-mesh/config')
const { getMesh } = require('@graphql-mesh/runtime')

async function main() {
  const meshConfig = await findAndParseConfig();
  const { schema, contextBuilder } = await getMesh(meshConfig);

  const context = await contextBuilder({
    testProp: 'test'
  })

  const apolloServer = new ApolloServer({
    schema,
    context
  });

  const { url } = await apolloServer.listen(4000);
  console.info(`πŸš€ Server ready at ${url}`);
}

main().catch(err => console.error(err));
hulucc commented 3 years ago

I need this too.

kraegpoeth commented 3 years ago

I need this too. Only way to do is to restart the mesh serve process and that will not be so nice once its deployed to production :/

jgoux commented 3 years ago

Right now I'm using mesh in front of Hasura, I have them both running in local for development.

What I do is :

The scripts look like this :

"graphql-codegen:get-schema": "concurrently yarn:graphql-codegen:get-schema-*",
"graphql-codegen:on-hasura-change": "chokidar \"packages/server/hasura/**/*\" --command \"yarn workspace @clovis/server run proxy:reload && yarn graphql-codegen:get-schema\" --silent",
"proxy:dev": "nodemon --watch .meshrc.yml --watch src/app/proxy --exec yarn proxy:start",
"proxy:start": "wait-port http://localhost:8080/healthz && mesh dev --dir src/app/proxy --require dotenv/config",
"proxy:reload": "cat .meshrc.yml | tee .meshrc.yml > /dev/null",

To simplify everything it would be awesome if mesh dev could poll for remote schema changes and automatically generate the schema.graphql. πŸ‘

alanwillms commented 1 year ago

I know this is not ideal, but here is another approach using Docker and Kubernetes. In my Dockerfile, I wrote:

FROM node:16.13-alpine
# ...
RUN npm i -g pm2
# ...
ENTRYPOINT ["/bin/sh", "/app/update-schemas.sh"]
CMD pm2-runtime '/app/node_modules/.bin/mesh start' --no-autorestart --wait-ready --name mesh --listen-timeout 15000

Then in my update-schemas.sh:

nohup sh -c "sleep 60 && yarn mesh build && pm2 reload all"
export $NEXT_RESTART_MINUTE=`date +"%M"`
echo "$NEXT_RESTART_MINUTE * * * * cd /app && yarn mesh build && pm2 reload all" >> /etc/crontab/root
crond -l 2 -f > /dev/stdout 2> /dev/stderr &
exec "$@"

What's happening here:

A few gotchas: