@@ -817,8 +817,14 @@ func completeAbstractValue(
817
817
path: [ IndexPathElement ] ,
818
818
result: MapRepresentable
819
819
) throws -> MapRepresentable {
820
- let resolveRes = try returnType. resolveType ? ( result, exeContext. contextValue, info) ??
821
- defaultResolveType ( value: result, context: exeContext. contextValue, info: info, abstractType: returnType) . map ( { . type( $0) } )
820
+ var resolveRes = try returnType. resolveType ? ( result, exeContext. contextValue, info) . typeResolveResult
821
+
822
+ resolveRes = resolveRes ?? defaultResolveType (
823
+ value: result,
824
+ context: exeContext. contextValue,
825
+ info: info,
826
+ abstractType: returnType
827
+ )
822
828
823
829
guard let resolveResult = resolveRes else {
824
830
throw GraphQLError (
@@ -841,7 +847,7 @@ func completeAbstractValue(
841
847
throw GraphQLError (
842
848
message:
843
849
" Abstract type \( returnType. name) must resolve to an Object type at " +
844
- " runtime for field \( info. parentType. name) . \( info. fieldName) with " +
850
+ " runtime for field \( info. parentType. name) . \( info. fieldName) with " +
845
851
" value \" \( resolveResult) \" , received \" \( runtimeType) \" . " ,
846
852
nodes: fieldASTs
847
853
)
@@ -880,7 +886,7 @@ func completeObjectValue(
880
886
// If there is an isTypeOf predicate func, call it with the
881
887
// current result. If isTypeOf returns false, then raise an error rather
882
888
// than continuing execution.
883
- if returnType. isTypeOf ? ( result, exeContext. contextValue, info) ?? false {
889
+ guard returnType. isTypeOf ? ( result, exeContext. contextValue, info) ?? true else {
884
890
throw GraphQLError (
885
891
message:
886
892
" Expected value of type \" \( returnType. name) \" but got: \( result) . " ,
@@ -923,24 +929,14 @@ func defaultResolveType(
923
929
context: MapRepresentable ,
924
930
info: GraphQLResolveInfo ,
925
931
abstractType: GraphQLAbstractType
926
- ) -> GraphQLObjectType ? {
932
+ ) -> TypeResolveResult ? {
927
933
let possibleTypes = info. schema. getPossibleTypes ( abstractType: abstractType)
928
- return possibleTypes. find ( { $0. isTypeOf ? ( value, context, info) ?? false } )
929
- }
930
934
931
- func unwrap( _ value: MapRepresentable ) -> MapRepresentable ? {
932
- let mirror = Mirror ( reflecting: value)
933
-
934
- if mirror. displayStyle != . optional {
935
- return value
936
- }
937
-
938
- if mirror. children. isEmpty {
935
+ guard let type = possibleTypes. find ( { $0. isTypeOf ? ( value, context, info) ?? false } ) else {
939
936
return nil
940
937
}
941
938
942
- let child = mirror. children. first!
943
- return child. value as? MapRepresentable
939
+ return . type( type)
944
940
}
945
941
946
942
/**
@@ -949,11 +945,10 @@ func unwrap(_ value: MapRepresentable) -> MapRepresentable? {
949
945
* and returns it as the result.
950
946
*/
951
947
func defaultResolve( source: MapRepresentable , args: Map , context: MapRepresentable , info: GraphQLResolveInfo ) -> MapRepresentable {
952
- print ( type ( of: source) )
953
948
guard let source = unwrap ( source) else {
954
949
return Map . null
955
950
}
956
- print ( type ( of : source ) )
951
+
957
952
guard let anyValue = try ? get ( info. fieldName, from: source) , let value = anyValue as? MapRepresentable else {
958
953
return Map . null
959
954
}
0 commit comments