[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 年开源,现已经在多种环境下可用,并被各种体量的团队所使用. 在这个链接可以看到更多 ...
随机推荐
- Android5.0L退出APP横竖屏切换导致的触摸屏输入(Touch Event)无效(冻屏)问题分析(Key Event仍然有效)
.Nexus4和Nexus5在相同的简单測试下没有重现此问题,因没有源代码所以无法Debug和打印log.兴许会尝试获取nexus的源代码以了解它的改动方案. 二.解决方案 通过初步分析.深入分析.对 ...
- Linux 内存管理与系统架构设计
Linux 提供各种模式(比如,消息队列),但是最著名的是 POSIX 共享内存(shmem,shared memory). Linux provides a variety of schemes ( ...
- 理性分析 C++(-O2) 和 JS 的性能差距
laptop: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz.. Test1: 最后一行:时间(ms) #pragma GCC optimize("O2& ...
- sqlserver 导入excel数据
有的时候需要将excel数据导入到数据库中,这里介绍一下操作方法: 1.可能需要安装sqlserver的插件 [AccessDatabaseEngine],这个可以在网上早,很多. 2.安装插件后,右 ...
- Vue的学习--遇到的一些问题和解决方法
包括: 1.Missing space before function parentheses 2.如何给.vue文件的页面添加css 3.如何给.vue文件页面里的元素添加监听器 4.如何为每一个页 ...
- AJAX - 封装AJAX GET 数组join( )方法 键值对取value POST请求参数注意点
function objToStr(obj){ obj.t = new Date().getTime(); // 给obj动态增加了一个属性 // 这个给对象添加属性的方法, 会被直接加到键值对里?? ...
- 手动挂接NFS
环境: 单板:s3c2440 内核:Linux-2.6.22.6 U-boot1.16 初始根文件系统Yaffs2 前提条件 1. 开发板上要烧写好文件系统 2. 能正常开机进入Linux系统 3. ...
- BeautifulSoup的高级应用 之 contents children descendants string strings stripped_strings
继上一节.BeautifulSoup的高级应用 之 find findAll,这一节,主要解说BeautifulSoup有关的其它几个重要应用函数. 本篇中,所使用的html为: html_doc = ...
- bootstrap课程11 模态框如何使用
bootstrap课程11 模态框如何使用 一.总结 一句话总结:多看手册咯. 1.模态框对应的英文单词是什么? modal,而不是madel 2.bootstrap中如何关闭某个效果? 比如要关掉m ...
- 1.15 Python基础知识 - 函数
函数是可重用的程序代码段. 一.函数的声明和调用 声明格式: def 函数名([形参列表]): 函数体 调用格式: 函数名([实参列表]) 函数名:是一种标识符,命名规则为全小写字母,可以使用下划线增 ...