What is an exclamation point in GraphQL?
What is an exclamation point in GraphQL?
In GraphQL, an exclamation point (!) is used to denote that a field is non-nullable. This means that the field must always return a value and cannot be null. The exclamation point can be applied to both scalar types and custom object types within the GraphQL schema.
By default, scalar types in GraphQL, such as String, Int, Float, Boolean, and ID, are nullable, meaning they can return a null value. However, by adding an exclamation point to the type definition, you can specify that the field must always return a value and cannot be null. For example:
type ExampleType {
someField: String!
}
In this example, someField is a non-nullable String field, meaning it must always return a string value and cannot be null.
Similarly, the exclamation point can be used to denote non-nullable fields in custom object types. For instance:
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.