Prisma binding unable to connect to prisma server. request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466

prisma

#1

I am running two separate docker services. One for my graphql server and the other one is a prisma service connecting to a local postgres database. I am able to run prisma deploy and test it out directly in http://localhost:4466. But When I try to query using my app’s graphql server in http://localhost:8080, it gives the following response.

{
  "data": null,
  "errors": [
    {
      "message": "request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "feed"
      ]
    }
  ]
}

This is the stack trace.

graphql-server_1  | [Network error]: FetchError: request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466
graphql-server_1  | Error: request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466
graphql-server_1  |     at new CombinedError (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/errors.js:83:28)
graphql-server_1  |     at Object.checkResultAndHandleErrors (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/errors.js:101:15)
graphql-server_1  |     at CheckResultAndHandleErrors.transformResult (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/transforms/CheckResultAndHandleErrors.js:10:25)
graphql-server_1  |     at /usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/transforms/transforms.js:19:54
graphql-server_1  |     at Array.reduce (<anonymous>)
graphql-server_1  |     at applyResultTransforms (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/transforms/transforms.js:18:23)
graphql-server_1  |     at /usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:82:50
graphql-server_1  |     at step (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)
graphql-server_1  |     at Object.next (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)
graphql-server_1  |     at fulfilled (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:4:58)

This is how I initialize it.

const server = new GraphQLServer({
  typeDefs: './src/schema.graphql',
  resolvers,
  context: req => ({
    ...req,
    db: new Prisma({
      typeDefs: './src/generated/prisma.graphql',
      endpoint: 'http://localhost:4466',
      secret: 'my-secret',
      debug: true,
    })
  })
});

I am not sure as to what is the problem. The error message is also too vague.

Full Code can be found here: https://github.com/dhanushuUzumaki/Journal/tree/feature/setup


#2

Can you share the output of docker ps? It seems that there is nothing running on port 4466 :slightly_smiling_face:


#3

Hi @nilan, prisma is running on 4466 and I am able to access and query it directly. Still, Adding the output of docker ps for your reference. And if it helps, I am starting my app server only after prisma is started.

CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                    NAMES
deff54a11dd9        journal_graphql-server     "./wait-for-it.sh pr…"   13 seconds ago      Up 13 seconds       0.0.0.0:8080->8080/tcp   journal_graphql-server_1
4c43e22c466d        prismagraphql/prisma:1.8   "/bin/sh -c /app/sta…"   13 seconds ago      Up 14 seconds       0.0.0.0:4466->4466/tcp   journal_prisma_1

#4

Hi @DhanushuUzumaki, this is an interesting problem. :slight_smile: Let me give you some background: Using localhost within a container points to the container itself and not the host on which the containers are running. So in order to connect to the Prisma instance, you have to use the internal service name which resolves to the respective Prisma container.

So instead of:

...
    db: new Prisma({
      typeDefs: './src/generated/prisma.graphql',
      endpoint: 'http://localhost:4466',
      secret: 'my-secret',
      debug: true,
    })
...

you have to configure the endpoint as:

...
    db: new Prisma({
      typeDefs: './src/generated/prisma.graphql',
      endpoint: 'http://prisma:4466',
      secret: 'my-secret',
      debug: true,
    })
...

Network error when running graphql get-schema
Development Workflow Integration
#5

@andre Thanks a lot… I updated docker-compose.yml while pointing to db in host machine for this reason to use host.docker.internal but didn’t think the same would bog me down here also… :pray::pray::pray: Thanks a lot.


Getting ECONNREFUSED error
#6

@andre I am facing the same issue. I am using typescript-client and the endpoints are auto generated. Not sure how can I modify these endpoint so that it is reachable from outside the docker container. Any help would be appreciated. Thanks!


#7

Hi, I am facing a similar issue. After I launch my docker-compose up command, everything starts up. Here is my docker-compose.yml file:

version: '3'
services:
  prisma:
    env_file:
      - .env
    image: prismagraphql/prisma:1.34
    restart: always
    ports:
     - "4466:4466"
    environment:
       PRISMA_CONFIG: |
            port: 4466
            databases:
                 default:
                     connector: mongo
                     uri: ${MONGODB_URI}
                     host: host.docker.internal
       JWT_SECRET: ${JWT_SECRET}
   mongo:
    env_file:
      - .env
    image: mongo:3.6
    restart: always
    environment:
         MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USERNAME}
         MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PASSWORD}
    ports:
       - "27017:27017"
    volumes:
       - mongo:/var/lib/mongo
   web:
    env_file:
      - .env
    build: .
    volumes:
      - .:/usr/app/
      - /usr/app/node_modules
    ports:
      - "4000:4000"
    environment:
      DATABASE_URL: ${MONGODB_URI}

volumes:
  mongo:

My Dockerfile:

FROM node:8.16.0-alpine
WORKDIR /usr/app
COPY package.json .
RUN npm install --quiet
COPY . .

ENV DOCKERIZE_VERSION v0.6.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize- 
alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz

CMD dockerize -wait tcp://mongo:27017 -wait tcp://prisma:4466 -timeout 60m npm start

My prisma.yml:

endpoint: http://localhost:4466
datamodel: 
   - db/types.prisma
   - db/enums.prisma
databaseType: document

generate:
  - generator: javascript-client
    output: ./generated/prisma-client/

My prisma deploy command works, and it generates the mongo database, but when I try to query my application at localhost:4000, it looks like this and returns this error:

request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466

But when I navigate to localhost:4466/_admin, the database is all set up fine and shows the three tables that should be there.

I checked if anything is running localhost:4466 by issuing this command: lsof -i :4466, and I can see that docker started up correctly.

COMMAND    PID        USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
com.docke 5923 sguduguntla   24u  IPv4 0x89ea943c9b98ff09      0t0  TCP *:4466 (LISTEN)
com.docke 5923 sguduguntla   25u  IPv6 0x89ea943c87111549      0t0  TCP localhost:4466 (LISTEN)

When I run docker ps, you can also see the following output with the three images:

CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS              PORTS                      
NAMES
fa70fae37f10        prismagraphql/prisma:1.34        "/bin/sh -c /app/sta…"   35 minutes ago      Up 31 
minutes       0.0.0.0:4466->4466/tcp     decal-board-graphql-server_prisma_1
d64b9f6dcd29        decal-board-graphql-server_web   "docker-entrypoint.s…"   35 minutes ago      Up 31 
minutes       0.0.0.0:4000->4000/tcp     decal-board-graphql-server_web_1
6f7dda5e58a0        mongo:3.6                        "docker-entrypoint.s…"   35 minutes ago      Up 31 minutes       
0.0.0.0:27017->27017/tcp   decal-board-graphql-server_mongo_1

I have been trying to find a solution to this for days, and there is nothing helpful online, and the few similar questions have been closed or ignored. I would appreciate getting help with this issue.