-
Notifications
You must be signed in to change notification settings - Fork 118
/
node_object.go
132 lines (114 loc) · 2.96 KB
/
node_object.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package resolve
import (
"slices"
)
type Object struct {
Nullable bool
Path []string
Fields []*Field
Fetch Fetch
UnescapeResponseJson bool `json:"unescape_response_json,omitempty"`
}
func (o *Object) HasChildFetches() bool {
for i := range o.Fields {
switch t := o.Fields[i].Value.(type) {
case *Object:
if t.Fetch != nil {
return true
}
if t.HasChildFetches() {
return true
}
case *Array:
switch at := t.Item.(type) {
case *Object:
if at.Fetch != nil {
return true
}
if at.HasChildFetches() {
return true
}
case *Array:
if at.HasChildFetches() {
return true
}
}
}
}
return false
}
func (_ *Object) NodeKind() NodeKind {
return NodeKindObject
}
func (o *Object) NodePath() []string {
return o.Path
}
func (o *Object) NodeNullable() bool {
return o.Nullable
}
type EmptyObject struct{}
func (_ *EmptyObject) NodeKind() NodeKind {
return NodeKindEmptyObject
}
func (_ *EmptyObject) NodePath() []string {
return nil
}
func (_ *EmptyObject) NodeNullable() bool {
return false
}
type Field struct {
Name []byte
Value Node
Position Position
Defer *DeferField
Stream *StreamField
OnTypeNames [][]byte
SkipDirectiveDefined bool
SkipVariableName string
IncludeDirectiveDefined bool
IncludeVariableName string
Info *FieldInfo
}
type FieldInfo struct {
// Name is the name of the field.
Name string
ExactParentTypeName string
// ParentTypeNames is the list of possible parent types for this field.
// E.g. for a root field, this will be Query, Mutation, Subscription.
// For a field on an object type, this will be the name of that object type.
// For a field on an interface type, this will be the name of that interface type and all of its possible implementations.
ParentTypeNames []string
// NamedType is the underlying node type of the field.
// E.g. for a field of type Hobby! this will be Hobby.
// For a field of type [Hobby] this will be Hobby.
// For a field of type [Hobby!]! this will be Hobby.
// For scalar fields, this will return string, int, float, boolean, ID.
NamedType string
Source TypeFieldSource
FetchID int
// HasAuthorizationRule needs to be set to true if the Authorizer should be called for this field
HasAuthorizationRule bool
}
func (i *FieldInfo) Merge(other *FieldInfo) {
for _, name := range other.ParentTypeNames {
if !slices.Contains(i.ParentTypeNames, name) {
i.ParentTypeNames = append(i.ParentTypeNames, name)
}
}
for _, sourceID := range other.Source.IDs {
if !slices.Contains(i.Source.IDs, sourceID) {
i.Source.IDs = append(i.Source.IDs, sourceID)
}
}
}
type TypeFieldSource struct {
IDs []string
}
type Position struct {
Line uint32
Column uint32
}
type StreamField struct {
InitialBatchSize int
}
type DeferField struct{}