grandstack graphql 工具基本试用
grandstack 是一个方便graphql 应用开发的工具
使用docker-compose 运行
环境准备
官方的starter 比较好,已经是使用docker-compose 创建好了所有的依赖,但是目前使用的版本镜像有bug,我修改了版本,可以运行
参考github 项目 https://github.com/rongfengliang/grand-stack-starter
- clone starter
git clone https://github.com/grand-stack/grand-stack-starter.git
- docker-compose 文件
version: '3'
services:
neo4j:
build: ./neo4j
ports:
- 7474:7474
- 7687:7687
environment:
- NEO4J_dbms_security_procedures_unrestricted=apoc.*
- NEO4J_apoc_import_file_enabled=true
- NEO4J_apoc_export_file_enabled=true
- NEO4J_dbms_shell_enabled=true
api:
build: ./api
ports:
- 4000:4000
links:
- neo4j
depends_on:
- neo4j
ui:
build: ./ui
ports:
- 3000:3000
links:
- api
depends_on:
- api
starter 说明
因为grandstack 数据存储服务、查询服务使用的核心是neo4j 所以需要启动ne4j
- neo4j server
docker 配置比较简单,主要是插件添加以及一些简单的参数配置
Dockerfile
FROM neo4j:3.4.5
ENV NEO4J_AUTH=neo4j/letmein
ENV APOC_VERSION 3.4.0.2
ENV APOC_URI https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/${APOC_VERSION}/apoc-${APOC_VERSION}-all.jar
RUN wget -P /var/lib/neo4j/plugins ${APOC_URI}
ENV GRAPHQL_VERSION 3.4.0.1
ENV GRAPHQL_URI https://github.com/neo4j-graphql/neo4j-graphql/releases/download/${GRAPHQL_VERSION}/neo4j-graphql-${GRAPHQL_VERSION}.jar
RUN wget -P /var/lib/neo4j/plugins ${GRAPHQL_URI}
EXPOSE 7474 7473 7687
CMD ["neo4j"]
启动配置
neo4j:
build: ./neo4j
ports:
- 7474:7474
- 7687:7687
environment:
- NEO4J_dbms_security_procedures_unrestricted=apoc.*
- NEO4J_apoc_import_file_enabled=true
- NEO4J_apoc_export_file_enabled=true
- NEO4J_dbms_shell_enabled=true
- api server 配置
定义graphql api 的schema 以及使用ne4j 进行graphql 查询的转换
简单schenma,集成了neo4j 指令
type User {
id: ID!
name: String
friends: [User] @relation(name: "FRIENDS", direction: "BOTH")
reviews: [Review] @relation(name: "WROTE", direction: "OUT")
avgStars: Float @cypher(statement: "MATCH (this)-[:WROTE]->(r:Review) RETURN toFloat(avg(r.stars))")
numReviews: Int @cypher(statement: "MATCH (this)-[:WROTE]->(r:Review) RETURN COUNT(r)")
}
查询指令解析配置,很传统,比较简单
import { neo4jgraphql } from "neo4j-graphql-js";
import fs from 'fs';
import path from 'path';
export const typeDefs =
fs.readFileSync(process.env.GRAPHQL_SCHEMA || path.join(__dirname, "schema.graphql"))
.toString('utf-8');
export const resolvers = {
Query: {
usersBySubstring: neo4jgraphql // resovler for neo4j
}
};
graphql server 启动
import { typeDefs, resolvers } from "./graphql-schema";
import { ApolloServer, gql, makeExecutableSchema } from "apollo-server";
import { v1 as neo4j } from "neo4j-driver";
import { augmentSchema } from "neo4j-graphql-js";
import dotenv from "dotenv";
dotenv.config();
const schema = makeExecutableSchema({
typeDefs,
resolvers
});
// augmentSchema will add autogenerated mutations based on types in schema
const augmentedSchema = augmentSchema(schema);
const driver = neo4j.driver(
process.env.NEO4J_URI || "bolt://localhost:7687",
neo4j.auth.basic(
process.env.NEO4J_USER || "neo4j",
process.env.NEO4J_PASSWORD || "neo4j"
)
);
const server = new ApolloServer({
// using augmentedSchema (executable GraphQLSchemaObject) instead of typeDefs and resolvers
//typeDefs,
//resolvers,
context: { driver },
// remove schema and uncomment typeDefs and resolvers above to use original (unaugmented) schema
schema: augmentedSchema
});
server.listen(process.env.GRAPHQL_LISTEN_PORT, '0.0.0.0').then(({ url }) => {
console.log(`GraphQL API ready at ${url}`);
});
- UI
基于react 的,也比较简单,就是集成graphql api
项目使用的react 脚手架生成的,主要是apollo-boost react-apollo的集成使用,同时项目使用了pwa
技术,还是挺好的参考
UI/src/UserList.js 比较重要,包含了数据查询的使用,主要是apollo client 的使用
运行&&测试
- 启动服务
docker-compose build
docker-compose up -d
- 访问测试
graphql api 地址
http://hostip:4000
添加数据

- neo4j 数据

- ui

