66import graphql .SerializationError ;
77import graphql .TypeMismatchError ;
88import graphql .TypeResolutionEnvironment ;
9+ import graphql .UnresolvedTypeError ;
910import graphql .execution .instrumentation .Instrumentation ;
1011import graphql .execution .instrumentation .InstrumentationContext ;
1112import graphql .execution .instrumentation .parameters .InstrumentationFieldCompleteParameters ;
@@ -366,15 +367,34 @@ protected CompletableFuture<ExecutionResult> completeValue(ExecutionContext exec
366367 } else if (fieldType instanceof GraphQLEnumType ) {
367368 return completeValueForEnum (executionContext , parameters , (GraphQLEnumType ) fieldType , result );
368369 }
370+
369371 //
370372 // when we are here, we have a complex type: Interface, Union or Object
371373 // and we must go deeper
372374 //
373- GraphQLObjectType resolvedObjectType = resolveType (executionContext , parameters , fieldType );
375+ GraphQLObjectType resolvedObjectType ;
376+ try {
377+ resolvedObjectType = resolveType (executionContext , parameters , fieldType );
378+ } catch (UnresolvedTypeException ex ) {
379+ // consider the result to be null and add the error on the context
380+ handleUnresolvedTypeProblem (executionContext , parameters , ex );
381+ // and validate the field is nullable, if non-nullable throw exception
382+ parameters .getNonNullFieldValidator ().validate (parameters .getPath (), null );
383+ // complete the field
384+ return completedFuture (new ExecutionResultImpl (null , null ));
385+ }
374386
375387 return completeValueForObject (executionContext , parameters , resolvedObjectType , result );
376388 }
377389
390+ private void handleUnresolvedTypeProblem (ExecutionContext context , ExecutionStrategyParameters parameters , UnresolvedTypeException e ) {
391+ UnresolvedTypeError error = new UnresolvedTypeError (parameters .getPath (), parameters .getTypeInfo (), e );
392+ log .warn (error .getMessage (), e );
393+ context .addError (error );
394+
395+ parameters .deferredErrorSupport ().onError (error );
396+ }
397+
378398 private CompletableFuture <ExecutionResult > completeValueForNull (ExecutionStrategyParameters parameters ) {
379399 Object nullValue = parameters .getNonNullFieldValidator ().validate (parameters .getPath (), null );
380400 return completedFuture (new ExecutionResultImpl (nullValue , null ));
@@ -659,9 +679,10 @@ protected GraphQLObjectType resolveType(ExecutionContext executionContext, Execu
659679 */
660680 protected GraphQLObjectType resolveTypeForInterface (TypeResolutionParameters params ) {
661681 TypeResolutionEnvironment env = new TypeResolutionEnvironment (params .getValue (), params .getArgumentValues (), params .getField (), params .getGraphQLInterfaceType (), params .getSchema (), params .getContext ());
662- GraphQLObjectType result = params .getGraphQLInterfaceType ().getTypeResolver ().getType (env );
682+ GraphQLInterfaceType abstractType = params .getGraphQLInterfaceType ();
683+ GraphQLObjectType result = abstractType .getTypeResolver ().getType (env );
663684 if (result == null ) {
664- throw new UnresolvedTypeException (params . getGraphQLInterfaceType () );
685+ throw new UnresolvedTypeException (abstractType );
665686 }
666687 return result ;
667688 }
@@ -675,9 +696,10 @@ protected GraphQLObjectType resolveTypeForInterface(TypeResolutionParameters par
675696 */
676697 protected GraphQLObjectType resolveTypeForUnion (TypeResolutionParameters params ) {
677698 TypeResolutionEnvironment env = new TypeResolutionEnvironment (params .getValue (), params .getArgumentValues (), params .getField (), params .getGraphQLUnionType (), params .getSchema (), params .getContext ());
678- GraphQLObjectType result = params .getGraphQLUnionType ().getTypeResolver ().getType (env );
699+ GraphQLUnionType abstractType = params .getGraphQLUnionType ();
700+ GraphQLObjectType result = abstractType .getTypeResolver ().getType (env );
679701 if (result == null ) {
680- throw new UnresolvedTypeException (params . getGraphQLUnionType () );
702+ throw new UnresolvedTypeException (abstractType );
681703 }
682704 return result ;
683705 }
0 commit comments