Search code examples
node.jsgraphqlexpress-graphqlhasura

is there a way to reload hasura remote schema using nodejs


I'm setting up a remote schema inside the other hasura graphql schema how can I set up the reload_remote_schema using node/express js?

I'm facing below problem. Graphql remote schema data is not updating before clicking on the reload button. I don't want to reload remote schema manually, it should refresh automatically via node/express js code.


Solution

  • With any JS http client, you should be able to hit this endpoint:

    POST /v1/query HTTP/1.1
    Content-Type: application/json
    X-Hasura-Role: admin
    
    {
        "type": "reload_remote_schema",
        "args": {
            "name": "my remote schema"
        }
    }
    

    Documentation: https://docs.hasura.io/1.0/graphql/manual/api-reference/schema-metadata-api/remote-schemas.html#reload-remote-schema

    Any time you update your remote schema (e.g. on a new deploy), you can refresh via API.

    It's also possible to refresh your remote schemas via CLI: https://docs.hasura.io/1.0/graphql/manual/hasura-cli/hasura_metadata_reload.html#hasura-metadata-reload. But this operation is an exclusive/expensive request (with potential to cause deadlocks as of beta.3 at least).