Skip to content

Async functions for querying public graph #438

@baiirun

Description

@baiirun

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions