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的更多相关文章

  1. 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 ...

  2. 一种不错的 BFF Microservice GraphQL/REST API 层的开发方式

    云原生(Cloud Native)Node JS Express Reactive 微服务模板 (REST/GraphQL) 这个项目提供了完整的基于 Node JS / Typescript 的微服 ...

  3. 使用ASP.NET Core开发GraphQL服务器 -- 预备知识(上)

    为了介绍使用ASP.NET Core构建GraphQL服务器,本文需要介绍一下GraphQL,其实看官网的文档就行. 什么是GraphQL? GraphQL 既是一种用于 API 的查询语言也是一个满 ...

  4. 朱晔的互联网架构实践心得S2E5:浅谈四种API设计风格(RPC、REST、GraphQL、服务端驱动)

    Web API设计其实是一个挺重要的设计话题,许多公司都会有公司层面的Web API设计规范,几乎所有的项目在详细设计阶段都会进行API设计,项目开发后都会有一份API文档供测试和联调.本文尝试根据自 ...

  5. API设计风格(RRC、REST、GraphQL、服务端驱动)

    API设计风格(RRC.REST.GraphQL.服务端驱动) Web API设计其实是一个挺重要的设计话题,许多公司都会有公司层面的Web API设计规范,几乎所有的项目在详细设计阶段都会进行API ...

  6. 使用graphql-code-generator 生成graphql 代码

    类似的工具比较多,比如prisma .qloo.golang 的gqlgen.apollo-codegen graphql-code-generator 也是一个不错的工具(灵活.模版自定义...) ...

  7. QLoo graphql engine 学习一 基本试用(docker&&docker-compose)

      说明:使用docker-compose 进行安装 代码框架 使用命令行工具创建 qlooctl install docker qloo-docker 运行qloo&&gloo 启动 ...

  8. 前端从零开始学习Graphql

    学习本姿势需要电脑装有node,vue-cli相关环境,以及要有node,express,koa,vue相关基础 本文相关demo的github地址: node服务:https://github.co ...

  9. UWP GraphQL数据查询的实现

    1. 缘起 Facebook 的移动应用从 2012 年就开始使用 GraphQL.GraphQL 规范于 2015 年开源,现已经在多种环境下可用,并被各种体量的团队所使用. 在这个链接可以看到更多 ...

随机推荐

  1. [Python] List & Object spread in Python

    def myfunc(x, y, z): print(x, y, z) tuple_vec = (, , ) dict_vec = {, , } >>> myfunc(*tuple_ ...

  2. struts2中action手动获取參数

    struts2中action手动获取Session,jsp页面參数 1. ActionContext 在Struts2开发中,除了将请求參数自己主动设置到Action的字段中,我们往往也须要在Acti ...

  3. Android Support 包里到底有什么

    大家假设喜欢我的博客,请关注一下我的微博,请点击这里(http://weibo.com/kifile),谢谢 转载请标明出处(http://blog.csdn.net/kifile),再次感谢 随着 ...

  4. android中图片倒影、圆角效果重绘

    本文用来记录一些Android 操作图片的方法,方便查看. 1.将Drawable转化为Bitmap public static Bitmap drawableToBitmap(Drawable dr ...

  5. 中间件 —— 消息中间件(MOM)

    维基百科对消息中间件的定义为:Message-oriented middleware (MOM) is software or hardware infrastructure supporting s ...

  6. 项目列表dl、dt、dd使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. python学习三:列表,元组

    1.列表: 1.列表的定义方式: list1 = [1,2,3,4,"hello","world"] 如上所示,list1就是一个列表,列表的内容以中括号包含起 ...

  8. C语言库函数,头文件

    参看:https://zhidao.baidu.com/question/328173842.html 该文件包含了的C语言标准库函数的定义 stdlib.h里面定义了五种类型.一些宏和通用工具函数. ...

  9. PythonNET网络编程3

    IO IO input output 在内存中存在数据交换的操作都可以认为是IO操作 和终端交互 : input print 和磁盘交互 : read write 和网络交互 : recv send ...

  10. 洛谷 P3131 [USACO16JAN]子共七Subsequences Summing to Sevens

    P3131 [USACO16JAN]子共七Subsequences Summing to Sevens 题目描述 Farmer John's NN cows are standing in a row ...