0
0
GraphQLquery~5 mins

Required fields with non-null (!) in GraphQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the exclamation mark (!) mean in GraphQL field definitions?
It means the field is required and cannot be null. The server must always return a value for this field.
Click to reveal answer
beginner
How do you define a required string field called name in GraphQL?
You write name: String! which means name must always have a string value and cannot be null.
Click to reveal answer
intermediate
What happens if a required field with ! is missing or null in the response?
The GraphQL server returns an error and the query fails or returns partial data with errors.
Click to reveal answer
intermediate
Can a required field with ! have a default value in GraphQL?
No, the ! means the client must provide a value or the server must always return a value. Default values are set differently in input types.
Click to reveal answer
beginner
Why use required fields with ! in GraphQL schemas?
To ensure important data is always present, improving data reliability and helping clients avoid null checks.
Click to reveal answer
In GraphQL, what does email: String! mean?
AThe email field is optional and can be null
BThe email field is required and cannot be null
CThe email field is a list of strings
DThe email field is a number
What will happen if a required field is missing in the GraphQL response?
AThe query returns partial data with errors
BThe server returns null silently
CThe server ignores the field
DThe client automatically fills the field
How do you mark a field as optional in GraphQL?
AAdd an exclamation mark (!)
BUse square brackets []
CDo not add an exclamation mark
DUse a question mark (?)
Can a required field with ! have a null value in the response?
ANo, never
BYes, always
COnly if the client allows it
DOnly if the server is in debug mode
Which of these is a valid required field declaration in GraphQL?
Aage: Int
Bage: !Int
Cage!: Int
Dage: Int!
Explain what the exclamation mark (!) means in GraphQL field types and why it is useful.
Think about how GraphQL enforces data rules.
You got /4 concepts.
    Describe what happens if a required field with ! is missing or null in a GraphQL response.
    Consider how GraphQL handles errors for required fields.
    You got /3 concepts.