-
Notifications
You must be signed in to change notification settings - Fork 8
add public delete #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add public delete #239
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this 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 debugconsole.log
insmart-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 toentityType
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';
const result = await request<EntityToDeleteQueryResult>(GEO_API_TESTNET_ENDPOINT, deleteEntityQueryDocument, { | ||
spaceId: space, | ||
entityId: id, | ||
}); |
Copilot
AI
Jun 23, 2025
There was a problem hiding this comment.
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.
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)); |
Copilot
AI
Jun 23, 2025
There was a problem hiding this comment.
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 |
Copilot
AI
Jun 23, 2025
There was a problem hiding this comment.
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.
// @ts-expect-error - TODO: find a better way to access the type.name |
Copilot uses AI. Check for mistakes.
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 }); |
Copilot
AI
Jun 23, 2025
There was a problem hiding this comment.
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.
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.
55b9ffd
to
896d123
Compare
No description provided.