-
Notifications
You must be signed in to change notification settings - Fork 24
/
default.esdl
101 lines (86 loc) · 2.23 KB
/
default.esdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#
# Copyright (c) 2019 MagicStack Inc.
# All rights reserved.
#
# See LICENSE for details.
##
using extension graphql;
using extension edgeql_http;
module default {
abstract type HasImage {
required property image -> str; # a URL to the image
index on (.image);
}
type User extending HasImage {
required property name -> str;
}
type Review {
required property body -> str;
required property rating -> int64 {
constraint min_value(0);
constraint max_value(5);
}
required link author -> User;
required link movie -> Movie;
required property creation_time -> cal::local_datetime {
default := cal::to_local_datetime(datetime_current(), 'UTC')
}
}
type Person extending HasImage {
required property first_name -> str;
required property middle_name -> str {
default := '';
}
required property last_name -> str;
property full_name :=
(
.first_name ++ ' ' ++
(
(.middle_name ++ ' ')
IF .middle_name != '' ELSE
''
) ++
.last_name
);
property bio -> str;
}
abstract link crew {
# Provide a way to specify some "natural" ordering, as relevant to
# the movie. This may be order of importance, appearance, etc.
property list_order -> int64;
}
abstract link directors extending crew;
abstract link cast extending crew;
type Movie extending HasImage {
required property title -> str;
required property year -> int64;
required property description -> str;
multi link directors extending crew -> Person;
multi link cast extending crew -> Person;
property avg_rating := math::mean(.<movie[IS Review].rating);
}
# GraphQL helper types
alias GraphQLUserDetails := (
select User {
latest_reviews := (
select User.<author[is Review]
order by .creation_time desc
)
}
);
alias GraphQLPersonDetails := (
with module default
select Person {
acted_in := ( select Person.<cast[is Movie] ),
directed := ( select Person.<directors[IS Movie] )
}
);
alias GraphQLMovieDetails := (
with module default
select Movie {
reviews := (
select Movie.<movie[is Review]
),
}
);
}