Skip to content

Commit

Permalink
Minor follow-up to graphql-go#311
Browse files Browse the repository at this point in the history
Commit:
533fc43f7d5836fc9b6a3eafde9801db9a3ee011 [533fc43]
Parents:
371a5a0908
Author:
Lee Byron <[email protected]>
Date:
23 March 2016 at 8:21:04 AM SGT
Commit Date:
23 March 2016 at 8:22:42 AM SGT
  • Loading branch information
sogko committed May 30, 2016
1 parent e23ac77 commit d7a15e0
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ func completeValue(eCtx *ExecutionContext, returnType Type, fieldASTs []*ast.Fie
panic(gqlerrors.FormatError(err))
}

// If field type is NonNull, complete for inner type, and throw field error
// if result is null.
if returnType, ok := returnType.(*NonNull); ok {
completed := completeValue(eCtx, returnType.OfType, fieldASTs, info, result)
if completed == nil {
Expand All @@ -606,6 +608,7 @@ func completeValue(eCtx *ExecutionContext, returnType Type, fieldASTs []*ast.Fie
return completed
}

// If result value is null-ish (null, undefined, or NaN) then return null.
if isNullish(result) {
return nil
}
Expand All @@ -615,24 +618,27 @@ func completeValue(eCtx *ExecutionContext, returnType Type, fieldASTs []*ast.Fie
return completeListValue(eCtx, returnType, fieldASTs, info, result)
}

// If field type is Scalar or Enum, serialize to a valid value, returning
// null if serialization is not possible.
// If field type is a leaf type, Scalar or Enum, serialize to a valid value,
// returning null if serialization is not possible.
if returnType, ok := returnType.(*Scalar); ok {
return completeLeafValue(eCtx, returnType, fieldASTs, info, result)
}
if returnType, ok := returnType.(*Enum); ok {
return completeLeafValue(eCtx, returnType, fieldASTs, info, result)
}

if returnType, ok := returnType.(*Object); ok {
return completeObjectValue(eCtx, returnType, fieldASTs, info, result)
}

// If field type is an abstract type, Interface or Union, determine the
// runtime Object type and complete for that type.
if returnType, ok := returnType.(Abstract); ok {
return completeAbstractValue(eCtx, returnType, fieldASTs, info, result)
}

// Not reachable
// If field type is Object, execute and complete all sub-selections.
if returnType, ok := returnType.(*Object); ok {
return completeObjectValue(eCtx, returnType, fieldASTs, info, result)
}

// Not reachable. All possible output types have been considered.
err := invariant(false,
fmt.Sprintf(`Cannot complete value of unexpected type "%v."`, returnType),
)
Expand All @@ -642,7 +648,7 @@ func completeValue(eCtx *ExecutionContext, returnType Type, fieldASTs []*ast.Fie
return nil
}

// completeObjectValue completes value of an Abstract type (Union / Interface) by determining the runtime type
// completeAbstractValue completes value of an Abstract type (Union / Interface) by determining the runtime type
// of that value, then completing based on that type.
func completeAbstractValue(eCtx *ExecutionContext, returnType Abstract, fieldASTs []*ast.Field, info ResolveInfo, result interface{}) interface{} {

Expand All @@ -664,6 +670,8 @@ func completeAbstractValue(eCtx *ExecutionContext, returnType Abstract, fieldAST

return completeObjectValue(eCtx, runtimeType, fieldASTs, info, result)
}

// completeObjectValue complete an Object value by executing all sub-selections.
func completeObjectValue(eCtx *ExecutionContext, returnType *Object, fieldASTs []*ast.Field, info ResolveInfo, result interface{}) interface{} {

// If there is an isTypeOf predicate function, call it with the
Expand Down

0 comments on commit d7a15e0

Please sign in to comment.