0
0
GraphQLquery~20 mins

Type definitions in GraphQL - Practice Problems & Coding Challenges

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

type Book {
  title: String!
  author: String!
  pages: Int
}

type Query {
  book: Book
}

And this query:

{
  book {
    title
    pages
  }
}

Assuming the resolver returns { title: "1984", author: "Orwell", pages: 328 }, what is the query result?

A{"data":{"book":{"title":"1984","pages":328}}}
B{"data":{"book":{"title":"1984","author":"Orwell"}}}
C{"data":{"book":{"title":"1984"}}}
D{"data":{"book":{"pages":328}}}
Attempts:
2 left
💡 Hint

Only requested fields appear in the result.

🧠 Conceptual
intermediate
1:30remaining
Which GraphQL type definition correctly defines a nullable field?

In GraphQL, how do you define a field that can be null?

Atype User { name: String!! }
Btype User { name: String }
Ctype User { name: String! }
Dtype User { name: !String }
Attempts:
2 left
💡 Hint

Nullable fields do not have an exclamation mark.

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

Which option contains a syntax error in the GraphQL type definition?

type Product {
  id: ID!
  name: String!
  price: Float
  tags: [String!]
}
Atype Product { id: ID! name String! price: Float tags: [String!] }
Btype Product { id: ID! name: String! price: Float tags: [String!]! }
C} !]!gnirtS[ :sgat taolF :ecirp !gnirtS :eman !DI :di { tcudorP epyt
Dype Product { id: ID! name: String! price: Float tags: [String!]! }
Attempts:
2 left
💡 Hint

Check for missing colons, commas, or invalid brackets.

🔧 Debug
advanced
2:30remaining
Why does this GraphQL schema cause an error?

Consider this schema snippet:

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

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

Why might this schema cause an error in some GraphQL servers?

ABecause 'Query' type cannot have arguments.
BBecause 'User' type is missing a required field.
CBecause 'id' field should not be non-nullable.
DBecause the 'friend' field creates a circular reference without a resolver.
Attempts:
2 left
💡 Hint

Think about recursive types and resolvers.

optimization
expert
3:00remaining
How to optimize GraphQL type definitions for large lists?

You have a GraphQL type with a field returning a large list of items:

type Query {
  allPosts: [Post!]!
}

What is the best way to optimize this type definition for performance and usability?

AKeep the list as is but add a non-null assertion to the list items.
BChange the field to return a single Post instead of a list.
CChange the field to use pagination arguments and return a paginated type instead of a large list.
DRemove the non-null assertion from the list and items to allow nulls.
Attempts:
2 left
💡 Hint

Think about how to handle large data sets efficiently.