知识卡片

普通读书笔记卡 · 3503.e

列表与元素分别约束非空

理解等级:中级

GraphQL 列表用 [T] 表示;! 放在元素类型后约束元素非空,放在列表类型后约束列表本身非空。因此 [T!] 允许整个列表为 null,[T]! 允许列表含 null,[T!]! 两者都不允许。空列表 [] 仍满足所有这些非空约束。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 8 章《Designing GraphQL APIs》(源文件:_epub-src/OEBPS/Text/08.htm) - 结论依据:原文逐一说明列表与元素各自的感叹号,并以表 8.1 列出 `null`、空列表和含 null 元素的有效组合。 - 原始内容:In list properties, we can use two exclamation points: one for the list itself and another for the item within the list. To make both the list and its contents non-nullable, we use exclamation points for both.