經過torodb && hasura graphql 讓mongodb 快速支持graphql api

torodb 能夠方便的將mongo 數據實時同步到pg,hasura graphql 能夠方便的將pg 數據暴露爲graphql
api,集成在一塊兒真的很方便html

環境準備

  • docker-compose 文件
version: '2'
services:
  graphql-engine:
    image: hasura/graphql-engine:v1.0.0-alpha27
    ports:
    - "8080:8080"
    command: >
      /bin/sh -c "
      graphql-engine --database-url postgres://postgres@postgres/torod serve --enable-console;
      "
  torodb-stampede:
    image: torodb/stampede
    links:
      - postgres
      - mongodb
    environment:
      - POSTGRES_PASSWORD
      - TORODB_SETUP=true
      - TORODB_SYNC_SOURCE=mongodb:27017
      - TORODB_BACKEND_HOST=postgres
      - TORODB_BACKEND_PORT=5432
      - TORODB_BACKEND_DATABASE
      - TORODB_BACKEND_USER
      - TORODB_BACKEND_PASSWORD
      - DEBUG
  postgres:
    image: postgres:9.6
    environment:
      - POSTGRES_PASSWORD
    ports:
      - "15432:5432"
  mongodb:
    image: mongo:3.2
    ports:
      - "28017:27017"
    entrypoint:
      - /bin/bash
      - "-c"
      - mongo --nodb --eval '
            var db; 
            while (!db) { 
                try { 
                  db = new Mongo("mongodb:27017").getDB("local"); 
                } catch(ex) {} 
                sleep(3000); 
            }; 
            rs.initiate({_id:"rs1",members:[{_id:0,host:"mongodb:27017"}]});
        ' 1>/dev/null 2>&1 & 
        mongod --replSet rs1
  • 啓動
docker-compose up -d

測試數據添加

可使用工具鏈接,直接導入數據都是能夠的git

graphql 集成

  • 添加支持

  • 查詢

說明

集成起來,簡直太方便了github

參考資料

https://github.com/rongfengliang/torodb-hasuar-graphql
https://www.torodb.com/
https://docs.hasura.io/1.0/graphql/manual/index.htmlmongodb

相關文章
相關標籤/搜索