Skip to content

GraphQLNonNull(GraphQLBoolean) could return null #438

@wdittmer-mp

Description

@wdittmer-mp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions