hasura graphql server 集成gatsby
hasura graphql server 社区基于gatsby-source-graphql 开发了gatsby-postgres-graphql 插件,
可以快速的开发丰富的网站
基本使用
- 安装hasura graphql server
我使用的Heroku 已经部署好了
https://rongfengliang.herokuapp.com/
说明:后边可能会删了,测试的话,最好的自己搭建
- 添加表结构以及数据(hasura server)


gastby 集成测试
- package.json
{
"name": "gatsby-postgres-graphql",
"description": "Gatsby simple source hasura graphql cms",
"license": "MIT",
"scripts": {
"develop": "gatsby develop",
"build": "gatsby build",
"serve": "gatsby serve"
},
"dependencies": {
"apollo-link-http": "^1.5.5",
"gatsby": "^2.0.9",
"gatsby-link": "^2.0.2",
"gatsby-source-graphql": "^2.0.2",
"react": "^16.5.2",
"react-dom": "^16.5.2"
}
}
- 组件编写
components/AuthorList
import React from "react"
const AuthorList = ({ authors }) => (
<div>
{authors.map((a, i) => (
<div key={i}>
<h2>{a.name}</h2>
<p>{a.id}</p>
</div>
))}
</div>
)
export default AuthorList;
- 使用组件
page/index.js
import React from "react"
import AuthorList from "../components/AuthorList"
const Index = ({ data }) => (
<div>
<h1>My Authors </h1>
<AuthorList authors={data.hasura.author} />
</div>
)
export default Index;
export const query = graphql`
query AuthorQuery {
hasura {
author {
id
name
}
}
}
`
- gastby 配置
const fetch = require(`node-fetch`)
const { createHttpLink } = require(`apollo-link-http`)
module.exports = {
plugins: [
{
resolve: 'gatsby-source-graphql',
options: {
typeName: 'HASURA',
fieldName: 'hasura',
createLink: () =>
createHttpLink({
uri: `${ process.env.HASURA_GRAPHQL_URL }`,
headers: {},
fetch,
}),
refetchInterval: 10, // Refresh every 60 seconds for new data
},
},
]
};
运行&&测试
- 运行
HASURA_GRAPHQL_URL=https://rongfengliang.herokuapp.com/v1alpha1/graphql yarn develop
- 效果

说明
hasura graphql server 是越来越强大了,很方便。
参考资料
https://github.com/rongfengliang/gatsby-hasura-graphql
https://github.com/hasura/graphql-engine/tree/master/community/boilerplates/gatsby-postgres-graphql
hasura graphql server 集成gatsby的更多相关文章
- hasura graphql server 集成gitlab
默认官方是提供了gitlab 集成的demo的,但是因为gitlab 一些版本的问题, 跑起来总有问题,所以查找相关资料测试了一个可以运行的版本 项目使用docker-compose 运行 参考 ht ...
- hasura graphql server event trigger 试用
hasura graphql server 是一个很不错的graphql 引擎,当前版本已经支持event triiger 了 使用此功能我们可以方便的集成webhook功能,实现灵活,稳定,快捷的消 ...
- hasura graphql server (haskell)构建
安装 &&运行pg(docker) version: '3.6' services: postgres: image: postgres environment: - "PO ...
- hasura graphql subscriptions 使用
subscriptions graphql 的一项实时数据推送的功能,还是很方便的,自己在直接使用subscriptions-transport-ws npm 包 的时候运行一直有错误(主要是依赖 ...
- 通过torodb && hasura graphql 让mongodb 快速支持graphql api
torodb 可以方便的将mongo 数据实时同步到pg,hasura graphql 可以方便的将pg 数据暴露为graphql api,集成在一起真的很方便 环境准备 docker-compose ...
- hasura graphql auth-webhook api 说明
hasura graphql 生产的使用是推荐使用webhook 进行角色访问控制的,官方同时提供了一个nodejs 的简单demo 代码 git clone https://github.com/h ...
- gqlgen golang graphql server 基本试用
gqlgen golang 的graphql server 具体代码参考https://github.com/rongfengliang/gqlgen-demo 特点 模型优先 类型安全 代码生成 安 ...
- Hasura GraphQL schema 生成是如何工作的
不像大部分的graphql 引擎,使用标准的graphql 规范的处理模型,Hasura graphql 不存在resolver 的概念(实际上是有的,只是转换为了sql语法) 以下是Hasura g ...
- ILOG JRules 和 WebSphere Process Server 集成概述
ILOG JRules 和 WebSphere Process Server 集成概述 简介 业务流程管理(Business Process Management,BPM)和业务规则管理系统(Busi ...
随机推荐
- 卸载 PrestaShop 1.7
PrestaShop 的卸载非常简单: 在你的 Web 服务器上删除所有 PrestaShop 的文件和目录.你可以使用 FTP 客户端,你也可以使用 SSH 工具. 使用数据库工具删除数据库中所有以 ...
- PHP函数笔记
一.函数(Function) 1.什么是函数:封装的,可以重复使用的 完成特定功能的代码段. 2.分类 (1)系统函数 (2)自定义函数 3.自定义函数 ...
- array_unshift
<!DOCTYPE html> <html> <body> <?php $a=array(0=>"red",1=>" ...
- HDOJ1000
#include<iostream> using namespace std; int main() { int a,b; while(cin >> a >> b) ...
- 安装 Android Studio
安装 Android Studio 只需轻松点击几下.(您需要已下载 Android Studio.) 若使用 JDK 1.8,在 Mac 系统上运行 Android Studio 可能出现一些已知的 ...
- C#窗体控件简介ListBox(需整理)
ListBox 控件 ListBox 控件又称列表框,它显示一个项目列表供用户选择.在列表框中,用户 一次可以选择一项,也可以选择多项. 1.常用属性: (1) Items属性: 用于存放列表框中的列 ...
- 网络SSID是什么意思
ssid是网络的ID(名称).一般用在无线网络上.搜索无线网络名一般就是在搜索无线网络的ssid. SSID是Service Set Identifier的缩写,意思是:服务集标识.SSID技术可以将 ...
- OC MRC之计数器的基本操作(代码分析)
/* 1.方法的基本使用 1> retain :计数器+1,会返回对象本身 2> release :计数器-1,没有返回值 3> retainCount :获取当前的计数器 4> ...
- 对比springmvc与struts2
转载:http://blog.csdn.net/chenleixing/article/details/44570681 1.Struts2是类级别的拦截, 一个类对应一个request上下文,Spr ...
- Maven 入门篇(下)
第一篇文章大概的介绍了一下Apache Maven以及它的下载和安装,并且运行了一个简单的示例.那么在对maven有了一点接触后,接下去的一步是要了解maven的核心概念,这样才能在使用maven的时 ...