Skip to content

Commit

Permalink
astFromNode does not converts NonNull values to NullValue
Browse files Browse the repository at this point in the history
  • Loading branch information
langpavel committed Oct 28, 2016
1 parent 03a90d6 commit 02d71a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/utilities/__tests__/astFromValue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
GraphQLString,
GraphQLBoolean,
GraphQLID,
GraphQLNonNull,
} from '../../type';


Expand Down Expand Up @@ -149,6 +150,13 @@ describe('astFromValue', () => {
);
});

it('does not converts NonNull values to NullValue', () => {
const NonNullBoolean = new GraphQLNonNull(GraphQLBoolean);
expect(astFromValue(null, NonNullBoolean)).to.deep.equal(
null
);
});

const complexValue = { someArbitrary: 'complexValue' };

const myEnum = new GraphQLEnumType({
Expand Down
8 changes: 5 additions & 3 deletions src/utilities/astFromValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ export function astFromValue(
const _value = value;

if (type instanceof GraphQLNonNull) {
// Note: we're not checking that the result is non-null.
// This function is not responsible for validating the input value.
return astFromValue(_value, type.ofType);
const astValue = astFromValue(_value, type.ofType);
if (astValue && astValue.kind === NULL) {
return null;
}
return astValue;
}

// only explicit null, not undefined, NaN
Expand Down

0 comments on commit 02d71a0

Please sign in to comment.