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 工具基本试用的更多相关文章

  1. grandstack graphql 开发模型

    当前grandstack 支持两类开发方式 js (使用Neo4j-graphql-js) 插件模型 js 模型 参考https://github.com/rongfengliang/grand-st ...

  2. WEB压力测试工具Pylot试用

    Pylot介绍 转载自[http://www.freehao123.com/pylot-web/] 为了能够准确地评估网站服务器对网络流量的承受能力,我们一般会采取模拟网站用户访问,通过不断地增加并发 ...

  3. Web软件开发工具WebBuilder试用手记

    最近公司在使用WebBuilder做项目开发,感觉很不错. 官方主页在这里:http://www.putdb.com/ 可以看到,这货不仅能使用可视化的方式拖拽出界面,还能直接在页面上完成数据库相关的 ...

  4. graphql elasticsearch 集成试用

    graphql 是很方便的api 查询语言,elasticsearch 可以方便的进行全文检索的应用开发 有一个方便的npm 包graphql-compose-elasticsearch 可以进行es ...

  5. swagger api 转graphql npm 包试用

    graphql 比较方便的进行api 的查询,操作,swagger 是一个方便的open api 描述标准,当前我们有比较多的 restapi 但是转换为graphql 是有成本的,还好swagger ...

  6. gqlgen golang graphql server 基本试用

    gqlgen golang 的graphql server 具体代码参考https://github.com/rongfengliang/gqlgen-demo 特点 模型优先 类型安全 代码生成 安 ...

  7. hasura graphql 引擎基本试用

    hasura 使用一个基于pg数据库的graphql引擎,他的设计比postgrpahql 有好多方便的地方,同时使用也比较简单 安装 docker && docker-compose ...

  8. prisma graphql 工具基本使用

    项目使用docker-compose mysql 运行 安装 npm insatll -g prisma or yarn global add prisma 创建代码 项目结构 ├── README. ...

  9. graphql-modules 企业级别的graphql server 工具

    graphql-modules 是一个新开源的graphql 工具,是基于apollo server 2.0 的扩展库,该团队 认为开发应该是模块化的. 几张来自官方团队的架构图可以参考,方便比较 a ...

随机推荐

  1. Rspec: feature spec 功能测试 测试JavaScript.

    我们要把应用各组件放在一起做集成 测试,这样才能保证模型和控制器之间能够良好契合. 在 RSpec 中,这种测试称为功能测试(feature spec),有时也称为验收测试(acceptance te ...

  2. mate桌面xrdp无法登陆问题

    vi /usr/libexec/xrdp/startwm.sh 或者/etc/xrdp/startwm.sh: 找到相应的发行版本,增加mate-session如下所示: # el  if [ -r ...

  3. Idea改项目名

    1.点开.idea文件夹,找到 modules.xml,更改里面的项目名 2.根目录下对应的.iml文件 3.右击 pom.xml 文件,选择最下面的 “ Add as maven build fil ...

  4. python-day21--time模块

    一.三种表示方法 1.时间戳(timestamp): time.time( )       #得到的是float类型 2.格式化(Format String): time.strftime('%Y/% ...

  5. memcpy详解

    头文件:#include<string.h>函数原型:void *memcpy(void str,const void *s,size_t n); 功能 c和c++使用的内存拷贝函数.从源 ...

  6. js 刷新页面

    Javascript刷新页面的几种方法:1 history.go(0)2 window.location.reload() window.location.reload(true) 3 locatio ...

  7. Python_Cxfreeze打包exe

    Cxfreeze打包exe   1● 下载cxfreeze 1◆   python -m pip install cx_Freeze --upgrade     https://sourceforge ...

  8. 060——VUE中vue-router之路由嵌套在文章系统中的使用方法:

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. js组件的写法

    工作之中的不足,报了js培训班,因为工作加班原因缺了几天课(js组件开发),现在拾起来补补 <!doctype html> <html> <head> <me ...

  10. js常用用途

     页面元素查找 查找元素方法表达式                                                 返回值                            依据元 ...