Bird
Raised Fist0
GraphQLquery~20 mins

Field-level errors in GraphQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Field-level Error Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Identify the field-level error in this GraphQL query response

Given this GraphQL query response, which field contains an error?

{
  "data": {
    "user": {
      "id": "123",
      "email": null,
      "name": "Alice"
    }
  },
  "errors": [
    {
      "message": "Email not found",
      "path": ["user", "email"]
    }
  ]
}
AThere are no field-level errors in this response
BThe 'id' field has an error because it is missing
CThe 'email' field has an error because it is null and reported in errors
DThe 'name' field has an error because it is a string
Attempts:
2 left
💡 Hint

Look at the 'errors' array and see which field path it points to.

🧠 Conceptual
intermediate
1:30remaining
Understanding field-level errors in GraphQL

What does a field-level error in a GraphQL response mean?

AOnly a specific field failed, but other data is returned successfully
BThe client sent an invalid authentication token
CThe server did not understand the query syntax
DThe entire query failed and no data is returned
Attempts:
2 left
💡 Hint

Field-level errors allow partial data with some fields failing.

📝 Syntax
advanced
2:00remaining
Which GraphQL error response is correctly formatted for a field-level error?

Choose the valid GraphQL error response that shows a field-level error for the 'price' field.

A{ "data": { "product": { "price": 100 } }, "errors": [{ "message": "Price error" }] }
B{ "data": { "product": { "price": null } }, "errors": [{ "message": "Price not available", "path": ["product", "price"] }] }
C{ "data": null, "errors": [{ "message": "Price not available" }] }
D{ "error": "Price field missing" }
Attempts:
2 left
💡 Hint

Field-level errors include a 'path' to the field and partial data.

🔧 Debug
advanced
2:30remaining
Find the mistake causing the field-level error in this GraphQL schema snippet

Given this GraphQL schema snippet, why might the 'email' field cause a field-level error?

type User {
  id: ID!
  name: String!
  email: String
}

query {
  user(id: "1") {
    id
    name
    email
  }
}
AThe 'email' field is non-nullable but the resolver returns null
BThe 'id' field is not defined in the schema
CThe 'name' field is missing in the query causing the error
DThe 'email' field is nullable but the resolver returns null without error handling
Attempts:
2 left
💡 Hint

Nullable fields can return null but may cause errors if not handled properly.

❓ optimization
expert
3:00remaining
How to minimize field-level errors in a complex GraphQL query?

You have a complex GraphQL query fetching multiple nested fields. Which approach best reduces field-level errors?

AImplement detailed error handling in each resolver to return partial data and clear error messages
BRemove all nullable fields from the schema to avoid nulls in responses
CUse error masking to hide all errors and always return null for failed fields
DDisable error reporting in the GraphQL server to prevent errors from reaching clients
Attempts:
2 left
💡 Hint

Good error handling helps clients understand and handle partial failures.

Practice

(1/5)
1. What is the main purpose of field-level errors in GraphQL queries?
easy
A. To show exactly which field in the query caused an error
B. To speed up the query execution time
C. To encrypt the query data for security
D. To automatically fix errors in the query

Solution

  1. Step 1: Understand what field-level errors represent

    Field-level errors identify the specific part of a query that failed, not the whole query.
  2. Step 2: Recognize the benefit of field-level errors

    This helps apps show clear messages next to the exact problem fields, improving user experience.
  3. Final Answer:

    To show exactly which field in the query caused an error -> Option A
  4. Quick Check:

    Field-level errors = pinpoint error location [OK]
Hint: Field-level errors pinpoint the exact failing field [OK]
Common Mistakes:
  • Thinking errors speed up queries
  • Believing errors fix themselves
  • Confusing errors with encryption
2. Which of the following is the correct way to represent a field-level error path in a GraphQL error response?
easy
A. "location": ["user", "email"]
B. "path": "user.email"
C. "error": "user.email"
D. "path": ["user", "email"]

Solution

  1. Step 1: Identify the standard format for error paths

    GraphQL error paths are arrays showing the nested fields causing the error, e.g., ["user", "email"].
  2. Step 2: Compare options to the standard format

    "path": ["user", "email"] matches the array format; others use strings or wrong keys.
  3. Final Answer:

    "path": ["user", "email"] -> Option D
  4. Quick Check:

    Error path = array of field names [OK]
Hint: Error paths use arrays, not dot strings [OK]
Common Mistakes:
  • Using dot notation strings for paths
  • Confusing 'error' with 'path' key
  • Using 'location' instead of 'path'
3. Given this GraphQL error response snippet:
{"errors": [{"message": "Cannot query field 'age' on type 'User'", "path": ["user", "age"]}]}

What does the path ["user", "age"] indicate?
medium
A. The error is in the 'age' field inside the 'user' object
B. The entire 'user' object is missing
C. The query has a syntax error at the root
D. The 'age' field is null but valid

Solution

  1. Step 1: Analyze the error message and path

    The message says 'Cannot query field age on type User', and the path shows the nested location: user -> age.
  2. Step 2: Interpret the meaning of the path

    This means the error is specifically with the 'age' field inside the 'user' object, not the whole user or root.
  3. Final Answer:

    The error is in the 'age' field inside the 'user' object -> Option A
  4. Quick Check:

    Path shows exact field with error [OK]
Hint: Error path shows nested field causing issue [OK]
Common Mistakes:
  • Assuming whole object is missing
  • Confusing syntax errors with field errors
  • Thinking null fields cause this error
4. You receive this GraphQL error response:
{"errors": [{"message": "Field 'price' must be a positive number", "path": ["product", "price"]}]}

Which fix will correctly address the field-level error?
medium
A. Ignore the error and retry the query
B. Change the 'price' value to a positive number in the query variables
C. Rename 'price' to 'cost' in the query
D. Remove the 'price' field from the query entirely

Solution

  1. Step 1: Understand the error message and path

    The error says 'price' must be positive, and the path points to product -> price field.
  2. Step 2: Determine the correct fix

    Fixing means providing a positive number for 'price' in the query variables, not removing or renaming the field.
  3. Final Answer:

    Change the 'price' value to a positive number in the query variables -> Option B
  4. Quick Check:

    Fix value to meet field rules [OK]
Hint: Fix field value to meet error message rules [OK]
Common Mistakes:
  • Removing required fields
  • Renaming fields without schema support
  • Ignoring errors expecting auto-fix
5. You have a GraphQL query requesting nested fields:
{ user { name, posts { title, comments { text, author } } } }

If the error response shows:
{"errors": [{"message": "Cannot query field 'author' on type 'Comment'", "path": ["user", "posts", 0, "comments", 2, "author"]}]}

What does this error tell you about the query and how should you fix it?
hard
A. The 'comments' array is empty; add comments to fix the error
B. The 'posts' field is missing; add it to the query
C. The 'author' field does not exist on 'Comment'; remove or correct it in the query
D. The 'user' field is invalid; rename it to 'member'

Solution

  1. Step 1: Analyze the error message and path

    The error says 'author' is not a valid field on 'Comment'. The path shows it is nested inside user -> posts -> comments at index 2.
  2. Step 2: Decide the fix based on schema rules

    Since 'author' is invalid, you should remove or correct this field in the query to match the schema.
  3. Final Answer:

    The 'author' field does not exist on 'Comment'; remove or correct it in the query -> Option C
  4. Quick Check:

    Field error means fix or remove invalid field [OK]
Hint: Invalid field in nested path means fix query field name [OK]
Common Mistakes:
  • Assuming empty arrays cause this error
  • Adding missing fields not in schema
  • Renaming unrelated fields
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