graphql 节点 api:如何将字段定义为可选字段?

graphql node api: how can I define a field as optional?

GraphQL 允许您指定字段是否可选(添加 !

使用节点 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