[GraphQL] Deploy a GraphQL dev playground with graphql-up
In this lesson we'll use a simple GraphQL IDL schema to deploy and explore a fully functional GraphQL service in minutes with graphql-up.
Install:
npm i -g graphql-up -g
Create schema:
type Person {
id: ID!,
name: String!,
tasks: [Task!]! @relation(name: "PersonTask")
}
type Task {
id: ID!,
description: String!
person: Person @relation(name: "PersonTask")
}
Run:
graphql-up tasks.schema
It will generate two url for use, just grap one. It will open graphcool.
We can query the data:
{
allPersons {
id,
name,
tasks {
id,
description
}
}
}
We won't get any, because we haven't create anything.
Create some mock data:
mutation {
createPerson(name:"Zhentian") {
id,
name
}
}
// get back
"data": {
"createPerson": {
"id": "cj2t31akybh3g01184klolj0t",
"name": "Zhentian"
}
}
}
Now if query again:
{
allPersons {
id,
name,
tasks {
id,
description
}
}
}
// get back
"data": {
"allPersons": [
{
"id": "cj2t31akybh3g01184klolj0t",
"name": "Zhentian",
"tasks": []
}
]
}
}
Create data for task:
mutation {
createTask(description: "Learn GraphQL", personId: "cj2t31akybh3g01184klolj0t") {
id,
description
}
}
// get back
"data": {
"createTask": {
"id": "cj2t37fo7kizn0102kf9otzh5",
"description": "Learn GraphQL"
}
}
}
When we do the query again:
{
allPersons {
id,
name,
tasks {
id,
description
}
}
}
// get back
"data": {
"allPersons": [
{
"id": "cj2t31akybh3g01184klolj0t",
"name": "Zhentian",
"tasks": [
{
"id": "cj2t37fo7kizn0102kf9otzh5",
"description": "Learn GraphQL"
}
]
}
]
}
}
Create Task and Person in same mutation:
mutation {
createPerson(name:"Wan", tasks:[
{description: "Learn Recompose"},
{description: "Learn SCSS"}
]) {
id,
name
}
}
After done with playground, can click "Generate code". Select Node env:
Install:
npm install lokka lokka-transport-http --save
Copy the code to index.js file, we should be able to run the code and get data back.
[GraphQL] Deploy a GraphQL dev playground with graphql-up的更多相关文章
- Why GraphQL is Taking Over APIs
A few years ago, I managed a team at DocuSign that was tasked with re-writing the main DocuSign web ...
- 一种不错的 BFF Microservice GraphQL/REST API 层的开发方式
云原生(Cloud Native)Node JS Express Reactive 微服务模板 (REST/GraphQL) 这个项目提供了完整的基于 Node JS / Typescript 的微服 ...
- 使用ASP.NET Core开发GraphQL服务器 -- 预备知识(上)
为了介绍使用ASP.NET Core构建GraphQL服务器,本文需要介绍一下GraphQL,其实看官网的文档就行. 什么是GraphQL? GraphQL 既是一种用于 API 的查询语言也是一个满 ...
- 朱晔的互联网架构实践心得S2E5:浅谈四种API设计风格(RPC、REST、GraphQL、服务端驱动)
Web API设计其实是一个挺重要的设计话题,许多公司都会有公司层面的Web API设计规范,几乎所有的项目在详细设计阶段都会进行API设计,项目开发后都会有一份API文档供测试和联调.本文尝试根据自 ...
- API设计风格(RRC、REST、GraphQL、服务端驱动)
API设计风格(RRC.REST.GraphQL.服务端驱动) Web API设计其实是一个挺重要的设计话题,许多公司都会有公司层面的Web API设计规范,几乎所有的项目在详细设计阶段都会进行API ...
- 使用graphql-code-generator 生成graphql 代码
类似的工具比较多,比如prisma .qloo.golang 的gqlgen.apollo-codegen graphql-code-generator 也是一个不错的工具(灵活.模版自定义...) ...
- QLoo graphql engine 学习一 基本试用(docker&&docker-compose)
说明:使用docker-compose 进行安装 代码框架 使用命令行工具创建 qlooctl install docker qloo-docker 运行qloo&&gloo 启动 ...
- 前端从零开始学习Graphql
学习本姿势需要电脑装有node,vue-cli相关环境,以及要有node,express,koa,vue相关基础 本文相关demo的github地址: node服务:https://github.co ...
- UWP GraphQL数据查询的实现
1. 缘起 Facebook 的移动应用从 2012 年就开始使用 GraphQL.GraphQL 规范于 2015 年开源,现已经在多种环境下可用,并被各种体量的团队所使用. 在这个链接可以看到更多 ...
随机推荐
- JMS基础知识
JMS规范: jms的基本构件: 连接工厂(connectionFactory):客户用来创建连接的对象.比如:activeMQ提供的ActiveMQConnectionFactory. 连接(co ...
- regular-第一课(正则表达式基础)
之前一直听说正则表达式,尤其是在学习java的时候,遇到了不少关于正则表达式的用法.例如一个输入框,你可以使用正则表达式限制输入的内容.当然,在android以后,正则表达式就几乎没有怎么用了.不过呢 ...
- 32.Node.js中的常用工具类util
转自:http://www.runoob.com/nodejs/nodejs-module-system.html util是一个Node.js核心模块,提供常用函数的集合,用于弥补JavaScrip ...
- Impala架构
Impala是Cloudera在受到Google的Dremel启发下开发的实时交互SQL大数据查询工具,Impala没有再使用缓慢的 Hive+MapReduce批处理,而是通过使用与商用并行关系数据 ...
- POJ 1738 An old Stone Game(石子合并 经典)
An old Stone Game Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 3672 Accepted: 1035 ...
- HDU4630-No Pain No Game(离线,线段树)
Problem Description Life is a game,and you lose it,so you suicide. But you can not kill yourself bef ...
- 疯狂html5讲义(二):HTML5简的经常使用元素与属性(二):html5新增的通用属性
1.contentEditable属性 true时可直接编辑html元素里面的内容.且具有"可继承"的特点. 编辑后不要刷新页面.否则编辑的内容会丢失,能够通过该元素的innerH ...
- hdu 2795 Billboard(线段树单点更新)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- stackFromBottom-listview 内容从底部开始填充
今天遇到了一个问题,就是listview虽然占满了整个屏幕,但是,当它的内容只有几条的时候,它会从底部开始显示,上面留有空白.后来进入xml发现,listview有个属性stackFromBottom ...
- caffe 在 windows 下的配置(scripts\build_win.cmd)
官网配置文档见:GitHub - BVLC/caffe at windows 1. windows 设置 requirements: visual studio 2013/2015 CMake > ...