hasura graphql-engine v1.0.0-alpha30 remote schema stitch 试用
新的hasura graphql-engine 代码仓库中已经包含了一个基于express 的简单graphql server,
可以用来测试模式拼接
graphql server 代码
- 项目结构
├── Dockerfile
├── README.md
├── now.json
├── package.json
└── server.js
- 代码说明
package.json: 依赖包
{
"name": "nodejs-express-gql-server",
"version": "1.0.0",
"description": "A GraphQL server boilerplate for NodeJS-Express using graphql-js library",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node -r esm server.js"
},
"author": "Hasura",
"license": "MIT",
"dependencies": {
"express": "^4.16.4",
"express-graphql": "^0.7.1",
"graphql": "^14.0.2"
},
"devDependencies": {
"esm": "^3.0.84"
}
}
server.js: 具体代码
const express = require('express');
const graphqlHTTP = require('express-graphql');
const { buildSchema } = require('graphql');
let count = 0;
const port = process.env.port || 3000;
// Construct a schema, using GraphQL schema language
const schema = buildSchema(`
type Query {
hello: String!
count: Int!
}
type Mutation {
increment_counter: count_mutation_response!
}
type count_mutation_response {
new_count: Int!
}
`);
// The root provides a resolver function for each API endpoint
const root = {
hello: () => {
return 'Hello world!';
},
count: () => {
return count;
},
increment_counter: () => {
return { new_count: ++count }
}
};
var app = express();
app.use('/graphql', graphqlHTTP({
schema: schema,
rootValue: root,
graphiql: true,
}));
app.listen(port);
console.log(`Running a GraphQL API server at localhost:${port}/graphql`);
Dockerfile: 代码的dockeer 运行
FROM node:8
WORKDIR /server
COPY ./package.json /server/
RUN npm install
COPY . /server/
CMD ["npm", "start"]
hasura graphql-engine 环境准备
graphql server 的我已经推送到dockerhub 了 镜像为:dalongrong/stitchmerge
- docker-compose 文件
version: '3.6'
services:
postgres2:
image: postgres:9.6
ports:
- "5432:5432"
environment:
- "POSTGRES_PASSWORD:dalong"
volumes:
- ./db_data2:/var/lib/postgresql/data
postgres:
image: postgres:9.6
ports:
- "5435:5432"
environment:
- "POSTGRES_PASSWORD:dalong"
volumes:
- ./db_data:/var/lib/postgresql/data
benthos:
image: jeffail/benthos
volumes:
- "./configs/webhook.yaml:/benthos.yaml"
ports:
- "4195:4195"
node-exress:
image: dalongrong/stitchmerge
ports:
- "3000:3000"
graphql-engine2:
image: hasura/graphql-engine:v1.0.0-alpha30
ports:
- "8080:8080"
depends_on:
- "postgres"
environment:
- "POSTGRES_PASSWORD:dalong"
command: >
/bin/sh -c "
graphql-engine --database-url postgres://postgres:dalong@postgres2:5432/postgres serve --enable-console;
"
graphql-engine:
image: hasura/graphql-engine:v1.0.0-alpha29
ports:
- "8090:8080"
depends_on:
- "postgres"
environment:
- "POSTGRES_PASSWORD:dalong"
command: >
/bin/sh -c "
graphql-engine --database-url postgres://postgres:dalong@postgres:5432/postgres serve --enable-console;
"
- 运行效果
graphql server:
http://localhost:3000/graphql
引擎界面
试用模式拼接功能
- 添加配置
- schema 信息
- 测试
但是,进行混合的时候就有问题了,新版发布的说明里面也有提示,后期应该可以解决
- 查看表结构
说明
这个功能还是很不错的,只是期待可以解决好多已知的问题
参考资料
https://github.com/hasura/graphql-engine
https://github.com/rongfengliang/hasura-graphql-event-benthos
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2017-11-27 cargo rust 包管理工具
2017-11-27 container-diff 谷歌开源镜像分析工具使用
2016-11-27 Disque
2015-11-27 node js 常用模块