Skip to content

Conversation

nikgraf
Copy link
Collaborator

@nikgraf nikgraf commented Aug 6, 2025

No description provided.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds filtering support for public queries by extending the public query functionality to accept and process filter parameters, enabling users to filter entities retrieved from the public GraphQL API.

Key changes:

  • Removed the equals property from EntityStringFilter type and added filter parameter support to public queries
  • Added a new utility function to translate internal filter formats to GraphQL filter syntax
  • Updated documentation and examples to reflect the new filtering capabilities

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/hypergraph/src/entity/types.ts Removes the equals property from EntityStringFilter type definition
packages/hypergraph-react/src/use-query.tsx Adds filter parameter to public query calls
packages/hypergraph-react/src/internal/use-query-public.tsx Integrates filter translation and adds filter parameter to GraphQL queries
packages/hypergraph-react/src/internal/types.ts Adds filter parameter to QueryPublicParams type
packages/hypergraph-react/src/internal/translate-filter-to-graphql.ts New utility function to convert internal filters to GraphQL format
packages/hypergraph-react/src/internal/translate-filter-to-graphql.test.ts Comprehensive test suite for the filter translation functionality
docs/docs/filtering-query-results.md Updates documentation examples to use is instead of equals and fixes syntax
apps/events/src/components/playground.tsx Adds commented example of filter usage

Comment on lines +42 to +49
): GraphqlFilterEntry {
if (!filter) {
return {};
}

// @ts-expect-error TODO should use the actual type instead of the name in the mapping
const typeName = type.name;

Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @ts-expect-error comment indicates this is a known issue that should be addressed. Consider using a proper type-safe way to extract the type name instead of relying on a potentially unsafe property access.

Suggested change
): GraphqlFilterEntry {
if (!filter) {
return {};
}
// @ts-expect-error TODO should use the actual type instead of the name in the mapping
const typeName = type.name;
typeName: string,
): GraphqlFilterEntry {
if (!filter) {
return {};
}

Copilot uses AI. Check for mistakes.

for (const [fieldName, fieldFilter] of Object.entries(filter)) {
if (fieldName === 'or') {
graphqlFilter.push({
or: fieldFilter.map((filter: Entity.EntityFilter<S>) => translateFilterToGraphql(filter, type, mapping)),
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation Entity.EntityFilter<S> may be incorrect. Based on the context, this should likely be the same type as the input filter parameter for consistency with the recursive call structure.

Suggested change
or: fieldFilter.map((filter: Entity.EntityFilter<S>) => translateFilterToGraphql(filter, type, mapping)),
or: fieldFilter.map((filter: { [K in keyof Schema.Schema.Type<S>]?: Entity.EntityFieldFilter<Schema.Schema.Type<S>[K]> } | undefined) => translateFilterToGraphql(filter, type, mapping)),

Copilot uses AI. Check for mistakes.

@nikgraf nikgraf changed the title public value filtering add value filtering for useQuery(Type, { mode: "public", … }) Aug 6, 2025
@nikgraf nikgraf self-assigned this Aug 6, 2025
@nikgraf nikgraf requested a review from cmwhited August 6, 2025 19:51
Copy link
Collaborator

@cmwhited cmwhited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment to consider. But great work on this


const mappingEntry = mapping[typeName];
if (!mappingEntry) {
throw new Error(`Mapping entry for ${typeName} not found`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it better to just return null or an empty object here instead of throwing an error? not sure which way I would lean. but wanted to raise it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, good question

my thinking was: if we silently ignore mapping issues we might confuse a lot of people e.g. you filter for name starts with Chris and then you get a lot of non Chris entries. By throwing an error you instantly get strong feedback that your mapping is wrong. Personally with the mapping changes I would love to have feedback right at the app start (maybe just console.errors in prod and throwing errors in dev?). Maybe that's also something we should do here?

What do you think?

@nikgraf nikgraf merged commit 4410012 into main Aug 7, 2025
6 checks passed
@nikgraf nikgraf deleted the ng/public-value-filtering branch August 7, 2025 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants