-
Notifications
You must be signed in to change notification settings - Fork 14
proposal: hook for publishing public data #416
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
Changes from all commits
7719f30
d1feaa4
2869429
bdeda9e
56a0aed
f56bfe7
c57266b
dc75818
3ccf52b
22c5daf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "create-hypergraph": patch | ||
| --- | ||
|
|
||
| Update vite template to use usePublishToPublicSpace | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@graphprotocol/hypergraph-react": patch | ||
| --- | ||
|
|
||
| Add usePublishToPublicSpace hook | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pnpm 10.14.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { Entity } from '@graphprotocol/hypergraph'; | ||
| import { type UseMutationOptions, useMutation } from '@tanstack/react-query'; | ||
| import { useHypergraphApp } from '../HypergraphAppContext.js'; | ||
| import { preparePublish } from '../prepare-publish.js'; | ||
| import { publishOps } from '../publish-ops.js'; | ||
| import type { OmitStrict } from '../types.js'; | ||
|
|
||
| type Variables<S extends Entity.AnyNoContext> = { | ||
| entity: S; | ||
| spaceId: string; | ||
| }; | ||
|
|
||
| type UsePublishToSpaceOptions = OmitStrict< | ||
| UseMutationOptions<Awaited<ReturnType<typeof publishOps>>, Error, Variables<Entity.AnyNoContext>, unknown>, | ||
| 'mutationFn' | 'mutationKey' | ||
| >; | ||
|
|
||
| export function usePublishToPublicSpace(options: UsePublishToSpaceOptions = {}) { | ||
| const { getSmartSessionClient } = useHypergraphApp(); | ||
|
|
||
| return useMutation({ | ||
| ...options, | ||
| mutationFn: async ({ entity, spaceId }) => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the |
||
| const { ops } = await preparePublish({ | ||
| entity, | ||
| publicSpace: spaceId, | ||
| }); | ||
| const smartSessionClient = await getSmartSessionClient(); | ||
| if (!smartSessionClient) { | ||
| throw new Error('Missing smartSessionClient'); | ||
| } | ||
|
|
||
| return await publishOps({ | ||
| ops, | ||
| space: spaceId, | ||
| name: 'Published entity', | ||
| walletClient: smartSessionClient, | ||
| }); | ||
| }, | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ import type { Op } from '@graphprotocol/grc-20'; | |
| import type { Entity } from '@graphprotocol/hypergraph'; | ||
| import type * as Schema from 'effect/Schema'; | ||
|
|
||
| export type OmitStrict<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this types utility which I add to basically every codebase. Makes it so type Banana = {
id: string;
isFruit: boolean;
}
// Will error as "isVegetable" doesn't exist on type Banana
type DerivedBanana = OmitStrict<Banana, "isVegetable">
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙏 🙏 idk why this isn't just in typescript. annoys the hell out of me |
||
|
|
||
| export type EntityLike = { | ||
| id: string; | ||
| [key: string]: unknown; | ||
|
|
||
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.
Omitted the mutation-related options so devs aren't tempted to add their own mutation function.