0

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 created the binding

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.

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

halfer
  • 19,824
  • 17
  • 99
  • 186
Dhanushu Uzumaki
  • 183
  • 1
  • 14

2 Answers2

7

Got Help from prisma forum to solve this.

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.

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

Prisma Forum - ECONNREFUSED - Unable to connect to prisma service through binding

Dhanushu Uzumaki
  • 183
  • 1
  • 14
1

This happened to me when using Docker Toolbox on windows, the endpoint had to be changed from using localhost to the VirtualBox default ip within prisma.yml:

endpoint: http://192.168.99.100:4466
Yaacov
  • 185
  • 4
  • 'ERR_INVALID_URL': Invalid URL: 192.168.99.100:4466 – abdelhedi hlel Jan 07 '19 at 10:58
  • 1
    THANK YOU! This worked for me. Installing Prisma server to create a React + Prisma/GrapQL app following this tutorial: https://www.prisma.io/tutorials/build-react-graphql-app-with-fetch-ct19 on Windows 8.1 with Docker. How do you know the VirtualBox IP? My VirtualBox network addresses are 192.168.56.1 and 192.168.99.1, but **192.168.99.100** was the address that worked to deploy prisma. – Rafael Fontoura Mar 26 '19 at 00:36