add backlinksTotalCountsTypeId1 - #554
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a temporary backlinksTotalCountsTypeId1 parameter to entity query functions to enable fetching backlink total counts for a specific type ID. The feature is added to Entity.findManyPublic and the useEntities React hook.
Key changes:
- Added
backlinksTotalCountsTypeId1optional parameter to all GraphQL queries with conditional inclusion via@includedirective - Extended return types to include the backlink count in entity results
- Propagated the parameter through React hooks and TypeScript type definitions
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/hypergraph/src/entity/find-many-public.ts | Added backlinksTotalCountsTypeId1 parameter to all 6 GraphQL queries (3 levels × 2 variants), updated types, and added variable handling logic |
| packages/hypergraph/src/entity/search-many-public.ts | Added @ts-expect-error comment due to type mismatch with parseResult function |
| packages/hypergraph-react/src/internal/use-entities-public.tsx | Propagated backlinksTotalCountsTypeId1 parameter to query key and function call |
| packages/hypergraph-react/src/internal/types.ts | Added backlinksTotalCountsTypeId1 to QueryPublicParams type |
| packages/hypergraph-react/src/hooks/use-entities.tsx | Added parameter to hook and type cast for return data |
| apps/events/src/routes/podcasts.lazy.tsx | Example usage showing the new parameter and displaying backlink counts; import order changed |
| .changeset/kind-peas-sniff.md | Documented the change as a patch |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // @ts-expect-error TODO: fix this | ||
| const { data, invalidEntities } = parseResult({ entities: result.search }, type); |
There was a problem hiding this comment.
The parseResult function expects entities with a backlinksTotalCountsTypeId1 field in EntityQueryResult, but SearchQueryResult doesn't include this field. This causes a type error that's being suppressed. To fix this, either add backlinksTotalCountsTypeId1 support to the search queries (similar to find-many-public.ts lines 45-47, 72-74, etc.) or create a separate parse function for search results that doesn't expect this field.
| const schemaWithId = Utils.addIdSchemaField(type); | ||
| const decode = Schema.decodeUnknownEither(schemaWithId); | ||
| const data: Entity.Entity<S>[] = []; | ||
| const data: (Entity.Entity<S> & { backlinksTotalCountsTypeId1?: number })[] = []; |
There was a problem hiding this comment.
[nitpick] The return type intersection Entity.Entity<S> & { backlinksTotalCountsTypeId1?: number } is duplicated in multiple places (lines 443 and 46 in use-entities.tsx). Consider defining a reusable type alias like type EntityWithBacklinkCount<S> = Entity.Entity<S> & { backlinksTotalCountsTypeId1?: number } to improve maintainability.
| return { | ||
| ...publicResult, | ||
| data: localResult.entities, | ||
| data: localResult.entities as (Entity.Entity<S> & { backlinksTotalCountsTypeId1?: number })[], |
There was a problem hiding this comment.
The type cast assumes local (private mode) entities will have backlinksTotalCountsTypeId1, but this field is only populated in public mode queries via findManyPublic. Local entities retrieved through useEntitiesPrivate won't have this field, making this cast potentially misleading. The field should be marked as optional and only expected when mode === 'public'.
No description provided.