Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add full error message for NonNullableValueCoercedAsNullException
  • Loading branch information
dondonz committed Mar 26, 2022
commit 97d55eff6d16e1e9a1587c1863b414cc1f3d0bc9
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public NonNullableValueCoercedAsNullException(VariableDefinition variableDefinit
this.path = path;
}

public NonNullableValueCoercedAsNullException(List<Object> path, GraphQLType graphQLType) {
super(format("Coerced Null value for NonNull type '%s'",
GraphQLTypeUtil.simplePrint(graphQLType)));
this.path = path;
}

public NonNullableValueCoercedAsNullException(VariableDefinition variableDefinition, String causeMessage) {
super(format("Variable '%s' has invalid value: %s",
variableDefinition.getName(), causeMessage));
this.sourceLocations = Collections.singletonList(variableDefinition.getSourceLocation());
}

public NonNullableValueCoercedAsNullException(String fieldName, List<Object> path, GraphQLType graphQLType) {
super(format("Field '%s' has coerced Null value for NonNull type '%s'",
fieldName, GraphQLTypeUtil.simplePrint(graphQLType)));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/graphql/execution/ValuesResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ private Map<String, Object> externalValueToInternalValueForVariables(GraphQLSche
.cause(e.getCause())
.sourceLocation(variableDefinition.getSourceLocation())
.build();
} catch (NonNullableValueCoercedAsNullException e) {
throw new NonNullableValueCoercedAsNullException(variableDefinition, e.getMessage());
}
}

Expand Down Expand Up @@ -495,7 +497,7 @@ private Object externalValueToInternalValue(GraphqlFieldVisibility fieldVisibili
Object returnValue =
externalValueToInternalValue(fieldVisibility, unwrapOne(graphQLType), value);
if (returnValue == null) {
throw new NonNullableValueCoercedAsNullException("", emptyList(), graphQLType);
throw new NonNullableValueCoercedAsNullException(emptyList(), graphQLType);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I see here is emptyList is not much better than "" - that is there is no real info available.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean its better than it was - but is it as good as it could be?

I guess we would have to "track" fields and types as we descending the ValueResolver to get excellent names in the exception

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to merge this as progress over perfection

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather remove the emptyList() path

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have another PR - #2773 - that means this is less likely in terms of conditions where this will happen - still possible but less likely

}
return returnValue;
}
Expand Down