hasura graphql-engine v1.0.0-alpha30 remote schema stitch 试用

时间:2023-03-09 05:08:50
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;
"

试用模式拼接功能

  • 添加配置
    hasura graphql-engine v1.0.0-alpha30 remote schema stitch 试用
  • schema 信息
    hasura graphql-engine v1.0.0-alpha30 remote schema stitch 试用
  • 测试
    hasura graphql-engine v1.0.0-alpha30 remote schema stitch 试用
    但是,进行混合的时候就有问题了,新版发布的说明里面也有提示,后期应该可以解决
    hasura graphql-engine v1.0.0-alpha30 remote schema stitch 试用
  • 查看表结构
    hasura graphql-engine v1.0.0-alpha30 remote schema stitch 试用
    hasura graphql-engine v1.0.0-alpha30 remote schema stitch 试用

说明

这个功能还是很不错的,只是期待可以解决好多已知的问题

参考资料

https://github.com/hasura/graphql-engine
https://github.com/rongfengliang/hasura-graphql-event-benthos