Skip to content

Commit c476388

Browse files
authored
fix filter types (#486)
1 parent 9ba3aef commit c476388

File tree

8 files changed

+16
-14
lines changed

8 files changed

+16
-14
lines changed

.changeset/new-teams-dig.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@graphprotocol/hypergraph-react": patch
3+
---
4+
5+
fix type for useQuery filter option to allwo for or/not operators
6+

apps/events/src/components/playground.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ export const Playground = ({ spaceId }: { spaceId: string }) => {
1818
},
1919
},
2020
// filter: {
21-
// name: {
22-
// startsWith: 'test',
23-
// },
21+
// or: [{ name: { startsWith: 'test' } }, { name: { startsWith: 'ETH' } }],
2422
// },
2523
first: 100,
2624
space: spaceId,

apps/events/src/components/todos.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import { Button } from './ui/button';
1313
import { Input } from './ui/input';
1414

1515
export const Todos = () => {
16-
const { data: todos } = useQuery(Todo, { mode: 'private', include: { assignees: {} } });
16+
const { data: todos } = useQuery(Todo, {
17+
mode: 'private',
18+
include: { assignees: {} },
19+
// filter: { or: [{ name: { startsWith: 'aa' } }, { name: { is: 'sdasd' } }] },
20+
});
1721
const { data: users } = useQuery(User, { mode: 'private' });
1822
const { ready: spaceReady } = useSpace({ mode: 'private' });
1923
const createEntity = useCreateEntity(Todo);

apps/events/src/mapping.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export const mapping: Mapping = {
66
typeIds: [Id('bffa181e-a333-495b-949c-57f2831d7eca')],
77
properties: {
88
name: Id('c9c79675-850a-42c5-bbbd-9e5c55d3f4e7'),
9-
created: Id('f8df1caf-14b4-4c1e-85fb-4e97f7d7070a'),
109
},
1110
},
1211
Todo: {
@@ -54,8 +53,6 @@ export const mapping: Mapping = {
5453
properties: {
5554
name: Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
5655
description: Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'),
57-
createdAt: Id('e2e6906b-d2b6-48d2-8aa2-54e8b29f6933'),
58-
updatedAt: Id('2e877fe0-a504-4ea0-b43c-210d011db434'),
5956
},
6057
relations: {
6158
sponsors: Id('6860bfac-f703-4289-b789-972d0aaf3abe'),

apps/events/src/schema.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Entity, Type } from '@graphprotocol/hypergraph';
22

33
export class User extends Entity.Class<User>('User')({
44
name: Type.String,
5-
created: Type.Date,
65
}) {}
76

87
export class Todo extends Entity.Class<Todo>('Todo')({
@@ -33,10 +32,8 @@ export class Company extends Entity.Class<Company>('Company')({
3332

3433
export class Event extends Entity.Class<Event>('Event')({
3534
name: Type.String,
36-
description: Type.String,
35+
description: Type.optional(Type.String),
3736
sponsors: Type.Relation(Company),
38-
createdAt: Type.Date,
39-
updatedAt: Type.Date,
4037
}) {}
4138

4239
export class Todo3 extends Entity.Class<Todo3>('Todo3')({

packages/hypergraph-react/src/HypergraphSpaceContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export function useHardDeleteEntity(options?: { space?: string }) {
134134
type QueryParams<S extends Entity.AnyNoContext> = {
135135
space?: string | undefined;
136136
enabled: boolean;
137-
filter?: { [K in keyof Schema.Schema.Type<S>]?: Entity.EntityFieldFilter<Schema.Schema.Type<S>[K]> } | undefined;
137+
filter?: Entity.EntityFilter<Schema.Schema.Type<S>> | undefined;
138138
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
139139
};
140140

packages/hypergraph-react/src/internal/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type * as Schema from 'effect/Schema';
44
export type QueryPublicParams<S extends Entity.AnyNoContext> = {
55
enabled: boolean;
66
space?: string | undefined;
7-
filter?: { [K in keyof Schema.Schema.Type<S>]?: Entity.EntityFieldFilter<Schema.Schema.Type<S>[K]> } | undefined;
7+
filter?: Entity.EntityFilter<Schema.Schema.Type<S>> | undefined;
88
// TODO: for multi-level nesting it should only allow the allowed properties instead of Record<string, Record<string, never>>
99
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
1010
first?: number | undefined;

packages/hypergraph-react/src/use-query.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useQueryPublic } from './internal/use-query-public.js';
55

66
type QueryParams<S extends Entity.AnyNoContext> = {
77
mode: 'public' | 'private';
8-
filter?: { [K in keyof Schema.Schema.Type<S>]?: Entity.EntityFieldFilter<Schema.Schema.Type<S>[K]> } | undefined;
8+
filter?: Entity.EntityFilter<Schema.Schema.Type<S>> | undefined;
99
// TODO: for multi-level nesting it should only allow the allowed properties instead of Record<string, Record<string, never>>
1010
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
1111
space?: string | undefined;

0 commit comments

Comments
 (0)