MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
GraphQL Fundamentals and Apollo Client Setup0%
Study Materials
React.js for AdvancedProgress 0%
1.1Control Props and Inversion of Control Pattern1.2State Reducer Pattern in Advanced React1.3Prop Getters and Flexible Design Systems1.4Headless UI Architecture and Accessibility Primitives
13.1GraphQL Fundamentals and Apollo Client Setup13.2Executing GraphQL Queries with useQuery13.3GraphQL Mutations and Optimistic UI Updates13.4Real-Time GraphQL Subscriptions with WebSockets
HomeTutorialsReact.js for AdvancedGraphQL Fundamentals and Apollo Client Setup
Executing GraphQL Queries with useQuery

GraphQL Fundamentals and Apollo Client Setup

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

REST APIs often suffer from two enterprise scale challenges: over-fetching (retrieving hundreds of unused object fields) and under-fetching (requiring multiple waterfall HTTP requests to assemble related relational data). GraphQL solves this by providing a declarative query language where the client specifies the exact shape of data required. Apollo Client is the premier state management and caching client for GraphQL in React.


1. Core GraphQL Concepts

  • Schema & Types: The strongly-typed contract defined on the server (type User { id: ID!, name: String!, email: String! }).
  • Queries: Read operations fetching specific fields:
1 query GetUserData {
2 user(id: "123") {
3 name
4 email
5 }
6 }
  • Mutations: Write operations creating, updating, or deleting data.
  • Subscriptions: Persistent real-time event streams over WebSockets.

2. Apollo Client Architecture & Normalized Cache

Unlike standard HTTP caches that store responses by raw URL endpoint string, Apollo Client's Normalized In-Memory Cache (InMemoryCache):

  1. 1
    Deconstructs incoming GraphQL JSON responses into individual records.
  2. 2
    Generates a unique key for each entity (by default: __typename:id, e.g. User:123).
  3. 3
    Normalizes and stores each entity in a flat key-value dictionary.
  4. 4
    If two queries request different fields of User:123, Apollo automatically merges them into a single coherent entity in memory!
1Incoming Query Response:
2{ user: { __typename: "User", id: "123", name: "Alice" } }
3 
4Normalized Cache Store:
5"User:123" ──► { __typename: "User", id: "123", name: "Alice" }

3. Configuring Apollo Client with Authentication Headers

1npm install @apollo/client graphql

4. Wrapping the Application with ApolloProvider

1import React from "react";
2import ReactDOM from "react-dom/client";
3import { ApolloProvider } from "@apollo/client";
4import { apolloClient } from "./lib/apolloClient";
5import { App } from "./App";
6 
7ReactDOM.createRoot(document.getElementById("root")!).render(
8 <React.StrictMode>
9 <ApolloProvider client={apolloClient}>
10 <App />
11 </ApolloProvider>
12 </React.StrictMode>
13);

Any child component within this tree can now execute GraphQL operations via hooks (useQuery, useMutation, useSubscription).


Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the primary problem of "over-fetching" in traditional REST APIs?
Question 2
How does Apollo Client's InMemoryCache normalize incoming data entities?
Question 3
What is the purpose of Apollo's setContext link in the client configuration?
Question 4
What happens if two separate queries request different fields for the exact same entity id?
Question 5
What is the GraphQL equivalent of an HTTP POST / PUT / DELETE operation in REST?
Next Lesson

Executing GraphQL Queries with useQuery

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
High-Performance Form Optimization ComparisonExecuting GraphQL Queries with useQuery

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext