0
0
GraphQLquery~20 mins

Object types in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GraphQL Object Types 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:

type Book {
  id: ID!
  title: String!
  author: Author!
}

type Author {
  id: ID!
  name: String!
}

And this query:

{
  book(id: "1") {
    title
    author {
      name
    }
  }
}

Assuming the data has a book with id "1" titled "GraphQL Basics" by author "Alice".

What is the expected JSON response?

A{"data": {"book": {"title": "GraphQL Basics", "author": {"name": "Alice"}}}}
B{"data": {"book": {"title": "GraphQL Basics", "author": "Alice"}}}
C{"data": {"book": {"title": "GraphQL Basics"}}}
D{"errors": [{"message": "Field 'author' not found"}]}
Attempts:
2 left
💡 Hint

Remember that nested objects in GraphQL return objects, not just strings.

📝 Syntax
intermediate
1:30remaining
Identify the syntax error in this GraphQL object type definition

Which option contains a syntax error in defining a GraphQL object type?

type User {
  id: ID!
  name: String!
  age: Int
}
A
type User {
  id: ID!
  name: String!
  age Int
}
B
type User {
  id: ID!
  name: String!
  age: Int!
}
C
type User {
  id: ID!
  name: String!
  age: Int
}
D
type User {
  id: ID!
  name: String!
  age: Int
  }
Attempts:
2 left
💡 Hint

Check the colon between field name and type.

optimization
advanced
2:00remaining
Optimize this GraphQL query to reduce data transfer

Given this query fetching user data:

{
  users {
    id
    name
    email
    posts {
      id
      title
      content
    }
  }
}

You only need the user's name and the titles of their posts. Which query is the best optimized version?

A{ users { name posts { title content } } }
B{ users { id name posts { id title content } } }
C{ users { name posts { title } } }
D{ users { name posts { title } email } }
Attempts:
2 left
💡 Hint

Only request the fields you need to reduce data size.

🔧 Debug
advanced
2:00remaining
Why does this GraphQL query return an error?

Given the schema:

type Product {
  id: ID!
  name: String!
  price: Float!
}

And this query:

{
  product(id: "5") {
    id
    name
    cost
  }
}

What is the cause of the error?

AThe query is missing a root query type.
BThe field 'cost' does not exist on type 'Product'.
CThe 'price' field is required but missing in the query.
DThe 'id' argument is missing in the query.
Attempts:
2 left
💡 Hint

Check if all requested fields exist in the schema.

🧠 Conceptual
expert
2:30remaining
How does GraphQL handle nested object types in queries?

Consider a GraphQL schema with nested object types, such as a Post type containing an Author object. When querying nested fields, what does GraphQL do?

AGraphQL flattens all nested objects into a single-level JSON object with dot-separated keys.
BGraphQL ignores nested objects and returns null for those fields unless explicitly joined in the schema.
CGraphQL returns only the IDs of nested objects, requiring separate queries to fetch details.
DGraphQL resolves each nested object field by calling the corresponding resolver and returns nested JSON objects matching the query structure.
Attempts:
2 left
💡 Hint

Think about how GraphQL responses mirror the query shape.