graphprotocol / graphprotocol/hypergraph

Async functions for querying public graph

Open
#438 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
22
Forks
12
PR merge metrics
No merged PRs in 30d

Description

Currently the only way to query the public graph using a specific schema is to go through Hypergraph's client-side useQuery hook. This works well when you need to modify the data, as we can keep the source of truth for queried data in the same place as modified data.

There are some use-cases where you just need to query for public data but not modify it. For this use case useQuery still works, but it won't work for server-side rendering or ad-hoc queries that run as a result of side-effects.

We should expose the query internals in a separate query(Schema) function.

Query options

Queries require things like the mapping or the space in order to generate the query + filters for a specific schema. We'll need a way to provide these options to the query at query time.

Option 1
We can pass the options to the query directly.

await query(Address, { mapping, spaceId })

Option 2
We can create a QueryClient which accepts options. Not entirely sure but this probably looks similar to hypergraph/react's internal context for spaces.

const client = new HypergraphClient({ mapping, spaceId });
await client.query(Address)
Appendix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the internal implementation linked in the appendix, packages/hypergraph-react/src/internal/use-query-public.tsx at line 384, and trace how useQuery builds schema queries, mappings, spaces, and filters. Compare the two proposed option designs for supplying mapping and spaceId, then define the async query entry point for server-side rendering and side-effect queries. Done means public graph data can be queried without the React useQuery hook.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.