[GraphQL] Use GraphQLList with GraphQLObject Types
When working with collections of things in GraphQL, we'll always reach out for the GraphQLList
Type. In this video, we'll learn how to use GraphQLList from the graphql
package in combination with a GraphQLObject
Type to create a field that returns a collection in our Schema.
We can use GraphQLList to fetch list objects:
const queryType = new GraphQLObjectType({
name: 'QueryType',
description: 'The root query type',
fields :{
videos: {
type: new GraphQLList(videoType),
resolve: getVideos
},
video: {
type: videoType,
args: {
id: {
type : new GraphQLNonNull(GraphQLID),
description: 'The id of the video'
}
},
resolve: (_, args) => getVideoById(args.id)
}
}
});
Data:
const videoA = {
id: 'a',
title: 'Create a GraphQL Schema',
duration: ,
watched: true,
};
const videoB = {
id: 'b',
title: 'Ember.js CLI',
duration: ,
watched: false,
};
const videos = [videoA, videoB];
const getVideoById = (id) => new Promise((resolve) => {
const [video] = videos.filter((video) => {
return video.id === id;
}); resolve(video);
}); const getVideos = () => new Promise((resolve) => resolve(videos)); exports.getVideoById = getVideoById;
exports.getVideos = getVideos;
[GraphQL] Use GraphQLList with GraphQLObject Types的更多相关文章
- [GraphQL] Query Lists of Multiple Types using a Union in GraphQL
Unions are used when we want a GraphQL field or list to handle multiple types of data. With a Union ...
- GraphQL Java Demo代码
mvn 引用GraphQL <dependency> <groupId>com.graphql-java</groupId> <artifactId>g ...
- 转 GraphQL Schema Stitching explained: Schema Delegation
转自官方文档 In the last article, we discussed the ins and outs of remote (executable) schemas. These remo ...
- 使用Hot Chocolate和.NET 6构建GraphQL应用(3) —— 实现Query基础功能
系列导航 使用Hot Chocolate和.NET 6构建GraphQL应用文章索引 需求 在本文中,我们通过一个简单的例子来看一下如何实现一个最简单的GraphQL的接口. 实现 引入Hot Cho ...
- [GraphQL] Use GraphQL's Object Type for Basic Types
We can create the most basic components of our GraphQL Schema using GraphQL's Object Types. These ty ...
- [GraphQL] Query GraphQL Interface Types in GraphQL Playground
Interfaces are similar to Unions in that they provide a mechanism for dealing with different types o ...
- [GraphQL] Mutations and Input Types
Sometimes, you want to resues object type when doing mutation, you can use 'input' type to help: inp ...
- graphql 新API 开发方式
我们知道 GraphQL 使用 Schema 来描述数据,并通过制定和实现 GraphQL 规范 定义了支持 Schema 查询的 DSQL (Domain Specific Query Langua ...
- GraphQL:一种不同于REST的接口风格
从去年开始,JS算是完全踏入ES6时代.在React相关项目中接触到了一些ES6的语法.这次接着GraphQL这种新型的接口风格,从后端的角度接触ES6. 这篇文章从ES6的特征讲起,打好语法基础:然 ...
随机推荐
- 78.pipe多管道云端,客户端通信
压力测试截图: 云端 定义管道缓存区大小,最多连接数量(线程个数),当前线程个数,管道名字 //缓冲区大小 #define SIZE 4096 //最多连接数量 #define MAX_CONNECT ...
- NOI2018归程(Kruskal重构树)
题目描述 本题的故事发生在魔力之都,在这里我们将为你介绍一些必要的设定. 魔力之都可以抽象成一个 n 个节点.m 条边的无向连通图(节点的编号从 1 至 n). 我们依次用 l,a 描述一条边的长度. ...
- Robot Framework 自动化测试
Robot Framework 自动化测试 RIDE 是 Robot Framework 测试数据的编辑器.它使测试用例的创建.运行.测试项目的组织可以在图形界面下完成. 通过 RIDE 去学习和使用 ...
- LoadRunner IP欺骗使用
- Android提示版本号更新操作流程
Android提示版本号更新操作流程 2014年5月8日: andorid的app应用中都会有版本号更新的操作,今天空暇的时候就花了点心思弄了一下.主要技术方面用到了AsyncTask异步载入.htt ...
- C++源文件到可运行文件的过程
一.四个步骤 对于C/C++编写的程序,从源码到可运行文件,一般经过以下四个步骤: 1).预处理,产生.ii文件 2).编译,产生汇编文件(.s文件) 3).汇编,产生目标文件(.o或.obj文 ...
- 2. ZooKeeper的ZAB协议。
转自:https://blog.csdn.net/en_joker/article/details/78662880 ZooKeeper并没有完全采用Paxos算法,而是使用了一种称为ZooKeepe ...
- C#做完一个网站怎么发布?
前段时间在局域网上发布了一个自己做的网站,发布过程中遇到了不少问题.下面就发布过程和发布过程中遇到的问题与(你)大家一起分享一下,希望对(你)大家有所帮助吧! 在将ASP.NET网站发布到服务器之前需 ...
- Spring view controller
https://www.zifangsky.cn/648.html https://www.zifangsky.cn/665.html https://www.zifangsky.cn/671.htm ...
- 洛谷—— P1765 手机_NOI导刊2010普及(10)
https://www.luogu.org/problem/show?pid=1765#sub 题目描述 一般的手机的键盘是这样的: 1 2 abc 3 def 4 ghi 5 jkl 6 mno 7 ...