HomeBytesheetsRoadmapsUI TemplatesUI ToolsStack Discussion
50 Topics
Chapter•120 Minutes

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?

Difficulty:EasyTopic:Basics

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.
Specifications & Requirements
  • Creator:Facebook (Meta)
  • Initial Release:2015
Key Takeaways
  • GraphQL allows clients to request exactly what data they need.
  • It eliminates over-fetching and under-fetching using a single endpoint.
Knowledge Check

Which issue is directly eliminated by GraphQL allowing field-level selection?

Q2: How does GraphQL differ from a traditional REST API?

Difficulty:EasyTopic:Architecture

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.

REST vs GraphQL Comparison
Endpoints: Multiple resource URIs
REST requires multiple network calls for relational data.
GraphQL Endpoints: Single endpoint
GraphQL executes complex declarative queries at one endpoint.
Data Fetching: Server defines payload
REST payload structure is static.
GraphQL Data Fetching: Client defines payload
GraphQL response reflects requested schema fields.
Key Takeaways
  • REST relies on multiple resource endpoints, while GraphQL operates over a single endpoint.
  • GraphQL gives the client total control over response shape.
Knowledge Check

What is the typical network architecture for a standard GraphQL server?

Q3: What is the GraphQL Schema and SDL?

Difficulty:EasyTopic:Schema

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
}
Key Takeaways
  • The Schema acts as a strongly-typed contract between frontend and backend.
  • SDL is the language-agnostic syntax used to declare GraphQL types.
Knowledge Check

What does the exclamation mark `!` indicate in SDL (e.g., `id: ID!`)?

Q4: What are the three root operation types in GraphQL?

Difficulty:EasyTopic:Operations

GraphQL supports three primary root operations:

  1. Query: Read-only fetches (analogous to HTTP GET).
  2. Mutation: Write operations that create, update, or delete data (analogous to POST/PUT/DELETE).
  3. Subscription: Event-driven real-time updates maintained over long-lived transport (e.g., WebSockets).
Key Takeaways
  • Queries are read-only, Mutations perform writes, and Subscriptions stream real-time events.
Knowledge Check

Which root operation should be used to modify data in a database?

Q5: What are the built-in scalar types in GraphQL?

Difficulty:EasyTopic:Types

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: true or false.
  • ID: Unique identifier serialized as a String, often used to re-fetch objects.
Key Takeaways
  • GraphQL provides 5 scalar primitives: Int, Float, String, Boolean, and ID.
Knowledge Check

Which of the following is NOT a built-in GraphQL scalar type?

Q6: What is a GraphQL Resolver?

Difficulty:EasyTopic:Execution

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.

Basic JavaScript Resolver
const resolvers = {
  Query: {
    user: (parent, args, context, info) => {
      return context.db.findUserById(args.id);
    }
  }
};
💡 Resolvers receive four positional arguments: parent, args, context, and info.
Key Takeaways
  • Resolvers bridge schema fields to actual data sources (DBs, REST APIs, microservices).
Knowledge Check

What role does a resolver fulfill in a GraphQL server?

Q7: What are the four standard arguments passed to a GraphQL resolver?

Difficulty:EasyTopic:Execution

Standard GraphQL resolvers in JavaScript environments receive four positional arguments:

  1. parent (or obj): The result returned from the resolver on the parent field.
  2. args: The parameters/arguments passed into the field in the GraphQL query.
  3. context: Shared contextual state across all resolvers in a request (e.g., auth user, DB instances).
  4. info: AST and execution information regarding the query state.
Key Takeaways
  • Resolver arguments are (parent, args, context, info).
  • context is the primary mechanism for sharing request-scoped objects like database connections.
Knowledge Check

Which resolver argument contains the current authenticated user object?

Q8: What are GraphQL Fragments and why are they used?

Difficulty:EasyTopic:Query Constructs

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.

GraphQL Fragment Example
fragment UserFields on User {
  id
  name
  email
}

query GetUser {
  user(id: "1") {
    ...UserFields
  }
}
💡 The fragment UserFields is reused using the spread syntax (...UserFields).
Key Takeaways
  • Fragments eliminate duplicate field selections across queries.
  • They are vital for UI components that define their own data dependencies.
Knowledge Check

Which operator is used to apply a fragment inside a query?

Q9: What are GraphQL Aliases and when should you use them?

Difficulty:EasyTopic:Query Constructs

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.

Querying with Aliases
query GetTwoUsers {
  admin: user(id: "1") {
    name
  }
  guest: user(id: "2") {
    name
  }
}
💡 The aliases admin and guest differentiate the two user field calls in the JSON response.
Key Takeaways
  • Aliases prevent JSON property collision when querying a field multiple times in one operation.
Knowledge Check

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?

Difficulty:EasyTopic:Security & Syntax

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.
Key Takeaways
  • Variables separate query structure from parameter values.
  • Using variables prevents query injection and enables client/server execution caching.
Knowledge Check

How are variable names prefixed in standard GraphQL query documents?