Giter Site home page Giter Site logo

Comments (11)

jordanmkoncz avatar jordanmkoncz commented on April 28, 2024 1

For anyone else who has the same question as @mnlbox, I found a fairly easy way to achieve this.

  1. Clone the https://github.com/hasura/3factor-example repository
  2. Add docker-compose.yaml to the repository root (see code below)
  3. Run docker-compose up -d
  4. Run docker exec -i 3factor_postgres psql -U postgres postgres < schema.sql

docker-compose.yaml:

version: '3.7'
services:
  postgres:
    image: "postgres:11.5"
    container_name: "3factor_postgres"
    ports:
    - "5432:5432"
    restart: always
    volumes:
    - db_data:/var/lib/postgresql/data
  graphql-engine:
    image: hasura/graphql-engine:v1.0.0-beta.4
    container_name: "3factor_hasura"
    ports:
    - "8080:8080"
    depends_on:
    - "postgres"
    restart: always
    environment:
      HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:@postgres:5432/postgres
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
      HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
      ## uncomment next line to set an admin secret
      # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
volumes:
  db_data:

With Hasura and Postgres running via this docker-compose.yaml configuration, when you want to run the Express server as part of https://github.com/jordanmkoncz/3factor-example#step-3-local-development (node localDevelopment.js), in your terminal you should first run:

export POSTGRES_CONNECTION_STRING='postgres://postgres:@localhost:5432/postgres'

Side note: if you decide to run the 3factor-example project like this, you will probably run into an issue where the event triggers fail. In the event response, I was seeing an error of ConnectionFailure Network.Socket.connect: <socket: 27>: does not exist (Connection refused). This happens because the webhooks are pointing to localhost, e.g. http://localhost:8081/validate-order, and Hasura which is running from the Docker container is not able to connect to the Express server (node localDevelopment.js) running directly on localhost (not in Docker).

The solution is to modify the event triggers so that Hasura within the Docker container can connect to the Express server on localhost, which is discussed in https://docs.hasura.io/1.0/graphql/manual/deployment/docker/index.html#network-config. On macOS, the event trigger would be updated by replacing localhost with host.docker.internal, and on Windows replacing it with docker.for.win.localhost, e.g. the new event trigger would point to http://host.docker.internal:8081/validate-order. You'll need to make this change for all event triggers.

from 3factor-example.

tirumaraiselvan avatar tirumaraiselvan commented on April 28, 2024

Hey @mnlbox

Do you have access to your Postgres db?

from 3factor-example.

mnlbox avatar mnlbox commented on April 28, 2024

@tirumaraiselvan I run my Hasura instance with this guide:
https://docs.hasura.io/1.0/graphql/manual/getting-started/docker-simple.html

How we can access to this Postgres? 🤔

from 3factor-example.

tirumaraiselvan avatar tirumaraiselvan commented on April 28, 2024

@mnlbox Ah! Seems like the Postgres container is not exposed to localhost in docker-compose manifest. We will fix it.

In the meanwhile, you can go to Hasura console -> Data tab -> Run SQL and copy paste the contents of schema.sql there. And execute.

from 3factor-example.

mnlbox avatar mnlbox commented on April 28, 2024

@tirumaraiselvan Thanks man.
Maybe related: hasura/graphql-engine#1424

from 3factor-example.

tirumaraiselvan avatar tirumaraiselvan commented on April 28, 2024

from 3factor-example.

mnlbox avatar mnlbox commented on April 28, 2024

Thanks @tirumaraiselvan I think expose Postgres and pgAdmin to local can be useful for this purpose 😉
Your temp solution (run SQL in Hasura console working well).

from 3factor-example.

tirumaraiselvan avatar tirumaraiselvan commented on April 28, 2024

Resolved

from 3factor-example.

mnlbox avatar mnlbox commented on April 28, 2024

@tirumaraiselvan Can you guide a little?

from 3factor-example.

tirumaraiselvan avatar tirumaraiselvan commented on April 28, 2024

@mnlbox You can use pgadmin like here: https://github.com/hasura/graphql-engine/blob/master/install-manifests/docker-compose-pgadmin/docker-compose.yaml

Or you can use network: host in your docker-compose.yaml and connect to psql directly on port 5432

from 3factor-example.

jordanmkoncz avatar jordanmkoncz commented on April 28, 2024

I've made a fork that includes all of the above changes (and some other fixes for this project) and submitted a pull request at #17. Feel free to use this fork if you'd prefer to use a docker-compose.yaml configuration and to run both Hasura and Postgres via Docker.

from 3factor-example.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.