@@ -41,6 +41,7 @@ import type {
4141 FieldNode ,
4242 FragmentDefinitionNode ,
4343 ValueNode ,
44+ ConstValueNode ,
4445} from '../language/ast' ;
4546
4647import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped' ;
@@ -971,11 +972,21 @@ export function defineInputValue(
971972 ! ( 'resolve' in config ) ,
972973 `${ name } has a resolve property, but inputs cannot define resolvers.` ,
973974 ) ;
975+ let defaultValue ;
976+ if ( config . defaultValue !== undefined || config . defaultValueLiteral ) {
977+ devAssert (
978+ config . defaultValue === undefined || ! config . defaultValueLiteral ,
979+ `${ name } has both a defaultValue and a defaultValueLiteral property, but only one must be provided.` ,
980+ ) ;
981+ defaultValue = config . defaultValueLiteral
982+ ? { literal : config . defaultValueLiteral }
983+ : { value : config . defaultValue } ;
984+ }
974985 return {
975986 name,
976987 description : config . description ,
977988 type : config . type ,
978- defaultValue : config . defaultValue ,
989+ defaultValue,
979990 deprecationReason : config . deprecationReason ,
980991 extensions : config . extensions && toObjMap ( config . extensions ) ,
981992 astNode : config . astNode ,
@@ -991,7 +1002,12 @@ export function inputValueToConfig(
9911002 return {
9921003 description : inputValue . description ,
9931004 type : inputValue . type ,
994- defaultValue : inputValue . defaultValue ,
1005+ defaultValue : inputValue . defaultValue ?. literal
1006+ ? undefined
1007+ : inputValue . defaultValue ?. value ,
1008+ defaultValueLiteral : inputValue . defaultValue ?. literal
1009+ ? inputValue . defaultValue . literal
1010+ : undefined ,
9951011 deprecationReason : inputValue . deprecationReason ,
9961012 extensions : inputValue . extensions ,
9971013 astNode : inputValue . astNode ,
@@ -1002,16 +1018,21 @@ export type GraphQLInputValue = {|
10021018 name : string ,
10031019 description : ?string ,
10041020 type : GraphQLInputType ,
1005- defaultValue : mixed ,
1021+ defaultValue : ? GraphQLDefaultValueUsage ,
10061022 deprecationReason : ?string ,
10071023 extensions : ?ReadOnlyObjMap < mixed > ,
10081024 astNode : ?InputValueDefinitionNode ,
10091025| } ;
10101026
1027+ export type GraphQLDefaultValueUsage =
1028+ | { | value : mixed | }
1029+ | { | literal : ConstValueNode | } ;
1030+
10111031export type GraphQLInputValueConfig = { |
10121032 description ?: ?string ,
10131033 type : GraphQLInputType ,
10141034 defaultValue ?: mixed ,
1035+ defaultValueLiteral ?: ?ConstValueNode ,
10151036 deprecationReason ?: ?string ,
10161037 extensions ?: ?ReadOnlyObjMapLike < mixed > ,
10171038 astNode ?: ?InputValueDefinitionNode ,
0 commit comments