const { ApolloClient, InMemoryCache, HttpLink } = require('@apollo/client');
const fetch = require('cross-fetch');
const headers = {
"Content-Type": "application/json",
"Hasura-Client-Name": "hasura-console",
"x-hasura-admin-secret": "myadminsecretkey",
};
const client = new ApolloClient({
link: new HttpLink({
uri: "http://localhost:8081/v1/graphql",
headers,
fetch
}),
cache: new InMemoryCache()
});
module.exports = client;
Using this to initialise my client is throwing me error:
leave-tracker-functions-1 | networkError: FetchError: request to http://localhost:8081/v1/graphql failed, reason: connect ECONNREFUSED 127.0.0.1:8081
leave-tracker-functions-1 | at ClientRequest.<anonymous> (/app/node_modules/cross-fetch/node_modules/node-fetch/lib/index.js:1491:11)
leave-tracker-functions-1 | at ClientRequest.emit (node:events:513:28)
leave-tracker-functions-1 | at Socket.socketErrorListener (node:_http_client:494:9)
leave-tracker-functions-1 | at Socket.emit (node:events:513:28)
leave-tracker-functions-1 | at emitErrorNT (node:internal/streams/destroy:157:8)
leave-tracker-functions-1 | at emitErrorCloseNT (node:internal/streams/destroy:122:3)
leave-tracker-functions-1 | at processTicksAndRejections (node:internal/process/task_queues:83:21) {
leave-tracker-functions-1 | type: 'system',
leave-tracker-functions-1 | errno: 'ECONNREFUSED',
leave-tracker-functions-1 | code: 'ECONNREFUSED'
leave-tracker-functions-1 | },
leave-tracker-functions-1 | extraInfo: undefined
leave-tracker-functions-1 | }
I tried using host.docker.internal, it didn’t work.
What worked for me is
uri: 'http://leave-tracker-graphql-engine-1:8080/v1/graphql',
I’m trying to understand why this works.
Config for my hasura docker container:
graphql-engine:
image: hasura/graphql-engine:v2.16.1
ports:
- "8081:8080"