-
Notifications
You must be signed in to change notification settings - Fork 4
/
message.go
56 lines (47 loc) · 1.31 KB
/
message.go
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
package proto
// IsModelField returns true if the input targets a model field
// and is handled automatically by the runtime.
// This will only be true for inputs that are built-in actions,
// as functions never have this behaviour.
func (f *MessageField) IsModelField() bool {
return len(f.Target) > 0
}
// IsFile tells us if the field is a file
func (f *MessageField) IsFile() bool {
if f.Type == nil {
return false
}
return f.Type.Type == Type_TYPE_FILE
}
// IsMessage checks if the field is a message itself
func (f *MessageField) IsMessage() bool {
return f.Type.Type == Type_TYPE_MESSAGE
}
func (m *Message) FindField(fieldName string) *MessageField {
for _, field := range m.Fields {
if field.Name == fieldName {
return field
}
}
return nil
}
// GetOrderByField returns the orderBy message field, if it has any; otherwise returns nil;
func (m *Message) GetOrderByField() *MessageField {
for _, field := range m.Fields {
if field.Name == "orderBy" && field.Type.Type == Type_TYPE_UNION {
return field
}
}
return nil
}
func messageHasFiles(s *Schema, f *Message) bool {
for _, field := range f.Fields {
if field.Type.MessageName != nil {
message := s.FindMessage(field.Type.MessageName.Value)
return messageHasFiles(s, message)
} else if field.IsFile() {
return true
}
}
return false
}