简体   繁体   English

“ graphql.NewList(type)”是做什么的?

[英]What does “graphql.NewList(type)” do?

As it turns out, graphql-go 's help doc is not beginner friendly. 事实证明, graphql-go的帮助文档对新手不友好。 I'm simply wondering what .NewList() does in, say, the following code: Type: graphql.NewList(types.Workouts) 我只是想知道.NewList()在以下代码中的作用: Type: graphql.NewList(types.Workouts)

It means array type 这意味着array类型

Lists work in a similar way: We can use a type modifier to mark a type as a List, which indicates that this field will return an array of that type. 列表的工作方式类似:我们可以使用类型修饰符将类型标记为列表,这表明该字段将返回该类型的array In the schema language, this is denoted by wrapping the type in square brackets, [ and ] . 在模式语言中,这是通过将类型包装在方括号[]

// js
languages: {
    type: new GraphQLNonNull(new GraphQLList(GraphQLString))
}

// schema language
languages: [String]! // returns empty array or array of strings

docs 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM