Day 01 Foundations

Schemas, Types, and Your First Query

GraphQL replaces a dozen REST endpoints with a single typed contract. Build a schema, write your first query and mutation, and understand why type-safety changes everything about API design.

~1 hour Intermediate Hands-on Precision AI Academy

Today's Objective

GraphQL replaces a dozen REST endpoints with a single typed contract. Build a schema, write your first query and mutation, and understand why type-safety changes everything about API design.

01

What GraphQL Solves

With REST, you get what the server decides to give you. With GraphQL, the client specifies exactly what it needs. No over-fetching (getting more data than needed). No under-fetching (needing multiple requests to get everything).

Setup
npm init -y
npm install @apollo/server graphql
# Create server.js
server.js
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';

// Schema Definition Language (SDL)
const typeDefs = `#graphql
  type User {
    id: ID!
    name: String!
    email: String!
    posts: [Post!]!
  }

  type Post {
    id: ID!
    title: String!
    body: String
    author: User!
  }

  type Query {
    users: [User!]!
    user(id: ID!): User
    posts: [Post!]!
  }
`;

const users = [
  { id: '1', name: 'Alice', email: '[email protected]' },
  { id: '2', name: 'Bob', email: '[email protected]' },
];

const resolvers = {
  Query: {
    users: () => users,
    user: (_, { id }) => users.find(u => u.id === id),
  },
  User: {
    posts: (user) => posts.filter(p => p.authorId === user.id),
  },
};

const server = new ApolloServer({ typeDefs, resolvers });
const { url } = await startStandaloneServer(server, { listen: { port: 4000 } });
console.log(`Server ready at ${url}`);
💡
The ! in GraphQL types means non-null. String! = never null. [Post!]! = non-null array of non-null posts. Use non-null as much as possible — it makes client code cleaner and prevents null checks everywhere.
📝 Day 1 Exercise
Build Your First GraphQL API
  1. C
  2. r
  3. e
  4. a
  5. t
  6. e
  7. a
  8. n
  9. A
  10. p
  11. o
  12. l
  13. l
  14. o
  15. S
  16. e
  17. r
  18. v
  19. e
  20. r
  21. w
  22. i
  23. t
  24. h
  25. U
  26. s
  27. e
  28. r
  29. a
  30. n
  31. d
  32. P
  33. o
  34. s
  35. t
  36. t
  37. y
  38. p
  39. e
  40. s
  41. .
  42. W
  43. r
  44. i
  45. t
  46. e
  47. r
  48. e
  49. s
  50. o
  51. l
  52. v
  53. e
  54. r
  55. s
  56. .
  57. R
  58. u
  59. n
  60. t
  61. h
  62. e
  63. s
  64. e
  65. r
  66. v
  67. e
  68. r
  69. a
  70. n
  71. d
  72. o
  73. p
  74. e
  75. n
  76. t
  77. h
  78. e
  79. G
  80. r
  81. a
  82. p
  83. h
  84. i
  85. Q
  86. L
  87. s
  88. a
  89. n
  90. d
  91. b
  92. o
  93. x
  94. a
  95. t
  96. l
  97. o
  98. c
  99. a
  100. l
  101. h
  102. o
  103. s
  104. t
  105. :
  106. 4
  107. 0
  108. 0
  109. 0
  110. .
  111. Q
  112. u
  113. e
  114. r
  115. y
  116. a
  117. l
  118. l
  119. u
  120. s
  121. e
  122. r
  123. s
  124. a
  125. n
  126. d
  127. a
  128. l
  129. l
  130. p
  131. o
  132. s
  133. t
  134. s
  135. .

Day 1 Summary

What's Next

The foundations from today carry directly into Day 2. In the next session the focus shifts to Resolvers, Data Sources, and Context — building directly on everything covered here.

Day 1 Checkpoint

Before moving on, verify you can answer these without looking:

  • What is the core concept introduced in this lesson, and why does it matter?
  • What are the two or three most common mistakes practitioners make with this topic?
  • Can you explain the key code pattern from this lesson to a colleague in plain language?
  • What would break first if you skipped the safeguards or best practices described here?
  • How does today's topic connect to what comes in Day 2?

Live Bootcamp

Learn this in person — 2 days, 5 cities

Thu–Fri sessions in Denver, Los Angeles, New York, Chicago, and Dallas. $1,490 per seat. June–October 2026.

Reserve Your Seat →
Continue To Day 2
Day 2: Queries: Fetching Exactly What You Need