Skip to content

GraphQLNonNull(GraphQLBoolean) could return null #438

Closed

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

Activity

  1. bbakerman commented on May 18, 2017

    @bbakerman
    Member

    Ahhh nice catch. Hmmm have to look into this.

  2. added this to the milestone on May 20, 2017
  3. bbakerman commented on May 24, 2017

    @bbakerman
    Member

    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

  4. added 4 commits that reference this issue on May 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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