博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[GraphQL] Use GraphQLList with GraphQLObject Types
阅读量:4355 次
发布时间:2019-06-07

本文共 1418 字,大约阅读时间需要 4 分钟。

When working with collections of things in GraphQL, we'll always reach out for the GraphQLListType. 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: 120,    watched: true,};const videoB = {    id: 'b',    title: 'Ember.js CLI',    duration: 240,    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;

 

转载于:https://www.cnblogs.com/Answer1215/p/6269835.html

你可能感兴趣的文章
web.xml文件的作用
查看>>
linux下oracle调试小知识
查看>>
alert弹出窗口,点击确认后关闭页面
查看>>
oracle问题之数据库恢复(三)
查看>>
单点登陆(SSO)
查看>>
HR,也确实“尽职尽责”
查看>>
MaxComputer 使用客户端配置
查看>>
20190823 顺其自然
查看>>
阅读《余生有你,人间值得》有感
查看>>
每日英语
查看>>
[leetcode] Regular Expression Matching
查看>>
BZOJ1927: [Sdoi2010]星际竞速(最小费用最大流 最小路径覆盖)
查看>>
洛谷P1317 低洼地
查看>>
MVC Redirect 页面跳转不了
查看>>
李开复有哪些地方做的不好
查看>>
12.22
查看>>
新版本的molar mass(uva-1586)明明debug过了,各种测试还是WA真是气死我了
查看>>
gdb(ddd,kdevelop等)调试ZeroIce开发的应用程序,中断信号引起的问题
查看>>
牛股助推器(每股收益率)
查看>>
SpringCloud+feign 基于Springboot2.0 负载均衡
查看>>