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?
Remember that nested objects in GraphQL return objects, not just strings.
The query requests the book's title and the nested author's name. The response must reflect the nested structure with an object for author.
Which option contains a syntax error in defining a GraphQL object type?
type User {
id: ID!
name: String!
age: Int
}Check the colon between field name and type.
Option A is missing the colon between age and Int, which is required syntax in GraphQL type definitions.
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?
Only request the fields you need to reduce data size.
Option C requests only name and title fields, minimizing data transfer.
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?
Check if all requested fields exist in the schema.
The schema defines price but the query requests cost, which is not a valid field.
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?
Think about how GraphQL responses mirror the query shape.
GraphQL executes resolvers for nested fields and returns nested JSON objects that match the query's nested structure.