说明
总的来说集成neo4j 是很不错,因为graphql 做的就是graph 查询,neo4j 就是干这个的,但是从实际来说neo4j 并不是免费的(单机是,集群不是)
同时类似的一些图数据库已经直接集成了graphql 了比如dgraph 、startdog
参考资料
https://grandstack.io/docs/getting-started-grand-stack-starter.html
https://github.com/grand-stack/grand-stack-starter.git
https://github.com/rongfengliang/grand-stack-starter
grandstack graphql 工具基本试用的更多相关文章
- grandstack graphql 开发模型
当前grandstack 支持两类开发方式 js (使用Neo4j-graphql-js) 插件模型 js 模型 参考https://github.com/rongfengliang/grand-st ...
- WEB压力测试工具Pylot试用
Pylot介绍 转载自[http://www.freehao123.com/pylot-web/] 为了能够准确地评估网站服务器对网络流量的承受能力,我们一般会采取模拟网站用户访问,通过不断地增加并发 ...
- Web软件开发工具WebBuilder试用手记
最近公司在使用WebBuilder做项目开发,感觉很不错. 官方主页在这里:http://www.putdb.com/ 可以看到,这货不仅能使用可视化的方式拖拽出界面,还能直接在页面上完成数据库相关的 ...
- graphql elasticsearch 集成试用
graphql 是很方便的api 查询语言,elasticsearch 可以方便的进行全文检索的应用开发 有一个方便的npm 包graphql-compose-elasticsearch 可以进行es ...
- swagger api 转graphql npm 包试用
graphql 比较方便的进行api 的查询,操作,swagger 是一个方便的open api 描述标准,当前我们有比较多的 restapi 但是转换为graphql 是有成本的,还好swagger ...
- gqlgen golang graphql server 基本试用
gqlgen golang 的graphql server 具体代码参考https://github.com/rongfengliang/gqlgen-demo 特点 模型优先 类型安全 代码生成 安 ...
- hasura graphql 引擎基本试用
hasura 使用一个基于pg数据库的graphql引擎,他的设计比postgrpahql 有好多方便的地方,同时使用也比较简单 安装 docker && docker-compose ...
- prisma graphql 工具基本使用
项目使用docker-compose mysql 运行 安装 npm insatll -g prisma or yarn global add prisma 创建代码 项目结构 ├── README. ...
- graphql-modules 企业级别的graphql server 工具
graphql-modules 是一个新开源的graphql 工具,是基于apollo server 2.0 的扩展库,该团队 认为开发应该是模块化的. 几张来自官方团队的架构图可以参考,方便比较 a ...
随机推荐
- 3.2 x86体系结构
计算机组成 3 指令系统体系结构 3.2 x86体系结构 X86是商业上最为成功,影响力最大的一种体系结构.但从技术的角度看,它又存在着很多的问题,那我们就来一起分析X86这种体系结构的特点. 要探讨 ...
- 第7章使用请求测试-测试API . Rspec: everyday-rspec实操。
测试应用与非人类用户的交互,涵盖外部 API 7.1request test vs feature test 对 RSpec 来说,这种专门针 对 API 的测试最好放在 spec/requests ...
- Android之封装好的异步网络请求框架
1.简介 Android中网络请求一般使用Apache HTTP Client或者采用HttpURLConnection,但是直接使用这两个类库需要写大量的代码才能完成网络post和get请求,而使 ...
- CF1082G Petya and Graph
题意 定义图权 = 图中边权总和 - 图中点权总和(空图的图权=0),求 n 个点 m 条边的无向图最大权子图. 把边看成点,这个点与两个原图中的点连边.直接最小割求最大闭合子图即可.
- 『Scrapy』爬取斗鱼主播头像
分析目标 爬取的是斗鱼主播头像,示范使用的URL似乎是个移动接口(下文有提到),理由是网页主页属于动态页面,爬取难度陡升,当然爬取斗鱼主播头像这么恶趣味的事也不是我的兴趣...... 目标URL如下, ...
- MQTT协议QoS服务质量 (Quality of Service 0, 1 & 2)概念学习
什么是 QoS ? QoS (Quality of Service) 是发送者和接收者之间,对于消息传递的可靠程度的协商. QoS 的设计是 MQTT 协议里的重点.作为专为物联网场景设计的协议,MQ ...
- Hibernate---hbm2ddl和数据库方言的配置
Hibernate---hbm2ddl和数据库方言的配置 hibernate配置文件--hbm2ddl.auto属性值的区别: update: 最常用的取值,如果但其数据库中不存在表结构,那么自动创建 ...
- python daal test
import os import sys from daal.algorithms import low_order_moments from daal.data_management import ...
- JavaScript学习总结(十二)——JavaScript编写类
在工作中经常用到JavaScript,今天总结一下JavaScript编写类的几种写法以及这几种写法的优缺点,关于JavaScript编写类的方式,在网上看到很多,而且每个人的写法都不太一样,经常看到 ...
- hdu2665
题解: 裸的主席树,记录最小值 代码: #include<cstdio> #include<cmath> #include<algorithm> #include& ...