Skip to content

Commit 27d83de

Browse files
authored
Merge pull request #403 from graphql-factory/master
exposing Path in ResolveInfo to follow the reference implementation
2 parents cc8e9a9 + 17eefea commit 27d83de

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

definition.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ type FieldResolveFn func(p ResolveParams) (interface{}, error)
582582
type ResolveInfo struct {
583583
FieldName string
584584
FieldASTs []*ast.Field
585+
Path *ResponsePath
585586
ReturnType Output
586587
ParentType Composite
587588
Schema Schema
@@ -1289,21 +1290,21 @@ func assertValidName(name string) error {
12891290

12901291
}
12911292

1292-
type responsePath struct {
1293-
Prev *responsePath
1293+
type ResponsePath struct {
1294+
Prev *ResponsePath
12941295
Key interface{}
12951296
}
12961297

12971298
// WithKey returns a new responsePath containing the new key.
1298-
func (p *responsePath) WithKey(key interface{}) *responsePath {
1299-
return &responsePath{
1299+
func (p *ResponsePath) WithKey(key interface{}) *ResponsePath {
1300+
return &ResponsePath{
13001301
Prev: p,
13011302
Key: key,
13021303
}
13031304
}
13041305

13051306
// AsArray returns an array of path keys.
1306-
func (p *responsePath) AsArray() []interface{} {
1307+
func (p *ResponsePath) AsArray() []interface{} {
13071308
if p == nil {
13081309
return nil
13091310
}

executor.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ type executeFieldsParams struct {
224224
ParentType *Object
225225
Source interface{}
226226
Fields map[string][]*ast.Field
227-
Path *responsePath
227+
Path *ResponsePath
228228
}
229229

230230
// Implements the "Evaluating selection sets" section of the spec for "write" mode.
@@ -559,7 +559,7 @@ type resolveFieldResultState struct {
559559
hasNoFieldDefs bool
560560
}
561561

562-
func handleFieldError(r interface{}, fieldNodes []ast.Node, path *responsePath, returnType Output, eCtx *executionContext) {
562+
func handleFieldError(r interface{}, fieldNodes []ast.Node, path *ResponsePath, returnType Output, eCtx *executionContext) {
563563
err := NewLocatedErrorWithPath(r, fieldNodes, path.AsArray())
564564
// send panic upstream
565565
if _, ok := returnType.(*NonNull); ok {
@@ -572,7 +572,7 @@ func handleFieldError(r interface{}, fieldNodes []ast.Node, path *responsePath,
572572
// figures out the value that the field returns by calling its resolve function,
573573
// then calls completeValue to complete promises, serialize scalars, or execute
574574
// the sub-selection-set for objects.
575-
func resolveField(eCtx *executionContext, parentType *Object, source interface{}, fieldASTs []*ast.Field, path *responsePath) (result interface{}, resultState resolveFieldResultState) {
575+
func resolveField(eCtx *executionContext, parentType *Object, source interface{}, fieldASTs []*ast.Field, path *ResponsePath) (result interface{}, resultState resolveFieldResultState) {
576576
// catch panic from resolveFn
577577
var returnType Output
578578
defer func() (interface{}, resolveFieldResultState) {
@@ -608,6 +608,7 @@ func resolveField(eCtx *executionContext, parentType *Object, source interface{}
608608
info := ResolveInfo{
609609
FieldName: fieldName,
610610
FieldASTs: fieldASTs,
611+
Path: path,
611612
ReturnType: returnType,
612613
ParentType: parentType,
613614
Schema: eCtx.Schema,
@@ -634,7 +635,7 @@ func resolveField(eCtx *executionContext, parentType *Object, source interface{}
634635
return completed, resultState
635636
}
636637

637-
func completeValueCatchingError(eCtx *executionContext, returnType Type, fieldASTs []*ast.Field, info ResolveInfo, path *responsePath, result interface{}) (completed interface{}) {
638+
func completeValueCatchingError(eCtx *executionContext, returnType Type, fieldASTs []*ast.Field, info ResolveInfo, path *ResponsePath, result interface{}) (completed interface{}) {
638639
// catch panic
639640
defer func() interface{} {
640641
if r := recover(); r != nil {
@@ -652,7 +653,7 @@ func completeValueCatchingError(eCtx *executionContext, returnType Type, fieldAS
652653
return completed
653654
}
654655

655-
func completeValue(eCtx *executionContext, returnType Type, fieldASTs []*ast.Field, info ResolveInfo, path *responsePath, result interface{}) interface{} {
656+
func completeValue(eCtx *executionContext, returnType Type, fieldASTs []*ast.Field, info ResolveInfo, path *ResponsePath, result interface{}) interface{} {
656657

657658
resultVal := reflect.ValueOf(result)
658659
if resultVal.IsValid() && resultVal.Kind() == reflect.Func {
@@ -719,7 +720,7 @@ func completeValue(eCtx *executionContext, returnType Type, fieldASTs []*ast.Fie
719720
return nil
720721
}
721722

722-
func completeThunkValueCatchingError(eCtx *executionContext, returnType Type, fieldASTs []*ast.Field, info ResolveInfo, path *responsePath, result interface{}) (completed interface{}) {
723+
func completeThunkValueCatchingError(eCtx *executionContext, returnType Type, fieldASTs []*ast.Field, info ResolveInfo, path *ResponsePath, result interface{}) (completed interface{}) {
723724

724725
// catch any panic invoked from the propertyFn (thunk)
725726
defer func() {
@@ -751,7 +752,7 @@ func completeThunkValueCatchingError(eCtx *executionContext, returnType Type, fi
751752

752753
// completeAbstractValue completes value of an Abstract type (Union / Interface) by determining the runtime type
753754
// of that value, then completing based on that type.
754-
func completeAbstractValue(eCtx *executionContext, returnType Abstract, fieldASTs []*ast.Field, info ResolveInfo, path *responsePath, result interface{}) interface{} {
755+
func completeAbstractValue(eCtx *executionContext, returnType Abstract, fieldASTs []*ast.Field, info ResolveInfo, path *ResponsePath, result interface{}) interface{} {
755756

756757
var runtimeType *Object
757758

@@ -788,7 +789,7 @@ func completeAbstractValue(eCtx *executionContext, returnType Abstract, fieldAST
788789
}
789790

790791
// completeObjectValue complete an Object value by executing all sub-selections.
791-
func completeObjectValue(eCtx *executionContext, returnType *Object, fieldASTs []*ast.Field, info ResolveInfo, path *responsePath, result interface{}) interface{} {
792+
func completeObjectValue(eCtx *executionContext, returnType *Object, fieldASTs []*ast.Field, info ResolveInfo, path *ResponsePath, result interface{}) interface{} {
792793

793794
// If there is an isTypeOf predicate function, call it with the
794795
// current result. If isTypeOf returns false, then raise an error rather
@@ -845,7 +846,7 @@ func completeLeafValue(returnType Leaf, result interface{}) interface{} {
845846
}
846847

847848
// completeListValue complete a list value by completing each item in the list with the inner type
848-
func completeListValue(eCtx *executionContext, returnType *List, fieldASTs []*ast.Field, info ResolveInfo, path *responsePath, result interface{}) interface{} {
849+
func completeListValue(eCtx *executionContext, returnType *List, fieldASTs []*ast.Field, info ResolveInfo, path *ResponsePath, result interface{}) interface{} {
849850
resultVal := reflect.ValueOf(result)
850851
if resultVal.Kind() == reflect.Ptr {
851852
resultVal = resultVal.Elem()

0 commit comments

Comments
 (0)