知识卡片
感叹号声明非空字段
GraphQL 字段类型后加 ! 表示该位置不能返回 null,例如 name: String!。这让客户端可按非空契约使用字段;服务端若无法满足约束,查询执行会产生错误并按模式规则处理结果,不能把 ! 当成自动补值机制。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《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.