@@ -93,14 +93,15 @@ func evalProjectionArray(ctx context.Context, pf ProjectionField, payload []inte
93
93
name = pf .Alias
94
94
}
95
95
96
- if ref , ok := validator .(* schema.Reference ); ok {
96
+ switch fieldType := validator .(type ) {
97
+ case * schema.Reference :
97
98
// Execute sub-request in batch
98
99
e := & In {Field : "id" , Values : payload }
99
100
q := & Query {
100
101
Projection : pf .Children ,
101
102
Predicate : Predicate {e },
102
103
}
103
- rbr .request (ref .Path , q , func (payloads []map [string ]interface {}, validator schema.Validator ) error {
104
+ rbr .request (fieldType .Path , q , func (payloads []map [string ]interface {}, validator schema.Validator ) error {
104
105
var v interface {}
105
106
var err error
106
107
for i := range payloads {
@@ -119,14 +120,14 @@ func evalProjectionArray(ctx context.Context, pf ProjectionField, payload []inte
119
120
resMu .Unlock ()
120
121
return nil
121
122
})
122
- } else if dict , ok := validator .( * schema.Dict ); ok {
123
+ case schema.FieldGetter :
123
124
for _ , val := range payload {
124
125
subval , ok := val .(map [string ]interface {})
125
126
if ! ok {
126
- return nil , fmt .Errorf ("%s: invalid value: not a dict" , pf .Name )
127
+ return nil , fmt .Errorf ("%s: invalid value: not a dict/object " , pf .Name )
127
128
}
128
129
var err error
129
- if subval , err = evalProjection (ctx , pf .Children , subval , dict , rbr ); err != nil {
130
+ if subval , err = evalProjection (ctx , pf .Children , subval , fieldType , rbr ); err != nil {
130
131
return nil , fmt .Errorf ("%s.%v" , pf .Name , err )
131
132
}
132
133
var v interface {}
@@ -135,12 +136,12 @@ func evalProjectionArray(ctx context.Context, pf ProjectionField, payload []inte
135
136
}
136
137
res = append (res , v )
137
138
}
138
- } else if array , ok := validator .( * schema.Array ); ok {
139
+ case * schema.Array :
139
140
for i , val := range payload {
140
141
if subval , ok := val .([]interface {}); ok {
141
142
var err error
142
143
var subvalp * []interface {}
143
- if subvalp , err = evalProjectionArray (ctx , pf , subval , & array .Values , rbr ); err != nil {
144
+ if subvalp , err = evalProjectionArray (ctx , pf , subval , & fieldType .Values , rbr ); err != nil {
144
145
return nil , fmt .Errorf ("%s: error applying projection on array item #%d: %v" , pf .Name , i , err )
145
146
}
146
147
var v interface {}
@@ -152,26 +153,8 @@ func evalProjectionArray(ctx context.Context, pf ProjectionField, payload []inte
152
153
return nil , fmt .Errorf ("%s. is not an array" , pf .Name )
153
154
}
154
155
}
155
- } else {
156
- for _ , val := range payload {
157
- subval , ok := val .(map [string ]interface {})
158
- if ! ok {
159
- return nil , fmt .Errorf ("%s: invalid value: not a dict" , pf .Name )
160
- }
161
- if fg , ok := validator .(schema.FieldGetter ); ok {
162
- var err error
163
- if subval , err = evalProjection (ctx , pf .Children , subval , fg , rbr ); err != nil {
164
- return nil , fmt .Errorf ("%s.%v" , pf .Name , err )
165
- }
166
- var v interface {}
167
- if v , err = resolveFieldHandler (ctx , pf , def , subval ); err != nil {
168
- return nil , err
169
- }
170
- res = append (res , v )
171
- } else {
172
- return nil , fmt .Errorf ("%s. is not an object" , pf .Name )
173
- }
174
- }
156
+ default :
157
+ return nil , fmt .Errorf ("%s. unknown field type" , pf .Name )
175
158
}
176
159
177
160
return resp , nil
0 commit comments