Given this GraphQL schema:
type Book {
id: ID!
title: String!
author: Author!
}
type Author {
id: ID!
name: String!
books: [Book!]!
}
type Query {
book(id: ID!): Book
}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 output?
Remember the query asks for both title and author.name.
The query requests the book's title and the author's name. Option A correctly includes both fields in the response.
In GraphQL schema definition, how do you define a field that is a list which cannot be null, but can contain null strings?
Think about the placement of the exclamation mark ! and what it means for the list and its items.
[String]! means the list itself cannot be null, but its items can be null. Other options either make items non-null or the list nullable.
What is wrong with this GraphQL type definition?
type User {
id: ID!
name: String
email: String!
friends: [User]
age: Int!
}Check if all fields follow GraphQL type syntax rules.
All fields are correctly defined. Lists and non-null types are valid as shown. Non-null fields do not require default values in schema.
You have a schema with types Post and Comment. Each post has many comments. Which schema design helps avoid the N+1 query problem when fetching posts with comments?
Think about how to reduce multiple database calls when resolving nested fields.
Using a batch loader or data loader batches requests to fetch comments for many posts in one query, avoiding the N+1 problem.
Consider this schema snippet:
type Employee {
id: ID!
name: String!
manager: Employee
subordinates: [Employee!]
}When trying to generate schema documentation, a circular reference error occurs. Why?
Think about how recursive types can cause infinite loops in tools processing the schema.
The schema itself is valid, but tools generating documentation or introspection may fail without limits on recursion depth, causing circular reference errors.