3

I am trying to run two applications by docker-compose without success, the federation cannot connect on service. Both works well out of docker.

Below follow the projects:

  • Apollo Server Federation in NodeJS

  • GraphQL API In Kotlin + Spring Boot + expediagroup:graphql-kotlin-spring-server

docker-compose.yml

version: '3'
services:
  myservice:
    image: 'myservice:0.0.1-SNAPSHOT'
    container_name: myservice_container
    ports:
      - 8080:8080
    expose:
      - 8080
  apollo_federation:
    image: 'apollo-federation'
    build: '.'
    container_name: apollo_federation_container
    restart: always
    ports:
      - 4000:4000
    expose:
      - 4000
    environment:
      ENDPOINT: "http://myservice/graphql"
    depends_on:
      - myservice

I already try a lot of combinations in my endpoint ex: http://myservice:8080/graphql, http://localhost:8080/graphql, http://myservice, etc...

index.js from Apollo Project

const { ApolloServer } = require("apollo-server");
const { ApolloGateway } = require("@apollo/gateway");

const gateway = new ApolloGateway({
  serviceList: [
    { name: "Service1", url: process.env.ENDPOINT || 'http://localhost:8080/graphql' },
  ]
});

const server = new ApolloServer({
  gateway,
  subscriptions: false
});

server.listen().then(({ url }) => {
  console.log(` Server ready at ${url}`);
})

Error Log

 Error checking for changes to service definitions: Couldn't load service definitions for "Service1" at http://myservice/graphql: request to http://myservice/graphql failed, reason: connect ECONNREFUSED 172.18.0.3:80

if I try to test from browse I get a error 500 by graphiql.

I am already tried to use a nginx as reverse-proxy, but no success

I am using the last libs in projects.

Thanks

1 Answers1

0

In your code, you are using

    { name: "Service1", url: process.env.ENDPOINT || 'http://localhost:8080/graphql' },

which is pulling process.env.ENDPOINT, which is defined in your docker-compose file as using port 80:

    environment:
      ENDPOINT: "http://myservice/graphql" # This is port 80
Dan Crews
  • 3,067
  • 17
  • 20