@@ -208,7 +208,8 @@ func makeScalarExec(t *schema.Scalar, resolverType reflect.Type) (Resolvable, er
208
208
return & Scalar {}, nil
209
209
}
210
210
211
- func (b * execBuilder ) makeObjectExec (typeName string , fields schema.FieldList , possibleTypes []* schema.Object , nonNull bool , resolverType reflect.Type ) (* Object , error ) {
211
+ func (b * execBuilder ) makeObjectExec (typeName string , fields schema.FieldList , possibleTypes []* schema.Object ,
212
+ nonNull bool , resolverType reflect.Type ) (* Object , error ) {
212
213
213
214
if ! nonNull {
214
215
if resolverType .Kind () != reflect .Ptr && resolverType .Kind () != reflect .Interface {
@@ -219,19 +220,22 @@ func (b *execBuilder) makeObjectExec(typeName string, fields schema.FieldList, p
219
220
methodHasReceiver := resolverType .Kind () != reflect .Interface
220
221
221
222
Fields := make (map [string ]* Field )
223
+ rt := unwrapPtr (resolverType )
222
224
for _ , f := range fields {
223
225
methodIndex := - 1
224
226
fieldIndex := - 1
225
- rt := unwrapPtr (resolverType )
226
227
227
228
/**
228
- * 1) Use resolver type's method for
229
+ * 1) Use resolver type's method when
229
230
* 1.1) __Type and __Schema requests
230
- * 1.2) or when field has arguments
231
+ * 1.2) or field has arguments
231
232
* 1.3) or it is configured to use method
233
+ * 1.4) or it is an interface
232
234
* 2) Otherwise use resolver type's field
233
235
*/
234
- if isResolverSchemaOrType (rt ) == true || len (f .Args ) > 0 || conf .UseResolverMethods == true {
236
+ //fmt.Printf("resName=%s, fName=%s\n", rt.Name(), f.Name)
237
+ if isResolverSchemaOrType (rt ) == true || len (f .Args ) > 0 ||
238
+ conf .UseResolverMethods == true || rt .Kind () == reflect .Interface {
235
239
methodIndex = findMethod (resolverType , f .Name )
236
240
} else {
237
241
fieldIndex = findField (rt , f .Name )
@@ -259,22 +263,27 @@ func (b *execBuilder) makeObjectExec(typeName string, fields schema.FieldList, p
259
263
Fields [f .Name ] = fe
260
264
}
261
265
266
+ // check type assertions when
267
+ // 1) __Type and __Schema requests
268
+ // 2) or it is configured to use method
262
269
typeAssertions := make (map [string ]* TypeAssertion )
263
- for _ , impl := range possibleTypes {
264
- methodIndex := findMethod (resolverType , "To" + impl .Name )
265
- if methodIndex == - 1 {
266
- return nil , fmt .Errorf ("%s does not resolve %q: missing method %q to convert to %q" , resolverType , typeName , "To" + impl .Name , impl .Name )
267
- }
268
- if resolverType .Method (methodIndex ).Type .NumOut () != 2 {
269
- return nil , fmt .Errorf ("%s does not resolve %q: method %q should return a value and a bool indicating success" , resolverType , typeName , "To" + impl .Name )
270
- }
271
- a := & TypeAssertion {
272
- MethodIndex : methodIndex ,
273
- }
274
- if err := b .assignExec (& a .TypeExec , impl , resolverType .Method (methodIndex ).Type .Out (0 )); err != nil {
275
- return nil , err
270
+ if isResolverSchemaOrType (rt ) == true || conf .UseResolverMethods == true {
271
+ for _ , impl := range possibleTypes {
272
+ methodIndex := findMethod (resolverType , "To" + impl .Name )
273
+ if methodIndex == - 1 {
274
+ return nil , fmt .Errorf ("%s does not resolve %q: missing method %q to convert to %q" , resolverType , typeName , "To" + impl .Name , impl .Name )
275
+ }
276
+ if resolverType .Method (methodIndex ).Type .NumOut () != 2 {
277
+ return nil , fmt .Errorf ("%s does not resolve %q: method %q should return a value and a bool indicating success" , resolverType , typeName , "To" + impl .Name )
278
+ }
279
+ a := & TypeAssertion {
280
+ MethodIndex : methodIndex ,
281
+ }
282
+ if err := b .assignExec (& a .TypeExec , impl , resolverType .Method (methodIndex ).Type .Out (0 )); err != nil {
283
+ return nil , err
284
+ }
285
+ typeAssertions [impl .Name ] = a
276
286
}
277
- typeAssertions [impl .Name ] = a
278
287
}
279
288
280
289
return & Object {
0 commit comments