-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.graphql
102 lines (94 loc) · 2.86 KB
/
schema.graphql
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
102
type User
@auth(
query: "z >> RT.FirebaseID | value | equals[info.context['auth']['user_id']]"
add: "params['firebaseID'] == info.context['auth']['user_id']"
) {
firebaseID: String! @unique
email: String @unique
givenName: String
familyName: String
phone: String
birthday: DateTime
transactions: [Transaction]
@incoming
@relation(source: "Transaction", rt: "User", target: "User")
categories: [Category]
@incoming
@relation(source: "Category", rt: "User", target: "User")
}
enum TransactionType {
EXPENSE
INCOME
}
type Transaction
@auth(
query: "z >> RT.User >> RT.FirebaseID | value | equals[info.context['auth']['user_id']]"
# First path is for creating a new user - weird case. The second path is for
# checking against the user given an ID.
add: """
((params
| get_in['user', 'firebaseID'][None]
| equals[info.context['auth']['user_id']]
| collect)
or
(info.context['g']
| now
| all[ET.User]
| filter[uid | equals[params | get_in['user','id'][None] | collect]]
| filter[Z >> RT.FirebaseID | value | equals[info.context['auth']['user_id']]]
| length
| equals[1]
| collect))
"""
# Alternatively:
# add: """gql_query('queryUser(filter: {id: {eq: $id}, firebaseID: {eq: $firebase}}) {
# id
# }', id=params['user']['id'], firebase=info.context['auth']['user_id'])"""
# update: """(And[Z >> RT.User >> RT.FirebaseID | value | equals[info.context['auth']['user_id']] | collect]
# [params | get_in['input', 'user', 'id'][None] | contained_in[[None, info.context['auth']['user_id']]]])"""
) {
user: User!
type: TransactionType! @search
amount: Float! @search
when: DateTime @search
category: Category
comment: String
}
enum CategoryType {
DEFAULT
PRIVATE
}
type Category
@auth(
query: """
(Or[Z >> O[RT.User] >> O[RT.FirebaseID] | value_or[None] | equals[info.context['auth']['user_id']]]
[Z >> RT.Type | value | equals[EN.CategoryType.DEFAULT]])
"""
) {
type: CategoryType! @search
user: User
title: String!
titleLangEn: String
titleLangJa: String
description: String
descriptionLangEn: String
descriptionLangJa: String
color: String
icon: String
transactions: [Transaction] @incoming @relation(rt: Category)
createdAt: DateTime!
}
type Company {
name: String! @search
description: String
categories: [Category]
}
# Dgraph.Authorization {"JWKUrl":"https://www.googleapis.com/service_accounts/v1/jwk/[email protected]", "Namespace": "https://dgraph.io/jwt/claims", "Audience": ["ikura-9437c"], "Header": "X-Auth-Token"}
type _Auth
@details(
JWKURL: "https://www.googleapis.com/service_accounts/v1/jwk/[email protected]"
Audience: "ikura-9437c"
Header: "X-Auth-Token"
) {
dummy: String
}