You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GraphQLNonNull(GraphQLBoolean) could return null #438
We had a strange situation that a non-nullable boolean somehow returned null.
E.g. our type definition was: .type(new GraphQLNonNull(GraphQLBoolean))
There was no exception (null for non-nullable type), which was strange.
Plus, we were using the Java boolean primitive, so even not initialized it should be false.
It turned out that we accidentally had the datafetcher returning an DateTime class.
So it looks like that GraphQLNonNull checks that the datafetcher's returned object is not null, which it isn't. Then the GraphQLBoolean tries to serialize the DateTime, and it returns null: @Override public Boolean serialize(Object input) { if (input instanceof Boolean) { return (Boolean) input; } else if (input instanceof Integer) { return (Integer) input > 0; } else if (input instanceof String) { return Boolean.parseBoolean((String) input); } else { return null; } }
Would it be possible for the GraphQLNonNull to check after the serialize?
This way, it would have at least thrown the 'null for non-nullable type' exception.
I don't know what the impact is for the rest of the system, hence this issue.
Activity
bbakerman commentedon May 18, 2017
Ahhh nice catch. Hmmm have to look into this.
bbakerman commentedon May 24, 2017
The new more strict Scalar code will help with this but what about anyone writing their own Scalar implementation.
I think we should do belts and braces.
We should fix the main Scalar implementations AND check for null after co-ercion
graphql-java#438 now with double checks in null values that might com…
graphql-java#438 - unit test for NonNullableFieldValidator
#438 now with double checks in null values that might come out of coe…
#438 - unit test for NonNullableFieldValidator
Merge remote-tracking branch 'upstream/master'