Reading GraphQL Schema
Types, nullable vs non-nullable fields, Query/Mutation/Subscription operations, and input types
GraphQL schema vocabulary
- Type! — non-nullable; server guarantees a value (never null)
- Query type — read operations; Mutation — write operations; Subscription — real-time events
- [Type!]! — non-nullable list of non-nullable items (always returns a list, even empty)
- Input type — argument object for mutations:
createUser(input: CreateUserInput!) - Resolver — the function that fetches the data for a field
Question 0 of 5
A GraphQL schema includes: type User { id: ID! name: String! email: String age: Int }. What does the ! symbol mean?
Non-nullable — the server guarantees a value, never null. GraphQL type system vocabulary:
String!— non-nullable String (always present)String— nullable String (may be null)[String!]!— non-nullable list of non-nullable StringsID!— non-nullable ID scalar (unique identifier)
name: String! → client can safely use user.name without null check; age: Int → client must handle null (user may not have provided their age). The ! is a contract between server and client.The schema defines: type Query { users(limit: Int, offset: Int): [User!]! user(id: ID!): User }. How would you describe these two query fields?
users returns a non-nullable list (with optional limit/offset); user returns a nullable single user by required ID. GraphQL Query type vocabulary:
- The Query type defines all read operations (equivalent to REST GET endpoints)
- Arguments in parentheses —
(limit: Int, offset: Int)— optional because no! [User!]!— the list itself is non-null (always returns a list, even if empty), each item in the list is non-nulluser(id: ID!): User—idis required; return is nullable (user might not exist → null instead of error)
The schema has: type Mutation { createUser(input: CreateUserInput!): User! deleteUser(id: ID!): Boolean! }. What does the Mutation type represent?
Write operations — Mutation is to GraphQL what POST/PUT/PATCH/DELETE are to REST. GraphQL Mutation vocabulary:
- Mutation type — defines all write operations (create, update, delete)
- Input types —
CreateUserInput!— a dedicated input object type (cleaner than many scalar arguments) - Return type — mutations typically return the created/updated object (
User!) or a success indicator (Boolean!)
createUser(input: CreateUserInput!): User! = "accepts a required input object, creates a user, returns the created user (never null)". deleteUser(id: ID!): Boolean! = "removes the user with the given ID, returns true on success".A schema includes: type Subscription { orderUpdated(orderId: ID!): Order! }. What does a Subscription represent in GraphQL?
Real-time event listener — the client receives live updates via WebSocket. GraphQL operation types:
- Query — one-time read (request/response)
- Mutation — one-time write (request/response)
- Subscription — long-lived connection; server pushes events to client (typically via WebSocket)
orderUpdated(orderId: ID!): Order!: "Subscribe to updates for a specific order; whenever that order changes, the server sends the updated Order object." Use cases: live order tracking, real-time notifications, collaborative editing. Implementation: requires a subscription-capable transport (WebSocket, SSE), not standard HTTP.What does this schema fragment mean? type Post { author: User! comments: [Comment!]! tags: [String!] }
Non-nullable author User, non-nullable Comment list, nullable tags list of non-null strings. Reading nested GraphQL types:
author: User!— object reference; every Post has a User (resolved via a separate resolver, not stored inline)comments: [Comment!]!— the list is always present (may be empty[]); each Comment in the list is non-nulltags: [String!]— the list itself may be null (field absent); but if present, each string is non-null
post.author.name is safe (both non-null); post.comments.forEach(...) is safe; post.tags?.forEach(...) needs a null check.