0
0
GraphQLquery~5 mins

Default resolvers in GraphQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a default resolver in GraphQL?
A default resolver is the built-in function GraphQL uses to fetch the value of a field when no custom resolver is provided. It simply returns the property of the source object that matches the field name.
Click to reveal answer
beginner
How does GraphQL's default resolver find the value for a field?
It looks for a property on the parent object with the same name as the field and returns its value directly.
Click to reveal answer
intermediate
When would you need to write a custom resolver instead of relying on the default resolver?
When the data needs transformation, fetching from another source, or combining multiple fields, you write a custom resolver. The default resolver only returns existing properties as-is.
Click to reveal answer
beginner
True or False: The default resolver can handle nested objects automatically.
True. If the field's value is an object, the default resolver returns it, and GraphQL continues resolving fields on that nested object.
Click to reveal answer
beginner
What happens if the default resolver does not find a matching property on the source object?
It returns null or undefined, which means the field will have no value in the query result unless a custom resolver handles it.
Click to reveal answer
What does the default resolver in GraphQL do when resolving a field?
AReturns the property of the source object matching the field name
BAlways returns null
CFetches data from a database automatically
DTransforms the data before returning
When is a custom resolver necessary instead of using the default resolver?
AWhen data needs to be fetched from another source or transformed
BWhen the field name matches the source object property
CWhen the query is simple
DWhen the default resolver returns the correct value
If a field's value is an object, how does the default resolver handle it?
AIt throws an error
BIt returns null
CIt returns the object and GraphQL resolves nested fields automatically
DIt converts the object to a string
What will the default resolver return if the source object does not have the requested field?
AAn error message
BNull or undefined
CThe entire source object
DA default string value
Which of the following is NOT true about default resolvers?
AThey handle nested objects by returning them
BThey return the property matching the field name
CThey are used when no custom resolver is defined
DThey automatically fetch data from databases
Explain how GraphQL's default resolver works when resolving a field in a query.
Think about how GraphQL finds the value without custom code.
You got /4 concepts.
    Describe a situation where you would need to write a custom resolver instead of relying on the default resolver.
    When the data is not directly available as a simple property.
    You got /4 concepts.