Skip to content

Commit 882e167

Browse files
authored
Merge pull request #569 from jjergus/intr
differentiate between input values with no default and with default = null
2 parents a17256b + e664374 commit 882e167

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

src/type/__tests__/introspection-test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ describe('Introspection', () => {
825825
name: 'TestInputObject',
826826
fields: {
827827
a: { type: GraphQLString, defaultValue: 'foo' },
828-
b: { type: new GraphQLList(GraphQLString) }
828+
b: { type: new GraphQLList(GraphQLString) },
829+
c: { type: GraphQLString, defaultValue: null }
829830
}
830831
});
831832

@@ -897,7 +898,13 @@ describe('Introspection', () => {
897898
{ kind: 'SCALAR',
898899
name: 'String',
899900
ofType: null } },
900-
defaultValue: null } ] } ] } }
901+
defaultValue: null },
902+
{ name: 'c',
903+
type:
904+
{ kind: 'SCALAR',
905+
name: 'String',
906+
ofType: null },
907+
defaultValue: 'null' } ] } ] } }
901908
});
902909
});
903910

src/type/introspection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* of patent rights can be found in the PATENTS file in the same directory.
99
*/
1010

11-
import isNullish from '../jsutils/isNullish';
11+
import isInvalid from '../jsutils/isInvalid';
1212
import { astFromValue } from '../utilities/astFromValue';
1313
import { print } from '../language/printer';
1414
import {
@@ -333,7 +333,7 @@ export const __InputValue = new GraphQLObjectType({
333333
description:
334334
'A GraphQL-formatted string representing the default value for this ' +
335335
'input value.',
336-
resolve: inputVal => isNullish(inputVal.defaultValue) ?
336+
resolve: inputVal => isInvalid(inputVal.defaultValue) ?
337337
null :
338338
print(astFromValue(inputVal.defaultValue, inputVal.type))
339339
}

src/utilities/__tests__/buildClientSchema-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,23 @@ describe('Type System: build schema from introspection', () => {
509509
defaultValue: { lat: 37.485, lon: -122.148 }
510510
}
511511
}
512+
},
513+
defaultNull: {
514+
type: GraphQLString,
515+
args: {
516+
intArg: {
517+
type: GraphQLInt,
518+
defaultValue: null
519+
}
520+
}
521+
},
522+
noDefault: {
523+
type: GraphQLString,
524+
args: {
525+
intArg: {
526+
type: GraphQLInt
527+
}
528+
}
512529
}
513530
}
514531
})

src/utilities/buildClientSchema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export function buildClientSchema(
321321
const type = getInputType(inputValueIntrospection.type);
322322
const defaultValue = inputValueIntrospection.defaultValue ?
323323
valueFromAST(parseValue(inputValueIntrospection.defaultValue), type) :
324-
null;
324+
undefined;
325325
return {
326326
name: inputValueIntrospection.name,
327327
description: inputValueIntrospection.description,

0 commit comments

Comments
 (0)