0
0
GraphQLquery~5 mins

Input types in GraphQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an Input type in GraphQL?
An Input type in GraphQL is a special kind of type used to pass complex objects as arguments to queries or mutations. It defines the shape of the data you can send to the server.
Click to reveal answer
intermediate
Can Input types contain fields that are other object types?
No, Input types can only contain fields of scalar types, enums, or other input types. They cannot contain regular object types because those are for output only.
Click to reveal answer
beginner
Why do we use Input types instead of regular object types for arguments?
Input types are designed for input data validation and safety. They ensure the data sent to the server matches expected shapes and prevent misuse of output-only types.
Click to reveal answer
beginner
How do you define an Input type in GraphQL SDL?
You define an Input type using the input keyword followed by the name and fields. For example:<br>
input UserInput {
  name: String!
  age: Int
}
Click to reveal answer
intermediate
Can Input types have default values for their fields?
Yes, when using Input types in arguments, you can provide default values for fields to make some inputs optional or have fallback values.
Click to reveal answer
Which keyword is used to define an Input type in GraphQL?
Ainput
Btype
Cinterface
Denum
Can Input types contain fields of regular object types?
AYes, always
BOnly in mutations
COnly if marked nullable
DNo, never
What is the main purpose of Input types in GraphQL?
ATo define the shape of data returned from the server
BTo define the shape of data sent to the server
CTo create database tables
DTo style the UI
Which of these is a valid field type inside an Input type?
AQuery
BObjectType
CString
DSubscription
Can you provide default values for fields in Input types when used as arguments?
AYes
BNo
COnly for scalar fields
DOnly for enum fields
Explain what Input types are in GraphQL and why they are important.
Think about how you send data to the server and how GraphQL expects it.
You got /4 concepts.
    Describe how to define and use an Input type in a GraphQL mutation.
    Imagine you want to send a new user’s info to the server.
    You got /4 concepts.