0
0
GraphQLquery~20 mins

Schema-first development in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Schema-first Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main advantage of schema-first development in GraphQL?

Consider you are building a GraphQL API. What is the primary benefit of defining the schema before writing any resolver code?

AIt forces the API to use REST endpoints internally.
BIt automatically generates database tables without any additional setup.
CIt eliminates the need for writing any resolver functions.
DIt allows frontend and backend teams to agree on data structure early, improving collaboration.
Attempts:
2 left
💡 Hint

Think about how defining the shape of data first helps teams work together.

query_result
intermediate
2:00remaining
What is the output of this GraphQL query given the schema?

Given the schema below, what will be the result of the query?

type Query {
  book(id: ID!): Book
}

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

Query:
{
  book(id: "1") {
    title
    author
  }
}
GraphQL
Assume the data source has a book with id "1", title "1984", and author "George Orwell".
A{ "data": { "book": { "title": "1984", "author": "George Orwell" } } }
B{ "data": { "book": { "id": "1", "title": "1984" } } }
C{ "data": { "book": null } }
D{ "errors": [ { "message": "Field 'author' not found" } ] }
Attempts:
2 left
💡 Hint

Look at the query fields and the schema's Book type.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this GraphQL schema definition

Which option contains the syntax error in the schema below?

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

type Query {
  user(id: ID!): User
}
GraphQL
Assume the schema is used in a GraphQL server.
AThere is no syntax error; the schema is valid.
BThe 'friends' field should be '[User]!' to indicate the list is non-null.
CThe 'friends' field should be '[User!]!' to indicate a non-null list of non-null Users.
DThe 'friends' field should be '[User!]' instead of '[User]'.
Attempts:
2 left
💡 Hint

Check the GraphQL list and nullability syntax rules.

optimization
advanced
2:00remaining
How to optimize resolver performance in schema-first GraphQL?

You notice your GraphQL API is slow because many resolvers fetch data separately. Which approach best improves performance?

ARemove the schema and write raw SQL queries instead.
BAdd more fields to the schema to reduce the number of queries.
CUse data loader pattern to batch and cache database requests in resolvers.
DUse REST endpoints inside resolvers to fetch data.
Attempts:
2 left
💡 Hint

Think about how to reduce repeated database calls in resolvers.

🔧 Debug
expert
3:00remaining
Why does this schema-first GraphQL server fail to start?

Given this schema snippet, the server throws an error on startup:

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

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

What is the most likely cause?

AThe schema has a circular reference with 'User' referencing itself, which is invalid.
BThere is no syntax error; the error is likely in resolver implementation.
CThe schema is missing a root mutation type, causing startup failure.
DThe 'bestFriend' field must be non-nullable with an exclamation mark.
Attempts:
2 left
💡 Hint

Think about whether self-referencing types are allowed in GraphQL schemas.