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

原文地址:https://www.cnblogs.com/rongfengliang/p/9728086.html

时间: 2024-08-03 03:47:05

hasura graphql server 集成gatsby的相关文章

hasura graphql server 集成gitlab

默认官方是提供了gitlab 集成的demo的,但是因为gitlab 一些版本的问题, 跑起来总有问题,所以查找相关资料测试了一个可以运行的版本 项目使用docker-compose 运行 参考 https://github.com/Trantect/docker-compose.yamls 环境准备 docker-compose 文件 version: '2' services: redis: image: sameersbn/redis:4.0.9-1 command: - --loglev

Team Foundation Server (TFS)与Project Server集成,使用DNS(友好地址)地址注册PWA

问题描述: 当Team Foundation Server(TFS 2010/2012/2013)与Project Server高可用性的环境集成时,必然会使用Project Server (PWA)的DNS地址注册PWA站点(RegisterPWA),而不是使用Project Server的计算机名注册,这样就会出现如下图所示的问题: 下图是执行注册PWA命令时出错的截屏 注册命令:tfsadmin project server /RegisterPWA /tfs:http://tfs2013

hasura graphql 角色访问控制

目前从官方文档以及测试可以看出不加任何header的请求访问的是所有的数据,对于具有访问 控制的请求需要添加请求头,实际生产的使用需要集合web hook 的实现访问控制. 参考配置 访问请求 目前数据只有id=1 不匹配的 匹配的 没有添加角色的(获取所有数据) 几张官方的参考图 配置 开发环境测试 生产使用 参考资料 https://docs.hasura.io/1.0/graphql/manual/auth/index.html 原文地址:https://www.cnblogs.com/r

eureka server 集成security,eureka client报错com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

当前Spring Coud 版本(Greenwich.SR2)  Spring Boot版本 (2.1.6.RELEASE) 在eureka server 中集成security后,发现eureka client 去注册的时候报以下错误: ----------------------------------------------------------------------------------------------------------------------------------

一篇来自hasura graphql-engine 百万级别live query 的实践

转自:https://github.com/hasura/graphql-engine/blob/master/architecture/live-queries.md Scaling to 1 million active GraphQL subscriptions (live queries) Hasura is a GraphQL engine on Postgres that provides instant GraphQL APIs with authorization. Read m

GraphQL入门指南

Introduction GraphQL is Facebook's new query language for fetching application data in a uniform way. GraphQL并不是一个面向图数据库的查询语言,而是一个数据抽象层,包括数据格式.数据关联.查询方式定义与实现等等一揽子的东西.GraphQL也并不是一个具体的后端编程框架,如果将REST看做适合于简单逻辑的查询标准,那么GraphQL可以做一个独立的抽象层,通过对于多个REST风格的简单的接口

34. PowerShell -- SQL Server的使用(2)

参考: http://www.shangxueba.com/jingyan/105946.html 一.先不用SqlServerCmdletSnapin100这个SnapIn来写几个操作常用数据的脚本 1. 由于有读者问如何用PowerShell显示数据库中表,以下是一个简单函数供参考 #==============================================# SQL Server 2008 - PowerShell# 显示用户表#zivsoft#=============

持续集成方案

大纲 构建 版本控制 部署 单元测试 架构文档化 命名约定 数据库伸缩性 自动化 反馈 实践 引言: 持续集成的前身: 在使用持续集成之前,很多开发团队都是用每日构建(nightly build).当时,微软使用这个实践很多年了.谁破坏了构建,就要负责监视后续的构建构成,直至发现下一个破坏了构建的人. 为什么要使用持续集成? 对于大多数项目来说,采纳持续集成实践是向高效率和高质量迈进的一大步.它保证那些创建大型复杂系统的团队具有高度的自信心和控制力.一旦代码提交引入了问题,持续集成就能为我们提供

Lync Server 2013 and FreePBX Integration

亲爱的小伙伴们大家好, 很多Lync server的学习者在学习企业语音这块时,都是想在测试环境下实现下.但是用户什么来模拟PBX和PSTN呢?大家通常可能会想到Freepbx. FREEPBX是一个基于Linux最强大的 GUI(基于网页的)配置Asterisk的工具.它提供标准传统电话系统能做的任何事,加入大量的新功能.我们就是为大家讲一下FreePBX与Lync Server集成的配置和调试. 首先我们从官网上下载最新的FREEPBX ISO文件.下载地址为:http://schmooze