Bird
Raised Fist0
GraphQLquery~20 mins

Default resolvers in GraphQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Default Resolver Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What is the output of this GraphQL query using default resolvers?

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
    }
  }
}
GraphQL
const data = {
  book: {
    title: "1984",
    author: {
      name: "George Orwell"
    }
  }
};
A{ "data": { "book": null } }
B{ "data": { "book": { "title": null, "author": { "name": null } } } }
C{ "data": { "book": { "title": "1984", "author": { "name": "George Orwell" } } } }
D{ "errors": [ { "message": "Field 'title' not found" } ] }
Attempts:
2 left
💡 Hint

Default resolvers return the value from the object if the field name matches.

🧠 Conceptual
intermediate
1:30remaining
How do default resolvers behave when a field is missing in the 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?

AIt throws a runtime error because the field is missing.
BIt returns <code>null</code> for the <code>author</code> field.
CIt returns an empty object <code>{}</code> for <code>author</code>.
DIt returns the string "undefined".
Attempts:
2 left
💡 Hint

Default resolvers return null if the field is not present in the object.

📝 Syntax
advanced
2:00remaining
Which option correctly defines a default resolver function in GraphQL?

Choose the correct JavaScript function that acts as a default resolver for a field.

Afunction defaultResolver(parent, args, context, info) { return parent[info.fieldName]; }
Bfunction defaultResolver(parent, args) { return args[info.fieldName]; }
Cfunction defaultResolver(info) { return parent[info.fieldName]; }
Dfunction defaultResolver(parent, args, context) { return parent.fieldName; }
Attempts:
2 left
💡 Hint

The default resolver uses the info.fieldName to get the field name dynamically.

❓ optimization
advanced
2:00remaining
How can default resolvers impact performance in deeply nested queries?

When using default resolvers on a deeply nested GraphQL query, what is a common performance concern?

ADefault resolvers always cache results automatically, improving performance.
BDefault resolvers prevent any data fetching beyond the first level.
CDefault resolvers batch all nested field requests into a single database call by default.
DDefault resolvers may cause multiple redundant data fetches if not optimized.
Attempts:
2 left
💡 Hint

Think about how default resolvers access nested fields and data fetching.

🔧 Debug
expert
3:00remaining
Why does this GraphQL query return null for a nested field despite data existing?

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
    }
  }
}
AThe data object uses 'authorName' instead of nested 'author' object, so default resolver returns null.
BThe schema is missing a resolver for 'author', causing a runtime error.
CThe query syntax is invalid and causes the server to return null.
DThe 'name' field is not defined in the 'Author' type, so it returns null.
Attempts:
2 left
💡 Hint

Check how the data structure matches the schema fields.

Practice

(1/5)
1. What is the main purpose of default resolvers in GraphQL?
easy
A. To write custom logic for every field in the schema
B. To automatically return data by matching schema fields to data keys
C. To validate user input before querying the database
D. To handle errors during query execution

Solution

  1. Step 1: Understand default resolver behavior

    Default resolvers automatically map schema fields to matching data keys without extra code.
  2. Step 2: Compare with other options

    Options B, C, and D describe custom logic, validation, and error handling, which are not default resolver roles.
  3. Final Answer:

    To automatically return data by matching schema fields to data keys -> Option B
  4. Quick Check:

    Default resolver = automatic field-to-key mapping [OK]
Hint: Default resolvers match schema fields to data keys automatically [OK]
Common Mistakes:
  • Thinking default resolvers handle validation
  • Confusing default resolvers with custom resolvers
  • Assuming default resolvers manage errors
2. Which of the following is the correct way to define a GraphQL schema field that uses a default resolver?
easy
A. type Query { user: User() }
B. type Query { user: User @customResolver }
C. type Query { user: User }
D. type Query { user: User -> resolver }

Solution

  1. Step 1: Identify correct schema syntax

    GraphQL schema fields are defined as fieldName: Type without extra syntax for default resolvers.
  2. Step 2: Analyze options

    type Query { user: User } uses correct syntax. Options B, C, and D include invalid or non-standard syntax.
  3. Final Answer:

    type Query { user: User } -> Option C
  4. Quick Check:

    Default resolver needs simple field: Type syntax [OK]
Hint: Default resolvers need simple field: Type syntax in schema [OK]
Common Mistakes:
  • Adding parentheses after type name
  • Using custom directives without definition
  • Using arrow or other symbols in schema
3. Given the schema type Query { book: Book } and data { book: { title: "1984", author: "Orwell" } }, what will the default resolver return for the field book?
medium
A. { title: "1984", author: "Orwell" }
B. "1984"
C. null
D. Error: Resolver not found

Solution

  1. Step 1: Understand default resolver behavior

    The default resolver returns the data object matching the field name if it exists.
  2. Step 2: Match field to data

    The field book matches the data key book which contains the object with title and author.
  3. Final Answer:

    { title: "1984", author: "Orwell" } -> Option A
  4. Quick Check:

    Field book returns matching data object [OK]
Hint: Default resolver returns matching data object for field name [OK]
Common Mistakes:
  • Returning only one property instead of whole object
  • Expecting null if no custom resolver is defined
  • Assuming error if resolver is not explicitly written
4. You wrote a GraphQL schema with type Query { user: User } but your query returns null for user. What is a likely cause related to default resolvers?
medium
A. The data source does not have a matching key named 'user'
B. You forgot to write a custom resolver for 'user'
C. The schema syntax is invalid
D. GraphQL does not support default resolvers

Solution

  1. Step 1: Recall default resolver behavior

    Default resolvers return data matching the field name from the data source.
  2. Step 2: Identify cause of null result

    If the data source lacks a key named 'user', the default resolver returns null.
  3. Final Answer:

    The data source does not have a matching key named 'user' -> Option A
  4. Quick Check:

    Missing data key causes null from default resolver [OK]
Hint: Check data keys match schema fields for default resolver to work [OK]
Common Mistakes:
  • Assuming custom resolver is always required
  • Blaming schema syntax without checking data
  • Thinking default resolvers are unsupported
5. You have a schema type Query { product: Product } and data { product: { id: 1, name: "Pen", price: 2.5 } }. You want to return the price with a 10% discount but keep default resolvers for other fields. How should you implement this?
hard
A. Use default resolvers only; custom resolvers cannot be mixed
B. Write a custom resolver for the entire 'product' field in Query
C. Modify the data source to store discounted price
D. Write a custom resolver only for the 'price' field inside Product type

Solution

  1. Step 1: Understand resolver layering

    Default resolvers work per field; you can override specific fields with custom resolvers.
  2. Step 2: Apply custom resolver to 'price' only

    Write a custom resolver for 'price' to apply discount, leaving other fields to default resolvers.
  3. Step 3: Avoid overriding entire 'product' resolver

    Overriding entire 'product' would require manually returning all fields, losing default resolver benefits.
  4. Final Answer:

    Write a custom resolver only for the 'price' field inside Product type -> Option D
  5. Quick Check:

    Custom resolver per field + default resolvers for others [OK]
Hint: Override only needed fields with custom resolvers, keep defaults for rest [OK]
Common Mistakes:
  • Overriding entire parent field unnecessarily
  • Trying to mix default and custom resolvers at root level only
  • Modifying data source instead of resolver logic
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard