Skip to content

Commit

Permalink
differentiate between input values with no default and with default =…
Browse files Browse the repository at this point in the history
… null
  • Loading branch information
jjergus committed Nov 15, 2016
1 parent a17256b commit e664374
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/type/__tests__/introspection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,8 @@ describe('Introspection', () => {
name: 'TestInputObject',
fields: {
a: { type: GraphQLString, defaultValue: 'foo' },
b: { type: new GraphQLList(GraphQLString) }
b: { type: new GraphQLList(GraphQLString) },
c: { type: GraphQLString, defaultValue: null }
}
});

Expand Down Expand Up @@ -897,7 +898,13 @@ describe('Introspection', () => {
{ kind: 'SCALAR',
name: 'String',
ofType: null } },
defaultValue: null } ] } ] } }
defaultValue: null },
{ name: 'c',
type:
{ kind: 'SCALAR',
name: 'String',
ofType: null },
defaultValue: 'null' } ] } ] } }
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/type/introspection.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

import isNullish from '../jsutils/isNullish';
import isInvalid from '../jsutils/isInvalid';
import { astFromValue } from '../utilities/astFromValue';
import { print } from '../language/printer';
import {
Expand Down Expand Up @@ -333,7 +333,7 @@ export const __InputValue = new GraphQLObjectType({
description:
'A GraphQL-formatted string representing the default value for this ' +
'input value.',
resolve: inputVal => isNullish(inputVal.defaultValue) ?
resolve: inputVal => isInvalid(inputVal.defaultValue) ?
null :
print(astFromValue(inputVal.defaultValue, inputVal.type))
}
Expand Down
17 changes: 17 additions & 0 deletions src/utilities/__tests__/buildClientSchema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,23 @@ describe('Type System: build schema from introspection', () => {
defaultValue: { lat: 37.485, lon: -122.148 }
}
}
},
defaultNull: {
type: GraphQLString,
args: {
intArg: {
type: GraphQLInt,
defaultValue: null
}
}
},
noDefault: {
type: GraphQLString,
args: {
intArg: {
type: GraphQLInt
}
}
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/buildClientSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export function buildClientSchema(
const type = getInputType(inputValueIntrospection.type);
const defaultValue = inputValueIntrospection.defaultValue ?
valueFromAST(parseValue(inputValueIntrospection.defaultValue), type) :
null;
undefined;
return {
name: inputValueIntrospection.name,
description: inputValueIntrospection.description,
Expand Down

0 comments on commit e664374

Please sign in to comment.