[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 年开源,现已经在多种环境下可用,并被各种体量的团队所使用. 在这个链接可以看到更多 ...
随机推荐
- C# XML类学习整理(待补)
一.读取xml文件内容: #region "获取xml文件内容" //将xml文件加载进来 XDocument xdoc = XDocument.Load("F:\\6. ...
- TextView- 内容过长省略号设定
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_conte ...
- php实现希尔排序(总结)
php实现希尔排序(总结) 一.总结 1.希尔排序的算法思路:分组排序, 缩小增量排序,插入排序 2.算法思路: 循环非常好写 有几次gap:log2(n) 每次gap有几组:gap组 每组有几个元素 ...
- JAVA MessageDigest(MD5加密等)
转自http://blog.csdn.net/hudashi/article/details/8394158 一.概述 java.security.MessageDigest类用于为应用程序提供信息摘 ...
- 百度地图API 添加标签
1.手动创建数据,实际项目则是接受GPS信息 /建立坐标点: // lng:经度 lat:纬度 var points = [ {"lng":112.58,"lat&quo ...
- [TS] Parse a string to an integer
A common interview question is to write a function that converts a string into an integer e.g. &q ...
- amazeui学习笔记二(进阶开发4)--JavaScript规范Rules
amazeui学习笔记二(进阶开发4)--JavaScript规范Rules 一.总结 1.注释规范总原则: As short as possible(如无必要,勿增注释):尽量提高代码本身的清晰性. ...
- Android实现微信分享及注意事项
一.获取帮助文档并下载相关资料 首先打开微信开放平台:https://open.weixin.qq.com/ 如果没有注册,请先注册并上传开发者资料等待审核. 资源中心----移动应用开发----分享 ...
- vue使用jsonp
axios不支持jsonp,所以需使用其他插件:vue-jsonp npm i vue-jsonp -S 然后在 src/main.js : import Vue from 'vue' import ...
- DataTable +chart控件
//这是仿你的DataTable //-----开始--------- DataTable dataTable1 = new System.Data.DataTable(); dataTable1.C ...