[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 年开源,现已经在多种环境下可用,并被各种体量的团队所使用. 在这个链接可以看到更多 ...
随机推荐
- Android中的MVP架构初探
说来羞愧,MVP的架构模式已经在Android领域出现一两年了.可是到今天自己才開始Android领域中的MVP架构征程. 闲话不多说,開始吧. 一.架构演变概述 我记得我找第一份工作时,面试官问我& ...
- UVa10397_Connect the Campus(最小生成树)(小白书图论专题)
解题报告 题目传送门 题意: 使得学校网络互通的最小花费,一些楼的线路已经有了. 思路: 存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树 #include <ios ...
- 写了个去重复文件的 PHP 脚本,
写了个去重复文件的 PHP 脚本点击打开链接 把各个零散网盘.邮箱和服务器上的文件,三台电脑上的文件收集在新硬盘里,然后清空了网络和电脑上的文件.才发现这个文件不能这里放点,那里存点,到时候不知道在哪 ...
- httpurlconnection发送文件到服务端并接收
httpurlconnection发送文件到服务端并接收 客户端 import java.io.DataInputStream; import java.io.File; import java.io ...
- POJ Fence Repair(优先队列)
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 51346 Accepted: 16857 De ...
- 关于Webpack详述系列文章 (第一篇)
WebPack官网地址(https://webpack-china.org/) 1. 什么是WebPack WebPack可以看做是模块打包机:它做的事情是,分析你的项目结构,找到JavaScript ...
- 洛谷 P2908 [USACO08OPEN]文字的力量Word Power
P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...
- iOS关闭键盘简单实现(objc/swift)
Objective-C 代码实例方式一 [[[UIApplication sharedApplication] keyWindow] endEditing:YES]; 假设一个view上有很多Text ...
- curl如何发起DELETE/PUT请求
curl如何发起DELETE/PUT请求 DELETE: curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); PUT: curl_setopt($ch ...
- shell脚本中的反引号,单引号,双引号与反斜杠
转自:http://blog.sina.com.cn/s/blog_6561ca8c0102we2i.html 反引号位 (`)经常被忽略,而且容易与单引号弄混.它位于键盘的Tab键的上方.1键的左方 ...