1- import { Graph , type GrcOp , Id } from '@graphprotocol/grc-20' ;
1+ import { Graph } from '@graphprotocol/grc-20' ;
22import type { Connect } from '@graphprotocol/hypergraph' ;
3- import { Config , Constants } from '@graphprotocol/hypergraph' ;
3+ import { Constants } from '@graphprotocol/hypergraph' ;
44import { useQueryClient } from '@tanstack/react-query' ;
55import * as Option from 'effect/Option' ;
66import type * as Schema from 'effect/Schema' ;
77import * as SchemaAST from 'effect/SchemaAST' ;
8- import request , { gql } from 'graphql-request' ;
98import { publishOps } from '../publish-ops.js' ;
109
1110type 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-
5314export 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