A type definition in GraphQL describes the shape of data by defining fields and their data types. It tells the server what kind of data clients can query or mutate.
Click to reveal answer
beginner
What does the type keyword do in GraphQL?
The type keyword defines a new object type with a set of fields and their types. For example, type User { id: ID!, name: String } defines a User type with id and name fields.
Click to reveal answer
intermediate
Explain the difference between type and input in GraphQL type definitions.
type defines the shape of data returned by queries or mutations, while input defines the shape of data sent as arguments to mutations or queries.
Click to reveal answer
beginner
What does the exclamation mark ! mean in a GraphQL type definition?
The exclamation mark ! means the field is non-nullable, so it must always have a value and cannot be null.
Click to reveal answer
beginner
How do you define a list of strings in a GraphQL type definition?
You define a list of strings using square brackets: [String]. For example, tags: [String] means the tags field is a list of strings.
Click to reveal answer
Which keyword is used to define a new object type in GraphQL?
Atype
Binput
Cschema
Dquery
✗ Incorrect
The type keyword defines a new object type with fields.
What does String! mean in a GraphQL type definition?
AA non-nullable string
BAn optional string
CA list of strings
DA nullable string
✗ Incorrect
The exclamation mark ! means the string cannot be null.
Which type is used to define input data for mutations?
Atype
Binput
Cenum
Dscalar
✗ Incorrect
input types define the shape of data sent as arguments.
How do you define a list of integers in GraphQL?
Alist<Int>
BInt[]
C[Int]
Darray<Int>
✗ Incorrect
Lists are defined with square brackets, e.g., [Int].
What does this GraphQL type definition mean? type Book { title: String, pages: Int! }
ABoth title and pages are optional
Btitle is required, pages is optional
CBoth title and pages are required
Dtitle is optional, pages is required
✗ Incorrect
Without !, fields are nullable (optional). pages: Int! means pages is required.
Describe what a GraphQL type definition is and why it is important.
Think about how you tell a friend what information you want from them.
You got /4 concepts.
Explain the difference between type and input in GraphQL.
One is for output, the other for input.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of type definitions in GraphQL?
easy
A. To describe the shape and types of data clients can request
B. To execute database queries directly
C. To style the user interface of a GraphQL client
D. To store data permanently in the server
Solution
Step 1: Understand the role of type definitions
Type definitions specify what data types exist and how data is structured in GraphQL.
Step 2: Identify what clients use type definitions for
Clients use type definitions to know what data they can ask for and how it will look.
Final Answer:
To describe the shape and types of data clients can request -> Option A
Quick Check:
Type definitions = Describe data shape [OK]
Hint: Type definitions describe data structure, not execution or styling [OK]
Common Mistakes:
Confusing type definitions with query execution
Thinking type definitions style UI
Assuming type definitions store data
2. Which of the following is the correct way to define a simple GraphQL object type named Book with a title field of type String?
easy
A. define Book { title: String }
B. object Book { title: String }
C. Book type { title: String }
D. type Book { title: String }
Solution
Step 1: Recall GraphQL syntax for object types
GraphQL uses the keyword type followed by the type name and fields in braces.
Step 2: Match the correct syntax
type Book { title: String } matches the correct syntax: type Book { title: String }.
Final Answer:
type Book { title: String } -> Option D
Quick Check:
Object type syntax = type Name { fields } [OK]
Hint: Remember: 'type' keyword defines object types in GraphQL [OK]
Common Mistakes:
Using 'object' instead of 'type'
Placing 'type' after the name
Using 'define' keyword which is invalid
3. Given the following GraphQL type definition:
type User {
id: ID!
name: String
age: Int
}
Which of these queries will return the name and age fields of a user?
medium
A. { user { id name age } }
B. { user { name age } }
C. { user { id } }
D. { user { age id } }
Solution
Step 1: Identify requested fields in each query
We want only name and age fields returned.
Step 2: Check which query requests exactly those fields
{ user { name age } } requests name and age only, matching the requirement.
Final Answer:
{ user { name age } } -> Option B
Quick Check:
Query fields = name and age only [OK]
Hint: Select only needed fields inside braces after type name [OK]
Common Mistakes:
Including extra fields like 'id' when not asked
Requesting fields in wrong order (order doesn't matter but distracts)
Missing required fields if needed
4. Identify the error in this GraphQL type definition:
type Product {
id: ID
price: Float!
name: String!
description: String
price: Int
}
medium
A. Missing exclamation mark on 'id' field
B. Incorrect type 'Float!' for price
C. Duplicate field name 'price' with different types
D. Description field cannot be optional
Solution
Step 1: Review all fields for correctness
Notice that 'price' is declared twice with different types: Float! and Int.
Step 2: Understand GraphQL rules on field names
Field names must be unique within a type; duplicates cause errors.
Final Answer:
Duplicate field name 'price' with different types -> Option C
Quick Check:
Duplicate fields cause errors [OK]
Hint: Check for repeated field names in type definitions [OK]
Common Mistakes:
Ignoring duplicate field names
Thinking missing '!' is always an error
Assuming optional fields are invalid
5. You want to define a GraphQL type Order that includes an id (non-null ID), a list of items (each an Item type), and a total price (non-null Float). Which is the correct type definition?
hard
A. type Order { id: ID! items: [Item!]! total: Float! }
B. type Order { id: ID items: Item total: Float }
C. type Order { id: ID! items: [Item]! total: Float! }
D. type Order { id: ID! items: [Item!] total: Float }
Solution
Step 1: Analyze each field requirement
'id' must be non-null ID, 'items' is a non-null list of non-null Item, 'total' is non-null Float.
Step 2: Match the correct syntax
type Order { id: ID! items: [Item!]! total: Float! } correctly uses ID!, [Item!]! (list non-null and items non-null), and Float!.
Final Answer:
type Order { id: ID! items: [Item!]! total: Float! } -> Option A
Quick Check:
Non-null fields and list syntax correct [OK]
Hint: Use [Type!]! for non-null list of non-null items [OK]
Common Mistakes:
Missing non-null markers (!)
Using list without non-null item type
Confusing list syntax with single type
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.