Skip to content

Conversation

nikgraf
Copy link
Collaborator

@nikgraf nikgraf commented Jun 23, 2025

No description provided.

@nikgraf nikgraf self-assigned this Jun 23, 2025
Copy link

vercel bot commented Jun 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hypergraph-connect ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 23, 2025 10:56am
hypergraph-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 23, 2025 10:56am

@nikgraf nikgraf requested a review from Copilot June 23, 2025 10:38
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a public deletion hook for Hypergraph entities, exposes it in the library index, and integrates it into the example Playground UI while removing leftover debug logging.

  • Adds useDeleteEntityPublic hook to fetch entity details, unset values, delete relations, publish ops, and invalidate cache.
  • Exports the new hook in src/index.ts as _useDeleteEntityPublic.
  • Integrates deletion button into Playground component and cleans up debug console.log in smart-account.ts.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
packages/hypergraph-react/src/internal/use-delete-entity-public.tsx Implement public deletion hook
packages/hypergraph-react/src/index.ts Export new delete hook for external use
apps/events/src/lib/smart-account.ts Remove debug logging of privateKey
apps/events/src/components/playground.tsx Integrate delete button using the new hook
Comments suppressed due to low confidence (2)

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

  • [nitpick] The parameter name type is ambiguous and may conflict with the TS keyword. Consider renaming it to entityType or similar for clarity.
export const useDeleteEntityPublic = <S extends Entity.AnyNoContext>(type: S, { space }: DeleteEntityPublicParams) => {

apps/events/src/components/playground.tsx:2

  • [nitpick] Importing an internal hook that starts with _ may signal a private API. Consider exporting it under a stable public name or documenting its intended use.
import { _useDeleteEntityPublic, useQuery } from '@graphprotocol/hypergraph-react';

Comment on lines 40 to 43
const result = await request<EntityToDeleteQueryResult>(GEO_API_TESTNET_ENDPOINT, deleteEntityQueryDocument, {
spaceId: space,
entityId: id,
});
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Network requests and publishing operations can fail—wrap this call (and the subsequent publishOps) in a try/catch to handle errors and return a structured failure result instead of letting exceptions bubble up.

Suggested change
const result = await request<EntityToDeleteQueryResult>(GEO_API_TESTNET_ENDPOINT, deleteEntityQueryDocument, {
spaceId: space,
entityId: id,
});
let result;
try {
result = await request<EntityToDeleteQueryResult>(GEO_API_TESTNET_ENDPOINT, deleteEntityQueryDocument, {
spaceId: space,
entityId: id,
});
} catch (error) {
return { success: false, error: `Failed to fetch entity: ${error.message}` };
}

Copilot uses AI. Check for mistakes.

walletClient,
network: 'TESTNET',
});
await new Promise((resolve) => setTimeout(resolve, 2000));
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a fixed delay for invalidation is brittle. Consider awaiting a transaction confirmation or using a more deterministic signal before invalidating queries.

Copilot uses AI. Check for mistakes.

queryClient.invalidateQueries({
queryKey: [
'hypergraph-public-entities',
// @ts-expect-error - TODO: find a better way to access the type.name
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @ts-expect-error indicates a type-system workaround. Consider refining the generic constraints or adding a proper interface so you can safely access entityType.name without suppressing TypeScript checks.

Suggested change
// @ts-expect-error - TODO: find a better way to access the type.name

Copilot uses AI. Check for mistakes.

Comment on lines 31 to 40
const walletClient = await getSmartAccountWalletClient();
if (!walletClient) {
throw new Error('Wallet client not found');
}
const { cid, txResult, success } = await deleteEntity({
id: event.id,
// @ts-expect-error - TODO: fix the types error
walletClient,
});
console.log({ cid, txResult, success });
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing inside an event handler will be uncaught in the UI. Wrap the logic in try/catch and provide user feedback instead of letting the exception crash the app.

Suggested change
const walletClient = await getSmartAccountWalletClient();
if (!walletClient) {
throw new Error('Wallet client not found');
}
const { cid, txResult, success } = await deleteEntity({
id: event.id,
// @ts-expect-error - TODO: fix the types error
walletClient,
});
console.log({ cid, txResult, success });
try {
const walletClient = await getSmartAccountWalletClient();
if (!walletClient) {
throw new Error('Wallet client not found');
}
const { cid, txResult, success } = await deleteEntity({
id: event.id,
// @ts-expect-error - TODO: fix the types error
walletClient,
});
console.log({ cid, txResult, success });
} catch (error) {
console.error('Error occurred while deleting entity:', error);
alert('An error occurred. Please try again later.');
}

Copilot uses AI. Check for mistakes.

@nikgraf nikgraf force-pushed the ng/implement-public-delete branch from 55b9ffd to 896d123 Compare June 23, 2025 10:54
@nikgraf nikgraf merged commit 35aaab2 into main Jun 23, 2025
7 checks passed
@nikgraf nikgraf deleted the ng/implement-public-delete branch June 23, 2025 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant