node.js - graphql node api:如何将字段定义为可选?
问题描述
GraphQL 允许您指定一个字段是否是可选的(添加!
)
使用 Node API,我找不到该选项。
见https://graphql.org/graphql-js/constructing-types/
我也经历了没有运气的类型
见https://github.com/graphql/graphql-js/blob/main/src/index.ts
我错过了什么?
我基本上想要
type MyEntity {
uuid: ID!
name: String!
}
代替
type MyEntity {
uuid: ID
name: String
}
解决方案
我找到了答案
const preType:GraphQLOutputType = GraphQLInt;
// wrap the type with `GraphQLNonNull`
const type = new GraphQLNonNull(preType);
见https://github.com/graphql/graphql-js/blob/main/src/type/definition.ts#L391
推荐阅读
- python - 在 QPlainTextEdit 元素中使用 Shift+Return 的 QShortcut 和 QKeySequence
- android - 模拟器无法启动(c066d201:未处理的退出 1d)
- vb.net - 公共函数返回 VB.Net
- python - 带复位的累积和
- android - 为什么在使用“flutter build aar”命令制作 aar 时,Android 项目中无法访问 dart 类?
- javascript - 设置 favicon 时不出现 React-FontAwesome 图标
- r - 用 survfit() 拟合生存曲线
- wpf - 您将如何在 WPF 中构建移动样式的 Shift 键?
- angular - 如何在单击反应形式的提交按钮时重置所有验证
- perl - 带有 U 选项和大写选项字符的音译