@powerhousedao/academy 4.1.0-dev.18 → 4.1.0-dev.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 4.1.0-dev.19 (2025-08-14)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - **academy:** subgraph example ([ae3e24458](https://github.com/powerhouse-inc/powerhouse/commit/ae3e24458))
6
+
7
+ ### ❤️ Thank You
8
+
9
+ - Frank
10
+
1
11
  ## 4.1.0-dev.18 (2025-08-14)
2
12
 
3
13
  This was a version bump only for @powerhousedao/academy to align it with other projects, there were no code changes.
@@ -78,7 +78,7 @@ Initializing Subgraph Manager...
78
78
  ➜ Reactor: http://localhost:4001/d/powerhouse
79
79
  ```
80
80
 
81
- ## 2. Building a to-do list subgraph
81
+ ## 2. Building a search subgraph
82
82
 
83
83
  Now that we've generated our subgraph its tome to define the GraphQL schema and implement the resolvers.
84
84
 
@@ -118,7 +118,7 @@ export const getResolvers = (subgraph: Subgraph) => {
118
118
  const todoItems: string[] = [];
119
119
  for (const docId of documents) {
120
120
  const doc: ToDoListDocument = await reactor.getDocument(docId);
121
- if (doc.header.documentType !== "powerhouse/todo-list") {
121
+ if (doc.header.documentType !== "powerhouse/todolist") {
122
122
  continue;
123
123
  }
124
124
 
@@ -153,7 +153,12 @@ You should see the subgraph being registered in the console output:
153
153
  ### 3.2. Create some test data
154
154
  Before testing queries, let's create some To-do List documents with test data:
155
155
 
156
- 1. Open Connect at `http://localhost:3001` in another terminal
156
+ 1. Start Connect
157
+ ```bash
158
+ ph connect
159
+ ```
160
+
161
+ 1. Open Connect at `http://localhost:3000` in the browser
157
162
  2. Add the 'remote' drive that is running locally via the (+) 'Add Drive' button. Add 'http://localhost:4001/d/powerhouse'
158
163
  3. Create a new To-do List document
159
164
  4. Add some test items:
@@ -165,7 +170,7 @@ Before testing queries, let's create some To-do List documents with test data:
165
170
  Open your browser and go to:
166
171
 
167
172
  ```bash
168
- http://localhost:4001/graphql/to-do-list
173
+ http://localhost:4001/graphql
169
174
  ```
170
175
 
171
176
  ### 3.4. Test the queries
@@ -173,10 +178,11 @@ http://localhost:4001/graphql/to-do-list
173
178
  **Query 1: Search for Todos **
174
179
  ```graphql
175
180
  query {
176
- searchTodos(driveId: "powerhouse", searchTerm: "test")
181
+ searchTodos(driveId: "powerhouse", searchTerm: "Test")
177
182
  }
178
183
  ```
179
184
 
185
+ You should get a list of the document Ids which contain the search term "Test".
180
186
 
181
187
  ### 3.5. Test real-time updates
182
188
 
@@ -190,9 +196,10 @@ To verify that your subgraph stays synchronized with document changes:
190
196
 
191
197
  This demonstrates the real-time synchronization between the document model and the subgraph through event processing.
192
198
 
193
- ## 4. Working with the supergraph or gateway
194
199
 
195
- A supergraph is a GraphQL schema that combines multiple underlying GraphQL APIs, known as subgraphs, into a single, unified graph. This architecture allows different teams to work independently on their respective services (subgraphs) while providing a single entry point for clients or users to query all available data.
200
+ ## 4. Working with the GraphQL Gateway
201
+
202
+ The GraphQL Gateway is a GraphQL schema that combines multiple underlying GraphQL APIs, known as subgraphs, into a single, unified graph. This architecture allows different teams to work independently on their respective services (subgraphs) while providing a single entry point for clients or users to query all available data.
196
203
 
197
204
  ### 4.1 Key concepts
198
205
 
@@ -268,19 +268,41 @@ A subgraph is a GraphQL schema that exposes your processed data to clients. It:
268
268
 
269
269
  ### Configure the Subgraph
270
270
 
271
- Open `./subgraphs/todo/index.ts` and configure the resolvers:
271
+ Open `./subgraphs/todo/schema.ts`and configure the schema:
272
272
 
273
273
  ```ts
274
- import { Subgraph } from "@powerhousedao/reactor-api";
275
274
  import { gql } from "graphql-tag";
275
+ import type { DocumentNode } from "graphql";
276
+
277
+ export const schema: DocumentNode = gql`
278
+
279
+ # Define the structure of a todo item as returned by GraphQL
280
+ type ToDoListEntry {
281
+ task: String! # The task description (! means required/non-null)
282
+ status: Boolean! # The completion status (true = done, false = pending)
283
+ }
284
+
285
+ # Define available queries
286
+ type Query {
287
+ todos(driveId: ID!): [ToDoListEntry] # Get array of todos for a specific drive
288
+ }
289
+ `;
290
+
291
+ ```
292
+
293
+ Open `./subgraphs/todo/resolvers.ts` and configure the resolvers:
294
+
295
+ ```ts
296
+ // subgraphs/search-todos/resolvers.ts
297
+ import { type Subgraph } from "@powerhousedao/reactor-api";
298
+ import { type ToDoListDocument } from "document-models/to-do-list/index.js";
276
299
  import { TodoIndexerProcessor } from "../../processors/todo-indexer/index.js";
277
300
 
278
- export class TodoSubgraph extends Subgraph {
279
- // Human-readable name for this subgraph
280
- name = "Todos";
301
+ export const getResolvers = (subgraph: Subgraph) => {
302
+ const reactor = subgraph.reactor;
303
+ const relationalDb = subgraph.relationalDb;
281
304
 
282
- // GraphQL resolvers - functions that fetch data for each field
283
- resolvers = {
305
+ return {
284
306
  Query: {
285
307
  todos: {
286
308
  // Resolver function for the "todos" query
@@ -288,7 +310,7 @@ export class TodoSubgraph extends Subgraph {
288
310
  resolve: async (_: any, args: {driveId: string}) => {
289
311
  // Query the database using the processor's static query method
290
312
  // This gives us access to the namespaced database for the specific drive
291
- const todos = await TodoIndexerProcessor.query(args.driveId, this.relationalDb)
313
+ const todos = await TodoIndexerProcessor.query(args.driveId, relationalDb)
292
314
  .selectFrom("todo") // Select from the "todo" table
293
315
  .selectAll() // Get all columns
294
316
  .execute(); // Execute the query
@@ -302,29 +324,10 @@ export class TodoSubgraph extends Subgraph {
302
324
  },
303
325
  },
304
326
  };
305
-
306
- // GraphQL schema definition using GraphQL Schema Definition Language (SDL)
307
- typeDefs = gql`
308
-
309
- # Define the structure of a todo item as returned by GraphQL
310
- type ToDoListEntry {
311
- task: String! # The task description (! means required/non-null)
312
- status: Boolean! # The completion status (true = done, false = pending)
313
- }
314
-
315
- # Define available queries
316
- type Query {
317
- todos(driveId: ID!): [ToDoListEntry] # Get array of todos for a specific drive
318
- }
319
- `;
320
-
321
- // Cleanup method called when the subgraph disconnects
322
- async onDisconnect() {
323
- // Add any cleanup logic here if needed
324
- }
325
- }
327
+ };
326
328
  ```
327
329
 
330
+
328
331
  ## Now query the data via the supergraph.
329
332
 
330
333
  **Understanding the Supergraph**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/academy",
3
- "version": "4.1.0-dev.18",
3
+ "version": "4.1.0-dev.19",
4
4
  "homepage": "https://powerhouse.academy",
5
5
  "repository": {
6
6
  "type": "git",