@@ -238,29 +238,29 @@ func executeFieldsSerially(exeContext: ExecutionContext, parentType: GraphQLObje
238
238
* for "read" mode.
239
239
*/
240
240
func executeFields( exeContext: ExecutionContext , parentType: GraphQLObjectType , sourceValue: Map ,
241
- path: [ IndexPathElement ] , fields: [ String : [ Field ] ] ) throws -> Map {
241
+ path: [ IndexPathElement ] , fields: [ String : [ Field ] ] ) throws -> Map {
242
242
let finalResults : [ String : Map ] = try fields. reduce ( [ : ] ) { results, field in
243
243
var results = results
244
- let fieldASTs = field. value
245
- let fieldPath = path + [ field. key] as [ IndexPathElement ]
244
+ let fieldASTs = field. value
245
+ let fieldPath = path + [ field. key] as [ IndexPathElement ]
246
246
247
- let result = try resolveField (
248
- exeContext: exeContext,
249
- parentType: parentType,
250
- source: sourceValue,
251
- fieldASTs: fieldASTs,
252
- path: fieldPath
253
- )
247
+ let result = try resolveField (
248
+ exeContext: exeContext,
249
+ parentType: parentType,
250
+ source: sourceValue,
251
+ fieldASTs: fieldASTs,
252
+ path: fieldPath
253
+ )
254
254
255
- guard let r = result else {
256
- return results
257
- }
255
+ guard let r = result else {
256
+ return results
257
+ }
258
258
259
259
results [ field. key] = r
260
-
261
- return results
260
+
261
+ return results
262
262
}
263
-
263
+
264
264
return . dictionary( finalResults)
265
265
}
266
266
@@ -537,79 +537,79 @@ func completeValueWithLocatedError(exeContext: ExecutionContext, returnType: Gra
537
537
* value by evaluating all sub-selections.
538
538
*/
539
539
func completeValue( exeContext: ExecutionContext , returnType: GraphQLType , fieldASTs: [ Field ] , info: GraphQLResolveInfo , path: [ IndexPathElement ] , result: Map ) throws -> Map ? {
540
- // If field type is NonNull, complete for inner type, and throw field error
541
- // if result is null.
542
- if let returnType = returnType as? GraphQLNonNull {
543
- let completed = try completeValue (
544
- exeContext: exeContext,
545
- returnType: returnType. ofType,
546
- fieldASTs: fieldASTs,
547
- info: info,
548
- path: path,
549
- result: result
550
- )
540
+ // If field type is NonNull, complete for inner type, and throw field error
541
+ // if result is null.
542
+ if let returnType = returnType as? GraphQLNonNull {
543
+ let completed = try completeValue (
544
+ exeContext: exeContext,
545
+ returnType: returnType. ofType,
546
+ fieldASTs: fieldASTs,
547
+ info: info,
548
+ path: path,
549
+ result: result
550
+ )
551
551
552
- guard let c = completed else {
553
- throw GraphQLError (
554
- message: " Cannot return null for non-nullable field \( info. parentType. name) . \( info. fieldName) . "
555
- )
556
- }
552
+ guard let c = completed else {
553
+ throw GraphQLError (
554
+ message: " Cannot return null for non-nullable field \( info. parentType. name) . \( info. fieldName) . "
555
+ )
556
+ }
557
557
558
- return c
559
- }
558
+ return c
559
+ }
560
560
561
- // If result value is null-ish (null, undefined, or NaN) then return null.
562
- if isNullish ( result) {
563
- return nil
564
- }
561
+ // If result value is null-ish (null, undefined, or NaN) then return null.
562
+ if isNullish ( result) {
563
+ return nil
564
+ }
565
565
566
- // If field type is List, complete each item in the list with the inner type
567
- if let returnType = returnType as? GraphQLList {
568
- return try completeListValue (
569
- exeContext: exeContext,
570
- returnType: returnType,
571
- fieldASTs: fieldASTs,
572
- info: info,
573
- path: path,
574
- result: result
575
- )
576
- }
566
+ // If field type is List, complete each item in the list with the inner type
567
+ if let returnType = returnType as? GraphQLList {
568
+ return try completeListValue (
569
+ exeContext: exeContext,
570
+ returnType: returnType,
571
+ fieldASTs: fieldASTs,
572
+ info: info,
573
+ path: path,
574
+ result: result
575
+ )
576
+ }
577
577
578
- // If field type is a leaf type, Scalar or Enum, serialize to a valid value,
579
- // returning null if serialization is not possible.
580
- if let returnType = returnType as? GraphQLLeafType {
581
- return try completeLeafValue ( returnType: returnType, result: result)
582
- }
578
+ // If field type is a leaf type, Scalar or Enum, serialize to a valid value,
579
+ // returning null if serialization is not possible.
580
+ if let returnType = returnType as? GraphQLLeafType {
581
+ return try completeLeafValue ( returnType: returnType, result: result)
582
+ }
583
583
584
- // If field type is an abstract type, Interface or Union, determine the
585
- // runtime Object type and complete for that type.
586
- if let returnType = returnType as? GraphQLAbstractType {
587
- return try completeAbstractValue (
588
- exeContext: exeContext,
589
- returnType: returnType,
590
- fieldASTs: fieldASTs,
591
- info: info,
592
- path: path,
593
- result: result
594
- )
595
- }
584
+ // If field type is an abstract type, Interface or Union, determine the
585
+ // runtime Object type and complete for that type.
586
+ if let returnType = returnType as? GraphQLAbstractType {
587
+ return try completeAbstractValue (
588
+ exeContext: exeContext,
589
+ returnType: returnType,
590
+ fieldASTs: fieldASTs,
591
+ info: info,
592
+ path: path,
593
+ result: result
594
+ )
595
+ }
596
596
597
- // If field type is Object, execute and complete all sub-selections.
598
- if let returnType = returnType as? GraphQLObjectType {
599
- return try completeObjectValue (
600
- exeContext: exeContext,
601
- returnType: returnType,
602
- fieldASTs: fieldASTs,
603
- info: info,
604
- path: path,
605
- result: result
597
+ // If field type is Object, execute and complete all sub-selections.
598
+ if let returnType = returnType as? GraphQLObjectType {
599
+ return try completeObjectValue (
600
+ exeContext: exeContext,
601
+ returnType: returnType,
602
+ fieldASTs: fieldASTs,
603
+ info: info,
604
+ path: path,
605
+ result: result
606
+ )
607
+ }
608
+
609
+ // Not reachable. All possible output types have been considered.
610
+ throw GraphQLError (
611
+ message: " Cannot complete value of unexpected type \" \( returnType) \" . "
606
612
)
607
- }
608
-
609
- // Not reachable. All possible output types have been considered.
610
- throw GraphQLError (
611
- message: " Cannot complete value of unexpected type \" \( returnType) \" . "
612
- )
613
613
}
614
614
615
615
/**
@@ -675,8 +675,8 @@ func completeLeafValue(returnType: GraphQLLeafType, result: Map) throws -> Map {
675
675
* of that value, then complete the value for that type.
676
676
*/
677
677
func completeAbstractValue( exeContext: ExecutionContext , returnType: GraphQLAbstractType , fieldASTs: [ Field ] , info: GraphQLResolveInfo , path: [ IndexPathElement ] , result: Map ) throws -> Map {
678
- let resolveRes = returnType. resolveType ? ( result, exeContext. contextValue, info) ??
679
- defaultResolveType ( value: result, context: exeContext. contextValue, info: info, abstractType: returnType) . map ( { . type( $0) } )
678
+ let resolveRes = try returnType. resolveType ? ( result, exeContext. contextValue, info) ??
679
+ defaultResolveType ( value: result, context: exeContext. contextValue, info: info, abstractType: returnType) . map ( { . type( $0) } )
680
680
681
681
guard let resolveResult = resolveRes else {
682
682
throw GraphQLError (
@@ -685,7 +685,7 @@ func completeAbstractValue(exeContext: ExecutionContext, returnType: GraphQLAbst
685
685
)
686
686
}
687
687
688
- // If resolveType returns a string, we assume it's a GraphQLObjectType name.
688
+ // If resolveType returns a string, we assume it's a GraphQLObjectType name.
689
689
var runtimeType : GraphQLType ?
690
690
691
691
switch resolveResult {
@@ -695,33 +695,33 @@ func completeAbstractValue(exeContext: ExecutionContext, returnType: GraphQLAbst
695
695
runtimeType = type
696
696
}
697
697
698
- guard let objectType = runtimeType as? GraphQLObjectType else {
699
- throw GraphQLError (
700
- message:
701
- " Abstract type \( returnType. name) must resolve to an Object type at " +
702
- " runtime for field \( info. parentType. name) . \( info. fieldName) with " +
703
- " value \" \( resolveResult) \" , received \" \( runtimeType) \" . " ,
704
- nodes: fieldASTs
705
- )
706
- }
698
+ guard let objectType = runtimeType as? GraphQLObjectType else {
699
+ throw GraphQLError (
700
+ message:
701
+ " Abstract type \( returnType. name) must resolve to an Object type at " +
702
+ " runtime for field \( info. parentType. name) . \( info. fieldName) with " +
703
+ " value \" \( resolveResult) \" , received \" \( runtimeType) \" . " ,
704
+ nodes: fieldASTs
705
+ )
706
+ }
707
707
708
- if !exeContext. schema. isPossibleType ( abstractType: returnType, possibleType: objectType) {
709
- throw GraphQLError (
710
- message:
711
- " Runtime Object type \" \( objectType. name) \" is not a possible type " +
712
- " for \" \( returnType. name) \" . " ,
713
- nodes: fieldASTs
714
- )
715
- }
708
+ if !exeContext. schema. isPossibleType ( abstractType: returnType, possibleType: objectType) {
709
+ throw GraphQLError (
710
+ message:
711
+ " Runtime Object type \" \( objectType. name) \" is not a possible type " +
712
+ " for \" \( returnType. name) \" . " ,
713
+ nodes: fieldASTs
714
+ )
715
+ }
716
716
717
- return try completeObjectValue (
718
- exeContext: exeContext,
719
- returnType: objectType,
720
- fieldASTs: fieldASTs,
721
- info: info,
722
- path: path,
723
- result: result
724
- )
717
+ return try completeObjectValue (
718
+ exeContext: exeContext,
719
+ returnType: objectType,
720
+ fieldASTs: fieldASTs,
721
+ info: info,
722
+ path: path,
723
+ result: result
724
+ )
725
725
}
726
726
727
727
/**
0 commit comments