@@ -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,22 @@ 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 = {
982+ value : config . defaultValue ,
983+ literal : config . defaultValueLiteral ,
984+ } ;
985+ }
974986 return {
975987 name,
976988 description : config . description ,
977989 type : config . type ,
978- defaultValue : config . defaultValue ,
990+ defaultValue,
979991 deprecationReason : config . deprecationReason ,
980992 extensions : config . extensions && toObjMap ( config . extensions ) ,
981993 astNode : config . astNode ,
@@ -991,7 +1003,8 @@ export function inputValueToConfig(
9911003 return {
9921004 description : inputValue . description ,
9931005 type : inputValue . type ,
994- defaultValue : inputValue . defaultValue ,
1006+ defaultValue : inputValue . defaultValue ?. value ,
1007+ defaultValueLiteral : inputValue . defaultValue ?. literal ,
9951008 deprecationReason : inputValue . deprecationReason ,
9961009 extensions : inputValue . extensions ,
9971010 astNode : inputValue . astNode ,
@@ -1002,16 +1015,22 @@ export type GraphQLInputValue = {|
10021015 name : string ,
10031016 description : ?string ,
10041017 type : GraphQLInputType ,
1005- defaultValue : mixed ,
1018+ defaultValue : ? GraphQLDefaultValueUsage ,
10061019 deprecationReason : ?string ,
10071020 extensions : ?ReadOnlyObjMap < mixed > ,
10081021 astNode : ?InputValueDefinitionNode ,
10091022| } ;
10101023
1024+ export type GraphQLDefaultValueUsage = { |
1025+ value : mixed ,
1026+ literal : ?ConstValueNode ,
1027+ | } ;
1028+
10111029export type GraphQLInputValueConfig = { |
10121030 description ?: ?string ,
10131031 type : GraphQLInputType ,
10141032 defaultValue ?: mixed ,
1033+ defaultValueLiteral ?: ?ConstValueNode ,
10151034 deprecationReason ?: ?string ,
10161035 extensions ?: ?ReadOnlyObjMapLike < mixed > ,
10171036 astNode ?: ?InputValueDefinitionNode ,
0 commit comments