graphprotocol / graphprotocol/hypergraph
Add upsert entity hook
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 22
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
Often you'll want to modify an entity if it exists, or create it if it doesn't. For example, say you land on a page for a new TV show. You might want to add the TV show to your "Watch later" list and add a note on why you saved it. To do this, the code looks like this:
const maybeSavedShow = useQueryEntity(...)
const updateSavedShow = useUpdateEntity(..., maybeSavedShow?.id ?? '')
const createSavedShow = useCreateEntity(...)
const onClick = maybeSavedShow ? updateSavedShow : createSavedShow
<button onClick={onClick}>Add to watchlist</button>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing useQueryEntity, useUpdateEntity, and useCreateEntity hooks referenced in the example. Define the new upsert hook around the shown existing-versus-new entity flow, and verify that it updates when the entity exists and creates it otherwise.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100