Skip to content

Commit 4bf4626

Browse files
authored
schema improvements (#547)
1 parent 9f74a13 commit 4bf4626

24 files changed

Lines changed: 244 additions & 266 deletions

File tree

.changeset/icy-emus-tap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class User extends Entity.Class<User>('User')({
1515

1616
After:
1717
```ts
18-
export const User = EntitySchema(
18+
export const User = Entity.Schema(
1919
{ name: Type.String },
2020
{
2121
types: [Id('bffa181e-a333-495b-949c-57f2831d7eca')],

apps/events/src/schema.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { EntitySchema, Id, Type } from '@graphprotocol/hypergraph';
1+
import { Entity, Id, Type } from '@graphprotocol/hypergraph';
22

3-
export const User = EntitySchema(
3+
export const User = Entity.Schema(
44
{ name: Type.String },
55
{
66
types: [Id('bffa181e-a333-495b-949c-57f2831d7eca')],
@@ -10,7 +10,7 @@ export const User = EntitySchema(
1010
},
1111
);
1212

13-
export const Todo = EntitySchema(
13+
export const Todo = Entity.Schema(
1414
{
1515
name: Type.String,
1616
completed: Type.Boolean,
@@ -26,7 +26,7 @@ export const Todo = EntitySchema(
2626
},
2727
);
2828

29-
export const Todo2 = EntitySchema(
29+
export const Todo2 = Entity.Schema(
3030
{
3131
name: Type.String,
3232
checked: Type.Boolean,
@@ -50,7 +50,7 @@ export const Todo2 = EntitySchema(
5050
},
5151
);
5252

53-
export const JobOffer = EntitySchema(
53+
export const JobOffer = Entity.Schema(
5454
{
5555
name: Type.String,
5656
salary: Type.Number,
@@ -64,7 +64,7 @@ export const JobOffer = EntitySchema(
6464
},
6565
);
6666

67-
export const Company = EntitySchema(
67+
export const Company = Entity.Schema(
6868
{
6969
name: Type.String,
7070
jobOffers: Type.Relation(JobOffer),
@@ -78,7 +78,7 @@ export const Company = EntitySchema(
7878
},
7979
);
8080

81-
export const Event = EntitySchema(
81+
export const Event = Entity.Schema(
8282
{
8383
name: Type.String,
8484
description: Type.optional(Type.String),
@@ -94,7 +94,7 @@ export const Event = EntitySchema(
9494
},
9595
);
9696

97-
export const Image = EntitySchema(
97+
export const Image = Entity.Schema(
9898
{
9999
url: Type.String,
100100
},
@@ -106,7 +106,7 @@ export const Image = EntitySchema(
106106
},
107107
);
108108

109-
export const Project = EntitySchema(
109+
export const Project = Entity.Schema(
110110
{
111111
name: Type.String,
112112
description: Type.optional(Type.String),

apps/privy-login-example/src/schema.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { EntitySchema, Id, Type } from '@graphprotocol/hypergraph';
1+
import { Entity, Id, Type } from '@graphprotocol/hypergraph';
22

3-
export const User = EntitySchema(
3+
export const User = Entity.Schema(
44
{ name: Type.String },
55
{
66
types: [Id('bffa181e-a333-495b-949c-57f2831d7eca')],
@@ -10,7 +10,7 @@ export const User = EntitySchema(
1010
},
1111
);
1212

13-
export const Todo = EntitySchema(
13+
export const Todo = Entity.Schema(
1414
{
1515
name: Type.String,
1616
completed: Type.Boolean,
@@ -26,7 +26,7 @@ export const Todo = EntitySchema(
2626
},
2727
);
2828

29-
export const Todo2 = EntitySchema(
29+
export const Todo2 = Entity.Schema(
3030
{
3131
name: Type.String,
3232
checked: Type.Boolean,
@@ -50,7 +50,7 @@ export const Todo2 = EntitySchema(
5050
},
5151
);
5252

53-
export const JobOffer = EntitySchema(
53+
export const JobOffer = Entity.Schema(
5454
{
5555
name: Type.String,
5656
salary: Type.Number,
@@ -64,7 +64,7 @@ export const JobOffer = EntitySchema(
6464
},
6565
);
6666

67-
export const Company = EntitySchema(
67+
export const Company = Entity.Schema(
6868
{
6969
name: Type.String,
7070
jobOffers: Type.Relation(JobOffer),
@@ -78,7 +78,7 @@ export const Company = EntitySchema(
7878
},
7979
);
8080

81-
export const Event = EntitySchema(
81+
export const Event = Entity.Schema(
8282
{
8383
name: Type.String,
8484
description: Type.optional(Type.String),
@@ -94,7 +94,7 @@ export const Event = EntitySchema(
9494
},
9595
);
9696

97-
export const Image = EntitySchema(
97+
export const Image = Entity.Schema(
9898
{
9999
url: Type.String,
100100
},
@@ -106,7 +106,7 @@ export const Image = EntitySchema(
106106
},
107107
);
108108

109-
export const Project = EntitySchema(
109+
export const Project = Entity.Schema(
110110
{
111111
name: Type.String,
112112
description: Type.optional(Type.String),

apps/template-nextjs/app/schema.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { EntitySchema, Id, Type } from '@graphprotocol/hypergraph';
1+
import { Entity, Id, Type } from '@graphprotocol/hypergraph';
22

3-
export const Image = EntitySchema(
3+
export const Image = Entity.Schema(
44
{
55
url: Type.String,
66
},
@@ -12,7 +12,7 @@ export const Image = EntitySchema(
1212
},
1313
);
1414

15-
export const Project = EntitySchema(
15+
export const Project = Entity.Schema(
1616
{
1717
name: Type.String,
1818
description: Type.optional(Type.String),
@@ -30,7 +30,7 @@ export const Project = EntitySchema(
3030
},
3131
);
3232

33-
export const Dapp = EntitySchema(
33+
export const Dapp = Entity.Schema(
3434
{
3535
name: Type.String,
3636
description: Type.optional(Type.String),
@@ -50,7 +50,7 @@ export const Dapp = EntitySchema(
5050
},
5151
);
5252

53-
export const Investor = EntitySchema(
53+
export const Investor = Entity.Schema(
5454
{
5555
name: Type.String,
5656
},
@@ -62,7 +62,7 @@ export const Investor = EntitySchema(
6262
},
6363
);
6464

65-
export const FundingStage = EntitySchema(
65+
export const FundingStage = Entity.Schema(
6666
{
6767
name: Type.String,
6868
},
@@ -74,7 +74,7 @@ export const FundingStage = EntitySchema(
7474
},
7575
);
7676

77-
export const InvestmentRound = EntitySchema(
77+
export const InvestmentRound = Entity.Schema(
7878
{
7979
name: Type.String,
8080
raisedAmount: Type.optional(Type.Number),
@@ -94,7 +94,7 @@ export const InvestmentRound = EntitySchema(
9494
},
9595
);
9696

97-
export const Asset = EntitySchema(
97+
export const Asset = Entity.Schema(
9898
{
9999
name: Type.String,
100100
symbol: Type.optional(Type.String),

apps/template-vite-react/src/schema.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { EntitySchema, Id, Type } from '@graphprotocol/hypergraph';
1+
import { Entity, Id, Type } from '@graphprotocol/hypergraph';
22

3-
export const Image = EntitySchema(
3+
export const Image = Entity.Schema(
44
{
55
url: Type.String,
66
},
@@ -12,7 +12,7 @@ export const Image = EntitySchema(
1212
},
1313
);
1414

15-
export const Project = EntitySchema(
15+
export const Project = Entity.Schema(
1616
{
1717
name: Type.String,
1818
description: Type.optional(Type.String),
@@ -30,7 +30,7 @@ export const Project = EntitySchema(
3030
},
3131
);
3232

33-
export const Dapp = EntitySchema(
33+
export const Dapp = Entity.Schema(
3434
{
3535
name: Type.String,
3636
description: Type.optional(Type.String),
@@ -50,7 +50,7 @@ export const Dapp = EntitySchema(
5050
},
5151
);
5252

53-
export const Investor = EntitySchema(
53+
export const Investor = Entity.Schema(
5454
{
5555
name: Type.String,
5656
},
@@ -62,7 +62,7 @@ export const Investor = EntitySchema(
6262
},
6363
);
6464

65-
export const FundingStage = EntitySchema(
65+
export const FundingStage = Entity.Schema(
6666
{
6767
name: Type.String,
6868
},
@@ -74,7 +74,7 @@ export const FundingStage = EntitySchema(
7474
},
7575
);
7676

77-
export const InvestmentRound = EntitySchema(
77+
export const InvestmentRound = Entity.Schema(
7878
{
7979
name: Type.String,
8080
raisedAmount: Type.optional(Type.Number),
@@ -94,7 +94,7 @@ export const InvestmentRound = EntitySchema(
9494
},
9595
);
9696

97-
export const Asset = EntitySchema(
97+
export const Asset = Entity.Schema(
9898
{
9999
name: Type.String,
100100
symbol: Type.optional(Type.String),

docs/docs/filtering-query-results.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ The filter API allows you to filter the results of a query by property values an
55
## Filtering by property values
66

77
```tsx
8-
export class Event extends Entity.Class<Event>("Event")({
9-
name: Type.String,
10-
cancelled: Type.Boolean,
11-
}) {}
8+
export const Event = Entity.Schema(
9+
{ name: Type.String, cancelled: Type.Boolean },
10+
{
11+
types: [Id('event-type-id')],
12+
properties: { name: Id('name-property-id'), cancelled: Id('cancelled-property-id') },
13+
},
14+
);
1215

1316
// inside the React component
1417
const { data } = useEntities(Event, {
@@ -128,11 +131,17 @@ const { data } = useEntities(Person, {
128131

129132
```tsx
130133
// schema
131-
export class Todo extends Entity.Class<Todo2>('Todo')({
132-
name: Type.String,
133-
checked: Type.Boolean,
134-
assignees: Type.Relation(User),
135-
})
134+
export const Todo = Entity.Schema(
135+
{ name: Type.String, checked: Type.Boolean, assignees: Type.Relation(User) },
136+
{
137+
types: [Id('todo-type-id')],
138+
properties: {
139+
name: Id('name-property-id'),
140+
checked: Id('checked-property-id'),
141+
assignees: Id('assignees-property-id'),
142+
},
143+
},
144+
);
136145
```
137146

138147
1 level filtering
@@ -171,15 +180,17 @@ const { data } = useEntities(Person, {
171180

172181
```tsx
173182
// schema
174-
export class Todo extends Entity.Class<Todo2>('Todo')({
175-
name: Type.String,
176-
checked: Type.Boolean,
177-
assignees: Type.Relation(User, {
178-
entity: {
179-
assignedAt: Type.DateTime,
180-
}
181-
}),
182-
})
183+
export const Todo = Entity.Schema(
184+
{ name: Type.String, checked: Type.Boolean, assignees: Type.Relation(User) },
185+
{
186+
types: [Id('todo-type-id')],
187+
properties: {
188+
name: Id('name-property-id'),
189+
checked: Id('checked-property-id'),
190+
assignees: Id('assignees-property-id'),
191+
},
192+
},
193+
);
183194
```
184195

185196
```tsx

docs/docs/mapping.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)