知识卡片
自定义标量需实现行为
内建标量不足以表达日期时间等值时,可在 GraphQL SDL 中声明 scalar Datetime,再在服务端实现解析、校验和序列化。声明只给出类型名称,不会自动建立日期时间规则;具体格式和失败处理属于运行时契约。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 8 章《Designing GraphQL APIs》(源文件:_epub-src/OEBPS/Text/08.htm)
- 结论依据:原文因内建标量缺少日期时间而声明 `scalar Datetime`,同时指出验证与序列化规则需在服务端实现。
- 原始内容:GraphQL doesn’t have a built-in scalar of that type, so we have to create our own. To declare a custom date-time scalar, we use the following statement: scalar Datetime We also need to define how this scalar type is validated and serialized.