A schema in GraphQL defines the types of data you can query or mutate. It acts like a blueprint for what data is available and how clients can ask for it.
Click to reveal answer
beginner
What does the type Query represent in a GraphQL schema?
The type Query defines the entry points for reading or fetching data. It lists all the queries clients can make to get data from the server.
Click to reveal answer
intermediate
Explain the role of type Mutation in a GraphQL schema.
type Mutation defines the operations that change data, like creating, updating, or deleting. It tells clients how they can modify data on the server.
Click to reveal answer
beginner
What is the purpose of scalar types in GraphQL schema?
Scalar types represent the basic data types like Int, String, Boolean, Float, and ID. They are the building blocks for defining fields.
Click to reveal answer
beginner
How do you define a custom object type in a GraphQL schema?
You define a custom object type using the type keyword followed by the name and its fields with their types. For example: type Book { id: ID! title: String! author: String }
Click to reveal answer
What keyword starts the definition of a GraphQL schema's query type?
Atype Query
Bschema Query
Cquery Type
Ddefine Query
✗ Incorrect
The query type is defined using the keyword type Query in GraphQL schema.
Which GraphQL type is used to represent a unique identifier?
AString
BID
CInt
DBoolean
✗ Incorrect
The ID scalar type is used to represent unique identifiers in GraphQL.
What does the exclamation mark (!) mean in a GraphQL type definition like String!?
AList of strings
BNullable field
COptional field
DNon-nullable field
✗ Incorrect
The exclamation mark means the field is non-nullable, so it must always have a value.
Which part of the schema defines how to change data?
Atype Mutation
Btype Query
Ctype Subscription
Dtype Change
✗ Incorrect
type Mutation defines operations that modify data in GraphQL.
How do you define a list of strings in GraphQL schema?
AString[]
BList<String>
C[String]
DArray<String>
✗ Incorrect
Lists are defined using square brackets, like [String] in GraphQL.
Describe the main components of a GraphQL schema and their roles.
Think about how clients ask for data and how they change data.
You got /4 concepts.
Explain how you would define a new object type with fields in a GraphQL schema.
Imagine describing a real-world object like a book or user.
You got /4 concepts.
Practice
(1/5)
1. What is the purpose of the schema block in a GraphQL schema definition?
easy
A. It specifies the database connection details.
B. It defines the main entry points like query and mutation types.
C. It creates new object types with fields.
D. It lists all the scalar types available.
Solution
Step 1: Understand the role of the schema block
The schema block in GraphQL defines the entry points for the API, such as which types are used for queries and mutations.
Step 2: Differentiate from other schema parts
Object types with fields are defined using type, not the schema block. Database connections and scalar types are not defined here.
Final Answer:
It defines the main entry points like query and mutation types. -> Option B
Hint: Remember schema block sets query and mutation roots [OK]
Common Mistakes:
Confusing schema block with type definitions
Thinking schema block defines database details
Assuming schema block lists scalar types
2. Which of the following is the correct syntax to define a simple object type Book with a title field of type String in GraphQL?
easy
A. schema Book { title: String }
B. object Book { title: String }
C. type Book { title: String }
D. define Book { title: String }
Solution
Step 1: Recall GraphQL syntax for object types
GraphQL uses the keyword type to define object types, followed by the type name and fields inside curly braces.
Step 2: Check each option
Only type Book { title: String } uses the correct keyword type and proper syntax. Others use invalid keywords like object, schema, or define.
Final Answer:
type Book { title: String } -> Option C
Quick Check:
Object type syntax = type + name + fields [OK]
Hint: Use 'type' keyword to define objects in GraphQL [OK]
Common Mistakes:
Using 'object' or 'define' instead of 'type'
Confusing schema block with type definition
Missing curly braces around fields
3. Given the schema definition:
type Query {
book: Book
}
type Book {
title: String
pages: Int
}
What fields can be queried under book?
medium
A. Only title
B. No fields, book is scalar
C. Only pages
D. title and pages
Solution
Step 1: Identify the type of book field in Query
The book field in Query returns a Book object type.
Step 2: Check fields inside Book type
The Book type has two fields: title (String) and pages (Int), so both can be queried.
Final Answer:
title and pages -> Option D
Quick Check:
Object fields = title + pages [OK]
Hint: Object fields are all listed inside its type definition [OK]
Common Mistakes:
Assuming only one field is accessible
Thinking book is a scalar, not an object
Ignoring fields inside the Book type
4. Identify the error in this GraphQL schema snippet:
schema {
query: Query
}
type Query {
book: Book
}
type Book {
title String
}
medium
A. Missing colon ':' after 'title' field name
B. Missing curly braces around Query type
C. Schema block should be named 'type Schema'
D. Book type cannot be used in Query
Solution
Step 1: Check field syntax in Book type
The field title String is missing a colon ':' between the field name and type. It should be title: String.
Step 2: Verify other parts of the schema
The schema block and Query type are correctly defined with proper braces and names.
Final Answer:
Missing colon ':' after 'title' field name -> Option A
Quick Check:
Field syntax requires colon ':' [OK]
Hint: Always put ':' between field name and type [OK]
Common Mistakes:
Omitting colon ':' after field names
Confusing schema block syntax
Misnaming schema block as a type
5. You want to add a mutation to create a new Book with fields title (String) and pages (Int). Which schema definition correctly adds this mutation?
hard
A. type Mutation { createBook(title: String, pages: Int): Book } schema { mutation: Mutation }
B. schema { mutation: Mutation } type Mutation { createBook(title String, pages Int): Book }
C. type Mutation { createBook(title: String, pages: Int): Book } schema { query: Query }
D. type Mutation { createBook(title: String, pages: Int): Book }
Solution
Step 1: Define the Mutation type with correct field syntax
The mutation field createBook must have arguments with colons, e.g., title: String, and return type Book. schema { mutation: Mutation } type Mutation { createBook(title String, pages Int): Book } has missing colons, so it's invalid.
Step 2: Link the Mutation type in the schema block
The schema block must include mutation: Mutation to expose the mutation. type Mutation { createBook(title: String, pages: Int): Book } schema { mutation: Mutation } correctly includes this after defining Mutation.
Final Answer:
type Mutation { createBook(title: String, pages: Int): Book } schema { mutation: Mutation } -> Option A
Quick Check:
Mutation type + schema mutation entry = correct [OK]
Hint: Mutation must be linked in schema block with correct syntax [OK]
Common Mistakes:
Omitting colons in argument definitions
Not linking mutation type in schema block
Only defining mutation type without schema entry
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.