ITPub博客

首页 > 数据库 > > 通过torodb && hasura graphql 让mongodb快速支持graphql api

通过torodb && hasura graphql 让mongodb快速支持graphql api

作者:u_9ff4c058a0e0 时间:2022-04-12 16:30:43 0 删除 编辑

orodb 可以方便的将mongo 数据实时同步到pg,hasura graphql 可以方便的将pg 数据暴露为graphql 
api,集成在一起真的很方便

环境准备

  • 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

测试数据添加

可以使用工具连接,直接导入数据都是可以的

graphql 集成

  • 添加支持 
     
  • 查询 

说明

集成起来,简直太方便了

参考资料

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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69999831/viewspace-3138290/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2022-02-11

  • 博文量
    1828
  • 访问量
    20587