Skip to content

Commit fae9b9c

Browse files
committed
add id to items
1 parent 507c2fb commit fae9b9c

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

apps/events/src/components/events.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const Events: React.FC = () => {
9797
<p>Participants:</p>
9898
<ul>
9999
{event.participants.map((participant) => (
100-
<li key={participant.name}>
100+
<li key={participant.id}>
101101
{participant.name} ({participant.badge.name})
102102
</li>
103103
))}

packages/graph-framework/src/context.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const type = {
4646
};
4747

4848
type BaseEntity = {
49+
id: string;
4950
types: string[];
5051
};
5152

@@ -424,7 +425,7 @@ export function createFunctions<T extends SchemaDefinition>(schema: T) {
424425
return entity; // Return as is or handle accordingly
425426
}
426427
visited.add(entityId);
427-
const resolvedEntity = { ...entity };
428+
const resolvedEntity = { ...entity, id: entityId };
428429
for (const entityType of entityTypes) {
429430
const typeSchema = schema.types[entityType];
430431
for (const key in typeSchema) {

packages/graph-framework/src/index.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ describe("Library Tests", () => {
150150
if (!event) {
151151
throw new Error("Event not found");
152152
}
153+
expect(event.id).toBeTypeOf("string");
153154
expect(event.types).toStrictEqual(["Event"]);
154155
expect(event.name).toBe("Conference");
155156

@@ -163,40 +164,50 @@ describe("Library Tests", () => {
163164
) {
164165
throw new Error("Participants not found");
165166
}
167+
168+
expect(event.participants[0].id).toBeTypeOf("string");
166169
expect(event.participants[0].types).toStrictEqual(["Person"]);
167170
expect(event.participants[0].name).toBe("Alice");
168171
expect(event.participants[0].age).toBe(30);
169172
expect(event.participants[0].badges).toHaveLength(1);
170173
expect(event.participants[0].badges[0].name).toBe("Speaker");
171174

175+
expect(event.participants[1].id).toBeTypeOf("string");
172176
expect(event.participants[1].types).toStrictEqual(["Person"]);
173177
expect(event.participants[1].name).toBe("Bob");
174178
expect(event.participants[1].age).toBe(25);
175179
expect(event.participants[1].badges).toHaveLength(1);
176180
expect(event.participants[1].badges[0].name).toBe("Attendee");
177181

178182
// Check author
183+
expect(event.author.id).toBeTypeOf("string");
179184
expect(event.author.types).toStrictEqual(["User", "Person"]);
180185
expect(event.author.name).toBe("Charlie");
181186
expect(event.author.email).toBe("[email protected]");
182187

183188
expectTypeOf(event).toMatchTypeOf<{
189+
id: string;
184190
types: string[];
185191
name: string;
186192
participants: {
193+
id: string;
187194
types: string[];
188195
name: string;
189196
age: number;
190197
badges: {
198+
id: string;
199+
types: string[];
191200
name: string;
192201
}[];
193202
}[];
194203
author: {
204+
id: string;
195205
types: string[];
196206
name: string;
197207
age: number;
198208
email: string;
199209
badges: {
210+
id: string;
200211
types: string[];
201212
name: string;
202213
}[];

0 commit comments

Comments
 (0)