admin管理员组文章数量:1122847
I'm facing issues while trying to build a Docker image for my project, which uses an older version of Apollo's rover and Node.js 14.20. Although the subgraphs build successfully, the supergraph fails during startup with connection errors.
Here is my supergraph-config.yaml:
users:
routing_url: http://localhost:4000/graphql
schema:
subgraph_url: http://localhost:4000/graphql
projects:
routing_url: http://localhost:4002/graphql
schema:
subgraph_url: http://localhost:4002/graphql
datasets:
routing_url: http://localhost:4001/graphql
schema:
subgraph_url: http://localhost:4001/graphql
And Dockerfile is
FROM node:14.21.3-bullseye
WORKDIR /app
ADD package.json .
RUN npm cache clean --force
RUN npm install
RUN npm i @apollo/rover
ADD . .
CMD ["npm", "run", "start:update-graph"]
The start:update-graph command in the package.json is defined as follows:
rover supergraph compose --config ./supergraph-config.yaml > supergraph.graphql && node -r esm index.js
Upon running, I receive the following errors indicating issues with connecting to the subgraph URLs:
2024-11-25 13:00:23 > rover supergraph compose --config ./supergraph-config.yaml > supergraph.graphql && node -r esm index.js
2024-11-25 13:00:23
2024-11-25 13:00:23 error[E038]: Encountered 3 build errors while trying to build a supergraph.
2024-11-25 13:00:23
2024-11-25 13:00:23 Caused by:
2024-11-25 13:00:23 E028: error sending request for url (http://localhost:4000/graphql) while resolving the schema for the 'datasets' subgraph
2024-11-25 13:00:23 Make sure the endpoint is accepting connections and is spelled correctly
2024-11-25 13:00:23 E028: error sending request for url (http://localhost:4002/graphql) while resolving the schema for the 'projects' subgraph
2024-11-25 13:00:23 Make sure the endpoint is accepting connections and is spelled correctly
2024-11-25 13:00:23 E028: error sending request for url (http://localhost:4001/graphql) while resolving the schema for the 'users' subgraph
2024-11-25 13:00:23 Make sure the endpoint is accepting connections and is spelled correctly
2024-11-25 13:00:23
The subgraphs are accessible on http://localhost:4000/graphql
, http://localhost:4001/graphql
, and http://localhost:4002/graphql
when accessed outside Docker, but the supergraph setup fails to recognize these endpoints within Docker.
Has anyone encountered similar issues or can offer insights into what might be causing these connection errors during the supergraph composition in Docker?
I'm facing issues while trying to build a Docker image for my project, which uses an older version of Apollo's rover and Node.js 14.20. Although the subgraphs build successfully, the supergraph fails during startup with connection errors.
Here is my supergraph-config.yaml:
users:
routing_url: http://localhost:4000/graphql
schema:
subgraph_url: http://localhost:4000/graphql
projects:
routing_url: http://localhost:4002/graphql
schema:
subgraph_url: http://localhost:4002/graphql
datasets:
routing_url: http://localhost:4001/graphql
schema:
subgraph_url: http://localhost:4001/graphql
And Dockerfile is
FROM node:14.21.3-bullseye
WORKDIR /app
ADD package.json .
RUN npm cache clean --force
RUN npm install
RUN npm i @apollo/rover
ADD . .
CMD ["npm", "run", "start:update-graph"]
The start:update-graph command in the package.json is defined as follows:
rover supergraph compose --config ./supergraph-config.yaml > supergraph.graphql && node -r esm index.js
Upon running, I receive the following errors indicating issues with connecting to the subgraph URLs:
2024-11-25 13:00:23 > rover supergraph compose --config ./supergraph-config.yaml > supergraph.graphql && node -r esm index.js
2024-11-25 13:00:23
2024-11-25 13:00:23 error[E038]: Encountered 3 build errors while trying to build a supergraph.
2024-11-25 13:00:23
2024-11-25 13:00:23 Caused by:
2024-11-25 13:00:23 E028: error sending request for url (http://localhost:4000/graphql) while resolving the schema for the 'datasets' subgraph
2024-11-25 13:00:23 Make sure the endpoint is accepting connections and is spelled correctly
2024-11-25 13:00:23 E028: error sending request for url (http://localhost:4002/graphql) while resolving the schema for the 'projects' subgraph
2024-11-25 13:00:23 Make sure the endpoint is accepting connections and is spelled correctly
2024-11-25 13:00:23 E028: error sending request for url (http://localhost:4001/graphql) while resolving the schema for the 'users' subgraph
2024-11-25 13:00:23 Make sure the endpoint is accepting connections and is spelled correctly
2024-11-25 13:00:23
The subgraphs are accessible on http://localhost:4000/graphql
, http://localhost:4001/graphql
, and http://localhost:4002/graphql
when accessed outside Docker, but the supergraph setup fails to recognize these endpoints within Docker.
Has anyone encountered similar issues or can offer insights into what might be causing these connection errors during the supergraph composition in Docker?
Share Improve this question asked Nov 25, 2024 at 9:14 DanisDanis 2,1103 gold badges17 silver badges27 bronze badges2 Answers
Reset to default 0Probably worth to point out what localhost is, when you connect to localhost you are actually connecting to yourself.
Probably your project Docker container is using default bridge docker network, so it is isolated network to container itself. So if your project container tries to connect to http://localhost:400x/graphql
that means it tries to find this service on container itself and based on what you put in your question, seems there are no such service running there.
How do you run http://localhost:400x/graphql services? Is it another container on same host? If it is another container, then best solution would be to have both containers in same docker network and then your project docker container should be able to connect to it using it name like http://containername:4000/graphql
, but not localhost!
Additional and simplest option would be just run your project container in host network and in this case it will use your host network interface and in this case most likely it will be able to connect to http://localhost:400x/graphql
. Keep in mind that is probably not an ideal solution, because it will expose all ports of your container and someone with limited understanding how docker works, probably should not use it.
The issue likely stems from Docker's networking. Replace localhost in your supergraph-config.yaml with host.docker.internal to allow the container to access services running on the host machine.
本文标签: Errors building supergraph with Dockernodejsand Apollo39s roverStack Overflow
版权声明:本文标题:Errors building supergraph with Docker, Node.js, and Apollo's rover - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736241178a1916921.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论