Skip to content

Commit eed2b33

Browse files
committed
fix invalidation
1 parent d84c16b commit eed2b33

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { Graph, type Op } from '@graphprotocol/grc-20';
22
import type { Connect } from '@graphprotocol/hypergraph';
3+
import { Constants } from '@graphprotocol/hypergraph';
34
import { useQueryClient } from '@tanstack/react-query';
5+
import * as Option from 'effect/Option';
46
import type * as Schema from 'effect/Schema';
7+
import * as SchemaAST from 'effect/SchemaAST';
58
import request, { gql } from 'graphql-request';
69
import { publishOps } from '../publish-ops.js';
710

@@ -70,16 +73,22 @@ export const useDeleteEntityPublic = <S extends Schema.Schema.AnyNoContext>(
7073
name: `Delete entity ${id}`,
7174
walletClient,
7275
});
76+
77+
const typeIds = SchemaAST.getAnnotation<string[]>(Constants.TypeIdsSymbol)(
78+
type.ast as SchemaAST.TypeLiteral,
79+
).pipe(Option.getOrElse(() => []));
80+
7381
// TODO: temporary fix until we get the information from the API when a transaction is confirmed
7482
await new Promise((resolve) => setTimeout(resolve, 2000));
75-
queryClient.invalidateQueries({
76-
queryKey: [
77-
'hypergraph-public-entities',
78-
// @ts-expect-error - TODO: find a better way to access the type.name
79-
type.name,
80-
space,
81-
],
82-
});
83+
if (typeIds.length > 0) {
84+
queryClient.invalidateQueries({
85+
queryKey: ['hypergraph-public-entities', space, typeIds],
86+
});
87+
} else {
88+
queryClient.invalidateQueries({
89+
queryKey: ['hypergraph-public-entities', space],
90+
});
91+
}
8392

8493
return { success: true, cid, txResult };
8594
} catch (_error) {

0 commit comments

Comments
 (0)