Skip to content

Commit

Permalink
allow resolvers as pointer methods
Browse files Browse the repository at this point in the history
fix #301
  • Loading branch information
gracenoah authored and chris-ramon committed Mar 24, 2018
1 parent 87d1ac4 commit 72ff732
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,20 +832,20 @@ type FieldResolver interface {
// and returns it as the result, or if it's a function, returns the result
// of calling that function.
func DefaultResolveFn(p ResolveParams) (interface{}, error) {
// try to resolve p.Source as a struct first
sourceVal := reflect.ValueOf(p.Source)
// Check if value implements 'Resolver' interface
if resolver, ok := sourceVal.Interface().(FieldResolver); ok {
return resolver.Resolve(p)
}

// try to resolve p.Source as a struct
if sourceVal.IsValid() && sourceVal.Type().Kind() == reflect.Ptr {
sourceVal = sourceVal.Elem()
}
if !sourceVal.IsValid() {
return nil, nil
}

// Check if value implements 'Resolver' interface
if resolver, ok := sourceVal.Interface().(FieldResolver); ok {
return resolver.Resolve(p)
}

if sourceVal.Type().Kind() == reflect.Struct {
for i := 0; i < sourceVal.NumField(); i++ {
valueField := sourceVal.Field(i)
Expand Down

0 comments on commit 72ff732

Please sign in to comment.