0
0
GraphQLquery~20 mins

Field selection in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Field Selection 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?

Given the following GraphQL schema snippet:

type Book {
  title: String
  author: Author
}

type Author {
  name: String
  age: Int
}

And the query:

{
  book {
    title
    author {
      name
    }
  }
}

What fields will be included in the response?

A{"data": {"book": {"title": "1984", "author": {"name": "George Orwell"}}}}
B{"data": {"book": {"title": "1984", "author": {"name": "George Orwell", "age": 46}}}}
C{"data": {"book": {"title": "1984"}}}
D{"data": {"book": {"author": {"name": "George Orwell"}}}}
Attempts:
2 left
💡 Hint

Look carefully at which fields are requested inside author.

📝 Syntax
intermediate
2:00remaining
Which GraphQL query has a syntax error?

Identify the query that will cause a syntax error when executed.

A{ book { title author name } }
B{ book { title author { name age } } }
C} } } eman { rohtua eltit { koob {
D{ book { title author { name } } }
Attempts:
2 left
💡 Hint

Remember that nested fields must be enclosed in braces.

optimization
advanced
2:00remaining
Which query is the most efficient to fetch only book titles?

You want to fetch only the titles of all books. Which query is best to minimize data transfer?

A{ books { title author { name } } }
B{ books { title author { name age } } }
C{ books { title author } }
D{ books { title } }
Attempts:
2 left
💡 Hint

Request only the fields you need.

🧠 Conceptual
advanced
2:00remaining
What happens if you omit a field in a GraphQL query?

Consider a GraphQL type User with fields id, name, and email. If you query only id and name, what will the server return for email?

AThe server returns the email field with its value.
BThe server returns null for the email field.
CThe server omits the email field entirely from the response.
DThe server returns an error because email was not requested.
Attempts:
2 left
💡 Hint

GraphQL only returns fields explicitly requested.

🔧 Debug
expert
3:00remaining
Why does this GraphQL query return an error?

Given the schema:

type Query {
  user(id: ID!): User
}

type User {
  id: ID
  name: String
  friends: [User]
}

And the query:

{
  user(id: "1") {
    id
    name
    friends {
      id
      name
      friends {
        id
      }
    }
  }
}

The server returns an error about exceeding query depth. Why?

AThe query is missing required arguments for friends field.
BThe query requests nested friends fields recursively, causing too deep nesting.
CThe query uses invalid field names for User type.
DThe query syntax is incorrect due to missing braces.
Attempts:
2 left
💡 Hint

Think about how deep the query goes into nested fields.