返回主题:GraphQL 模式、查询与执行

知识卡片

普通读书笔记卡 · 3503.b

感叹号声明非空字段

理解等级:中级

GraphQL 字段类型后加 ! 表示该位置不能返回 null,例如 name: String!。这让客户端可按非空契约使用字段;服务端若无法满足约束,查询执行会产生错误并按模式规则处理结果,不能把 ! 当成自动补值机制。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 8 章《Designing GraphQL APIs》(源文件:_epub-src/OEBPS/Text/08.htm) - 结论依据:原文以 `name: String!` 说明感叹号表示 non-nullable,并解释客户端据此预期字段不会是 null。 - 原始内容:We mark a property as non-nullable by placing an exclamation point at the end of the property definition: name: String! This line defines a property name of type String , and it marks it as non-nullable by using an exclamation point.