Complete Interview Questions & Answer Bank
50 curated interview questions ordered strictly by difficulty from Easy to Expert covering core concepts, schema design, performance, security, and federation.
Q1: What is GraphQL and what primary problem does it solve?
GraphQL is an open-source query language for APIs and a runtime for fulfilling those queries with existing data. Developed by Facebook in 2012 and open-sourced in 2015, it provides a complete and understandable description of the data in your API.
Primary problems solved:
- Over-fetching: Clients receive only the specific fields they request.
- Under-fetching: Multiple nested resources can be retrieved in a single request instead of round-tripping to multiple endpoints.
- Strong Typing: The API schema serves as a strict contract between client and server.
- Creator:
Facebook (Meta) - Initial Release:
2015
- GraphQL allows clients to request exactly what data they need.
- It eliminates over-fetching and under-fetching using a single endpoint.
Which issue is directly eliminated by GraphQL allowing field-level selection?
Q2: How does GraphQL differ from a traditional REST API?
In REST, endpoints represent resources (e.g., /users, /posts), and data structure is fixed by the server. GraphQL uses a single endpoint (typically /graphql) where clients post a structured query specifying the exact response shape.
Multiple resource URIsSingle endpointServer defines payloadClient defines payload- REST relies on multiple resource endpoints, while GraphQL operates over a single endpoint.
- GraphQL gives the client total control over response shape.
What is the typical network architecture for a standard GraphQL server?
Q3: What is the GraphQL Schema and SDL?
The GraphQL Schema defines the hierarchy of types, fields, inputs, and operations available on the server. Schema Definition Language (SDL) is the standard human-readable syntax used to write GraphQL schemas.
type User {
id: ID!
name: String!
email: String
}
- The Schema acts as a strongly-typed contract between frontend and backend.
- SDL is the language-agnostic syntax used to declare GraphQL types.
What does the exclamation mark `!` indicate in SDL (e.g., `id: ID!`)?
Q4: What are the three root operation types in GraphQL?
GraphQL supports three primary root operations:
- Query: Read-only fetches (analogous to HTTP GET).
- Mutation: Write operations that create, update, or delete data (analogous to POST/PUT/DELETE).
- Subscription: Event-driven real-time updates maintained over long-lived transport (e.g., WebSockets).
- Queries are read-only, Mutations perform writes, and Subscriptions stream real-time events.
Which root operation should be used to modify data in a database?
Q5: What are the built-in scalar types in GraphQL?
GraphQL includes five built-in primitive scalar types:
Int: Signed 32‐bit integer.Float: Signed double-precision fractional value.String: UTF‐8 character sequence.Boolean:trueorfalse.ID: Unique identifier serialized as a String, often used to re-fetch objects.
- GraphQL provides 5 scalar primitives: Int, Float, String, Boolean, and ID.
Which of the following is NOT a built-in GraphQL scalar type?
Q6: What is a GraphQL Resolver?
A resolver is a function that populates the data for a specific field in a GraphQL schema. Every field on every type in GraphQL is backed by a resolver function on the server.
const resolvers = {
Query: {
user: (parent, args, context, info) => {
return context.db.findUserById(args.id);
}
}
};- Resolvers bridge schema fields to actual data sources (DBs, REST APIs, microservices).
What role does a resolver fulfill in a GraphQL server?
Q7: What are the four standard arguments passed to a GraphQL resolver?
Standard GraphQL resolvers in JavaScript environments receive four positional arguments:
parent(orobj): The result returned from the resolver on the parent field.args: The parameters/arguments passed into the field in the GraphQL query.context: Shared contextual state across all resolvers in a request (e.g., auth user, DB instances).info: AST and execution information regarding the query state.
- Resolver arguments are
(parent, args, context, info). contextis the primary mechanism for sharing request-scoped objects like database connections.
Which resolver argument contains the current authenticated user object?
Q8: What are GraphQL Fragments and why are they used?
A fragment is a reusable unit of a GraphQL query. It allows developers to construct sets of fields and include them in multiple queries, preventing code duplication.
fragment UserFields on User {
id
name
email
}
query GetUser {
user(id: "1") {
...UserFields
}
}UserFields is reused using the spread syntax (...UserFields).- Fragments eliminate duplicate field selections across queries.
- They are vital for UI components that define their own data dependencies.
Which operator is used to apply a fragment inside a query?
Q9: What are GraphQL Aliases and when should you use them?
Aliases allow you to rename the result of a field in a query. They are essential when you need to query the exact same schema field multiple times with different arguments in a single request.
query GetTwoUsers {
admin: user(id: "1") {
name
}
guest: user(id: "2") {
name
}
}admin and guest differentiate the two user field calls in the JSON response.- Aliases prevent JSON property collision when querying a field multiple times in one operation.
Why are aliases mandatory when calling the same field twice with different arguments in one query?
Q10: Why should you use variables instead of inline string interpolation in queries?
GraphQL variables allow query values to be dynamic without constructing queries via string manipulation.
Benefits:
- Security: Prevents query injection attacks.
- Caching: Allows GraphQL servers/clients to compile and cache static query document structures.
- Readability: Keeps document text clean and re-executable.
- Variables separate query structure from parameter values.
- Using variables prevents query injection and enables client/server execution caching.
How are variable names prefixed in standard GraphQL query documents?