Skip to content

Commit 11c2ab9

Browse files
committed
update delete entity
1 parent 8f4b46d commit 11c2ab9

File tree

2 files changed

+5
-64
lines changed

2 files changed

+5
-64
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"WebFetch(domain:raw.githubusercontent.com)",
1515
"Bash(node -e:*)",
1616
"Bash(pnpm build:*)",
17-
"mcp__chrome-devtools__list_pages"
17+
"mcp__chrome-devtools__list_pages",
18+
"Bash(pnpm lint:*)"
1819
],
1920
"deny": [],
2021
"ask": []

packages/hypergraph-react/src/internal/use-delete-entity-public.tsx

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,16 @@
1-
import { Graph, type GrcOp, Id } from '@graphprotocol/grc-20';
1+
import { Graph } from '@graphprotocol/grc-20';
22
import type { Connect } from '@graphprotocol/hypergraph';
3-
import { Config, Constants } from '@graphprotocol/hypergraph';
3+
import { Constants } from '@graphprotocol/hypergraph';
44
import { useQueryClient } from '@tanstack/react-query';
55
import * as Option from 'effect/Option';
66
import type * as Schema from 'effect/Schema';
77
import * as SchemaAST from 'effect/SchemaAST';
8-
import request, { gql } from 'graphql-request';
98
import { publishOps } from '../publish-ops.js';
109

1110
type DeleteEntityPublicParams = {
1211
space: string;
1312
};
1413

15-
// Local implementation since unsetEntityValues is not exported from Graph namespace
16-
// Note: The UNSET_ENTITY_VALUES op type exists in the v2 binary format but isn't
17-
// included in the GrcOp type definition. Using type assertion as a workaround.
18-
const unsetEntityValues = ({ id, properties }: { id: string; properties: string[] }) => {
19-
const op = {
20-
type: 'UNSET_ENTITY_VALUES',
21-
unsetEntityValues: {
22-
id: Id(id),
23-
properties: properties.map((propertyId) => Id(propertyId)),
24-
},
25-
} as unknown as GrcOp;
26-
return { id: Id(id), ops: [op] };
27-
};
28-
29-
const deleteEntityQueryDocument = gql`
30-
query entityToDelete($entityId: UUID!, $spaceId: UUID!) {
31-
entity(id: $entityId) {
32-
valuesList(filter: {spaceId: {is: $spaceId}}) {
33-
propertyId
34-
}
35-
relationsList(filter: {spaceId: {is: $spaceId}}) {
36-
id
37-
}
38-
}
39-
}
40-
`;
41-
42-
type EntityToDeleteQueryResult = {
43-
entity: {
44-
valuesList: {
45-
propertyId: string;
46-
}[];
47-
relationsList: {
48-
id: string;
49-
}[];
50-
};
51-
} | null;
52-
5314
export const useDeleteEntityPublic = <S extends Schema.Schema.AnyNoContext>(
5415
type: S,
5516
{ space }: DeleteEntityPublicParams,
@@ -58,28 +19,7 @@ export const useDeleteEntityPublic = <S extends Schema.Schema.AnyNoContext>(
5819

5920
return async ({ id, walletClient }: { id: string; walletClient: Connect.SmartSessionClient }) => {
6021
try {
61-
const result = await request<EntityToDeleteQueryResult>(
62-
`${Config.getApiOrigin()}/v2/graphql`,
63-
deleteEntityQueryDocument,
64-
{
65-
spaceId: space,
66-
entityId: id,
67-
},
68-
);
69-
if (!result) {
70-
return { success: false, error: 'Entity not found' };
71-
}
72-
const { valuesList, relationsList } = result.entity;
73-
const ops: GrcOp[] = [];
74-
const { ops: unsetEntityValuesOps } = unsetEntityValues({
75-
id,
76-
properties: valuesList.map(({ propertyId }) => propertyId),
77-
});
78-
ops.push(...unsetEntityValuesOps);
79-
for (const relation of relationsList) {
80-
const { ops: deleteRelationOps } = Graph.deleteRelation({ id: relation.id });
81-
ops.push(...deleteRelationOps);
82-
}
22+
const { ops } = Graph.deleteEntity({ id });
8323

8424
const { cid, txResult } = await publishOps({
8525
ops,

0 commit comments

Comments
 (0)