Câu hỏi phỏng vấn GraphQL
Câu hỏi

What is an exclamation point in GraphQL?

Câu trả lời

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.

Non-Nullable Scalar Types

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:

graphql Copy
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[2][4][6].

Non-Nullable Object Fields

Similarly, the exclamation point can be used to denote non-nullable fields in custom object types. For instance:

graphql Copy
type ExampleType {
  someObject: AnotherType!
}

Here, someObject is a non-nullable field of type AnotherType, indicating that it must always return an instance of AnotherType and cannot be null[2][4][6].

Lists and Non-Null

The exclamation point can also be used with lists to ensure that the list itself or the items within the list are non-nullable. For example:

graphql Copy
type Query {
  listOfStrings: [String!]!
}

In this case, listOfStrings is a non-nullable list of non-nullable strings, meaning the list itself cannot be null, and none of its items can be null[5][7][10].

Implications in Queries and Mutations

Wh...

entry

entry

Gợi ý câu hỏi phỏng vấn

senior

Can you make a GraphQL type both an input and output type?

senior

How to implement a set of GraphQL mutations in single transaction?

entry

What is GraphQL?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào