Given this GraphQL schema and data, what will be the result of the query below?
type Query {
book: Book
}
type Book {
title: String
author: Author
}
type Author {
name: String
}
const data = {
book: {
title: "1984",
author: {
name: "George Orwell"
}
}
};
Query:
{
book {
title
author {
name
}
}
}const data = { book: { title: "1984", author: { name: "George Orwell" } } };
Default resolvers return the value from the object if the field name matches.
The default resolver returns the value of the field from the parent object. Since the data has matching fields, the query returns the full nested data.
Consider a GraphQL schema with a field author of type Author. The data object for book does not have the author property. What will the default resolver return for author?
Default resolvers return null if the field is not present in the object.
If the field is missing in the data object, the default resolver returns null instead of throwing an error or returning other values.
Choose the correct JavaScript function that acts as a default resolver for a field.
The default resolver uses the info.fieldName to get the field name dynamically.
The default resolver function receives parent, args, context, and info. It returns the property of parent matching info.fieldName.
When using default resolvers on a deeply nested GraphQL query, what is a common performance concern?
Think about how default resolvers access nested fields and data fetching.
Default resolvers simply access properties on objects and do not optimize data fetching. This can lead to multiple redundant calls if the data source is not optimized or batched.
Given this schema and data, the query returns null for author.name. Identify the cause.
type Query {
book: Book
}
type Book {
title: String
author: Author
}
type Author {
name: String
}
const data = {
book: {
title: "Dune",
authorName: "Frank Herbert"
}
};
Query:
{
book {
title
author {
name
}
}
}Check how the data structure matches the schema fields.
The data has 'authorName' as a flat property instead of an 'author' object with 'name'. Default resolvers look for 'author' object but find none, so return null.