Hi,
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.
Kind Regards,
Wilfred
Hi,
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.
Kind Regards,
Wilfred