-
Notifications
You must be signed in to change notification settings - Fork 8
Public graph integration #154
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
Merged
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
d32cc49
first version of merged query
nikgraf 4b163dd
refactor useQuery
nikgraf 2338269
add spinner and improve loading experience
nikgraf efe0872
fix test
nikgraf 44ec55b
filter out entities marked as deleted from local result
nikgraf 01fc533
fix linting
nikgraf bbf9227
fix loading experience
nikgraf 2158f57
fix login behaviour by reseting first and then setting the auth
nikgraf a86843c
fix types
nikgraf 3082921
fix delete by using correct endpoint
nikgraf bb853a7
invalidate queries after publishing
nikgraf b16b4eb
fix bug filtering out deleted entities
nikgraf 0baa851
fix returning multiple entities
nikgraf 6861e89
show deleted local todos
nikgraf 62ccd8c
fix update
nikgraf 133e005
add prepare publish functionality
nikgraf 7c75d65
swtich from kg to geo for deleting entities
nikgraf d31aacd
restructure utilities
nikgraf df8ccd0
expose more information in getDiff
nikgraf 413ce3b
fix checked state for public queries
nikgraf ff3b874
create PublishDiff component
nikgraf 2ee0ba1
add loading states to buttons
nikgraf 3d87051
add type information
nikgraf 983b992
ignore updates in the __version field
nikgraf d1d9cdf
hotfix the entity type name for the publish diff component
nikgraf d5aa216
only require mapping if in merged mode
nikgraf 1cdc4de
split up todos2
nikgraf e2399b1
add user mapping
nikgraf 04e68a6
refactor and cleanup diff structure
nikgraf 9faf6d2
fix types to pass different entities to the PublishDiff
nikgraf 6706d83
render relation from public query
nikgraf fd76a0b
add users tab
nikgraf 3f71c47
ensure stable references to the data array for use-query
nikgraf 6f4a404
add assignee selector
nikgraf c8c237e
improve relation creation
nikgraf c2fe954
fix loading entities when switching tabs
nikgraf be0fa3c
improve diff for relations
nikgraf 5c18295
fix relation setup for public integration and implement generating up…
nikgraf 5fac44a
allow to remove assignees again
nikgraf c32fb72
fix showing multiple relations in the public query
nikgraf 1108f08
use separate relation entries instead of adding it to the entity
nikgraf 3af2031
fix updating the list after changing a related entity
nikgraf be9bd6b
add relationParentsMap
nikgraf 230ec7b
refactor smartaccount instantiation
nikgraf bb57575
introduce filters
nikgraf 4a7d692
provide relationId from local relation when publishing
nikgraf 6e4347c
cleanup app structure
nikgraf 563d29d
update mapping
nikgraf 619cad8
fix md5 hashing for web platform
nikgraf 394ac72
fix tests
nikgraf 59b3ee7
update effect packages
nikgraf f085e63
wip patching the entity types
nikgraf 6425aec
improve types
nikgraf 1be3201
cleanup types
nikgraf 59a7388
implement include for local & public queries
nikgraf 2c4bda7
add more filters
nikgraf 5a2a3f5
enhance filter capabilities
nikgraf 1d5d2c5
Merge branch 'main' into ng/public-graph-integration
nikgraf e0c822b
fix import
nikgraf 5910d3b
remove unused filter-types
nikgraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
apps/events/src/components/create-properties-and-types.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { getSmartAccountWalletClient } from '@/lib/smart-account'; | ||
import { type GeoSmartAccount, Graph, type Op } from '@graphprotocol/grc-20'; | ||
import { publishOps, useHypergraphSpace } from '@graphprotocol/hypergraph-react'; | ||
import { useState } from 'react'; | ||
import { Button } from './ui/button'; | ||
import { Card, CardContent } from './ui/card'; | ||
|
||
const createPropertiesAndTypes = async ({ | ||
smartAccountWalletClient, | ||
space, | ||
}: { smartAccountWalletClient: GeoSmartAccount; space: string }) => { | ||
const ops: Array<Op> = []; | ||
const { id: checkedPropertyId, ops: createCheckedPropertyOps } = Graph.createProperty({ | ||
type: 'CHECKBOX', | ||
name: 'Checked', | ||
}); | ||
ops.push(...createCheckedPropertyOps); | ||
|
||
const { id: userId, ops: createUserOps } = Graph.createType({ | ||
name: 'User', | ||
}); | ||
ops.push(...createUserOps); | ||
|
||
const { id: assigneesRelationTypeId, ops: createAssigneesRelationTypeOps } = Graph.createProperty({ | ||
type: 'RELATION', | ||
name: 'Assignees', | ||
relationValueTypes: [userId], | ||
}); | ||
ops.push(...createAssigneesRelationTypeOps); | ||
|
||
const { id: todoTypeId, ops: createTodoTypeOps } = Graph.createType({ | ||
name: 'Todo', | ||
properties: [checkedPropertyId, assigneesRelationTypeId], | ||
}); | ||
ops.push(...createTodoTypeOps); | ||
|
||
const result = await publishOps({ ops, walletClient: smartAccountWalletClient, space }); | ||
return { result, todoTypeId, checkedPropertyId, userId, assigneesRelationTypeId }; | ||
}; | ||
|
||
export const CreatePropertiesAndTypes = () => { | ||
const [mapping, setMapping] = useState<string>(''); | ||
const space = useHypergraphSpace(); | ||
|
||
return ( | ||
<div> | ||
{mapping && ( | ||
<Card> | ||
<CardContent> | ||
<pre>{mapping}</pre> | ||
</CardContent> | ||
</Card> | ||
)} | ||
<Button | ||
onClick={async () => { | ||
const smartAccountWalletClient = await getSmartAccountWalletClient(); | ||
if (!smartAccountWalletClient) { | ||
throw new Error('Missing smartAccountWalletClient'); | ||
} | ||
const { todoTypeId, checkedPropertyId, userId, assigneesRelationTypeId } = await createPropertiesAndTypes({ | ||
smartAccountWalletClient, | ||
space, | ||
}); | ||
|
||
const newMapping = `Todo2: { | ||
typeIds: [Id.Id('${todoTypeId}')], | ||
properties: { | ||
name: Id.Id('LuBWqZAu6pz54eiJS5mLv8'), | ||
checked: Id.Id('${checkedPropertyId}'), | ||
}, | ||
relations: { | ||
assignees: Id.Id('${assigneesRelationTypeId}'), | ||
}, | ||
}, | ||
User: { | ||
typeIds: [Id.Id('${userId}')], | ||
properties: { | ||
name: Id.Id('LuBWqZAu6pz54eiJS5mLv8'), | ||
}, | ||
} | ||
`; | ||
setMapping(newMapping); | ||
}} | ||
> | ||
Create properties and types | ||
</Button> | ||
</div> | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { useQuery } from '@graphprotocol/hypergraph-react'; | ||
import { NewsStory } from '../schema'; | ||
|
||
export const Playground = () => { | ||
const { data: entityData, isLoading, isError } = useQuery(NewsStory, { mode: 'public' }); | ||
|
||
console.log({ isLoading, isError, entityData }); | ||
|
||
return <pre className="text-xs">{JSON.stringify(entityData, null, 2)}</pre>; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use client'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
import { motion } from 'framer-motion'; | ||
|
||
interface SpinnerProps { | ||
size?: 'sm' | 'md' | 'lg' | 'xl'; | ||
color?: 'default' | 'primary' | 'secondary' | 'accent' | 'white'; | ||
className?: string; | ||
} | ||
|
||
export function Spinner({ size = 'md', color = 'primary', className }: SpinnerProps) { | ||
const sizeClasses = { | ||
sm: 'h-4 w-4 border-2', | ||
md: 'h-6 w-6 border-2', | ||
lg: 'h-8 w-8 border-3', | ||
xl: 'h-12 w-12 border-4', | ||
}; | ||
|
||
const colorClasses = { | ||
default: 'border-muted-foreground/30 border-t-muted-foreground', | ||
primary: 'border-primary/30 border-t-primary', | ||
secondary: 'border-secondary/30 border-t-secondary', | ||
accent: 'border-accent/30 border-t-accent', | ||
white: 'border-white/30 border-t-white', | ||
}; | ||
|
||
return ( | ||
<motion.div | ||
className={cn('rounded-full animate-spin', sizeClasses[size], colorClasses[color], className)} | ||
animate={{ rotate: 360 }} | ||
transition={{ | ||
duration: 1, | ||
ease: 'linear', | ||
repeat: Number.POSITIVE_INFINITY, | ||
}} | ||
aria-label="Loading" | ||
> | ||
<span className="sr-only">Loading...</span> | ||
</motion.div> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useHardDeleteEntity, useQuery, useUpdateEntity } from '@graphprotocol/hypergraph-react'; | ||
import { Todo2 } from '../../schema'; | ||
import { Button } from '../ui/button'; | ||
|
||
export const TodosLocal = () => { | ||
const updateEntity = useUpdateEntity(Todo2); | ||
const hardDeleteEntity = useHardDeleteEntity(); | ||
const { data: todosLocalData, deleted: deletedTodosLocalData } = useQuery(Todo2, { mode: 'local' }); | ||
|
||
return ( | ||
<> | ||
<h2 className="text-2xl font-bold">Todos (Local)</h2> | ||
{todosLocalData.map((todo) => ( | ||
<div key={todo.id} className="flex flex-row items-center gap-2"> | ||
<h2>{todo.name}</h2> | ||
<div className="text-xs">{todo.id}</div> | ||
{todo.assignees.map((assignee) => ( | ||
<span key={assignee.id} className="border rounded-sm mr-1 p-1"> | ||
{assignee.name} | ||
</span> | ||
))} | ||
<input | ||
type="checkbox" | ||
checked={todo.checked} | ||
onChange={(e) => updateEntity(todo.id, { checked: e.target.checked })} | ||
/> | ||
{/* @ts-expect-error */} | ||
<div className="text-xs">{todo.__deleted ? 'deleted' : 'not deleted'}</div> | ||
{/* @ts-expect-error */} | ||
<div className="text-xs">{todo.__version}</div> | ||
<Button variant="secondary" size="sm" onClick={() => hardDeleteEntity(todo.id)}> | ||
Hard Delete | ||
</Button> | ||
</div> | ||
))} | ||
<h2 className="text-2xl font-bold">Deleted Todos (Local)</h2> | ||
{deletedTodosLocalData.map((todo) => ( | ||
<div key={todo.id} className="flex flex-row items-center gap-2"> | ||
<h2>{todo.name}</h2> | ||
<div className="text-xs">{todo.id}</div> | ||
<Button variant="secondary" size="sm" onClick={() => hardDeleteEntity(todo.id)}> | ||
Hard Delete | ||
</Button> | ||
</div> | ||
))} | ||
</> | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { getSmartAccountWalletClient } from '@/lib/smart-account'; | ||
import { Id } from '@graphprotocol/grc-20'; | ||
import { | ||
_generateDeleteOps, | ||
publishOps, | ||
useCreateEntity, | ||
useHypergraphSpace, | ||
useQuery, | ||
} from '@graphprotocol/hypergraph-react'; | ||
import { useGenerateCreateOps } from '@graphprotocol/hypergraph-react/internal/use-generate-create-ops'; | ||
import { Todo2 } from '../../schema'; | ||
import { Spinner } from '../spinner'; | ||
import { Button } from '../ui/button'; | ||
|
||
export const TodosPublicGeo = () => { | ||
const space = useHypergraphSpace(); | ||
const { | ||
data: dataPublic, | ||
isLoading: isLoadingPublic, | ||
isError: isErrorPublic, | ||
} = useQuery(Todo2, { | ||
mode: 'public', | ||
include: { assignees: {} }, | ||
}); | ||
|
||
const createTodo = useCreateEntity(Todo2); | ||
const generateCreateOps = useGenerateCreateOps(Todo2); | ||
|
||
return ( | ||
<> | ||
<div className="flex flex-row gap-4 items-center"> | ||
<h2 className="text-2xl font-bold">Todos (Public Geo)</h2> | ||
{isLoadingPublic && <Spinner size="sm" />} | ||
</div> | ||
{isErrorPublic && <div>Error loading todos</div>} | ||
{dataPublic.map((todo) => ( | ||
<div key={todo.id} className="flex flex-row items-center gap-2"> | ||
<h2>{todo.name}</h2> | ||
<div className="text-xs">{todo.id}</div> | ||
<input type="checkbox" checked={todo.checked} readOnly /> | ||
{todo.assignees.map((assignee) => ( | ||
<span key={assignee.id} className="border rounded-sm mr-1 p-1"> | ||
{assignee.name} | ||
</span> | ||
))} | ||
|
||
<Button | ||
onClick={async () => { | ||
const smartAccountWalletClient = await getSmartAccountWalletClient(); | ||
if (!smartAccountWalletClient) { | ||
throw new Error('Missing smartAccountWalletClient'); | ||
} | ||
const ops = await _generateDeleteOps({ id: todo.id, space }); | ||
const result = await publishOps({ ops, walletClient: smartAccountWalletClient, space }); | ||
console.log('result', result); | ||
}} | ||
> | ||
Delete | ||
</Button> | ||
</div> | ||
))} | ||
<Button | ||
onClick={async () => { | ||
const smartAccountWalletClient = await getSmartAccountWalletClient(); | ||
if (!smartAccountWalletClient) { | ||
throw new Error('Missing smartAccountWalletClient'); | ||
} | ||
const userId = Id.Id('8zPJjTGLBDPtUcj6q2tghg'); | ||
const todo = createTodo({ name: 'New Todo 22', checked: false, assignees: [userId] }); | ||
console.log('todo', todo); | ||
const { ops } = generateCreateOps(todo); | ||
console.log('ops', ops); | ||
const result = await publishOps({ ops, walletClient: smartAccountWalletClient, space }); | ||
console.log('result', result); | ||
}} | ||
> | ||
Create | ||
</Button> | ||
</> | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { getSmartAccountWalletClient } from '@/lib/smart-account'; | ||
import { | ||
_generateDeleteOps, | ||
publishOps, | ||
useHypergraphSpace, | ||
_useQueryPublicKg as useQueryPublicKg, | ||
} from '@graphprotocol/hypergraph-react'; | ||
import { Todo2 } from '../../schema'; | ||
import { Spinner } from '../spinner'; | ||
import { Button } from '../ui/button'; | ||
|
||
export const TodosPublicKg = () => { | ||
const space = useHypergraphSpace(); | ||
const { data: kgPublicData, isLoading: kgPublicIsLoading, isError: kgPublicIsError } = useQueryPublicKg(Todo2); | ||
|
||
return ( | ||
<> | ||
<div className="flex flex-row gap-4 items-center"> | ||
<h2 className="text-2xl font-bold">Todos (Public KG)</h2> | ||
{kgPublicIsLoading && <Spinner size="sm" />} | ||
</div> | ||
{kgPublicIsError && <div>Error loading todos</div>} | ||
{kgPublicData.map((todo) => ( | ||
<div key={todo.id} className="flex flex-row items-center gap-2"> | ||
<h2>{todo.name}</h2> | ||
<div className="text-xs">{todo.id}</div> | ||
<input type="checkbox" checked={todo.checked} readOnly /> | ||
<Button | ||
onClick={async () => { | ||
const smartAccountWalletClient = await getSmartAccountWalletClient(); | ||
if (!smartAccountWalletClient) { | ||
throw new Error('Missing smartAccountWalletClient'); | ||
} | ||
const ops = await _generateDeleteOps({ id: todo.id, space }); | ||
const result = await publishOps({ ops, walletClient: smartAccountWalletClient, space }); | ||
console.log('result', result); | ||
}} | ||
> | ||
Delete | ||
</Button> | ||
</div> | ||
))} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.