@@ -41,6 +41,7 @@ import type {
41
41
FieldNode ,
42
42
FragmentDefinitionNode ,
43
43
ValueNode ,
44
+ ConstValueNode ,
44
45
} from '../language/ast' ;
45
46
46
47
import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped' ;
@@ -971,11 +972,21 @@ export function defineInputValue(
971
972
! ( 'resolve' in config ) ,
972
973
`${ name } has a resolve property, but inputs cannot define resolvers.` ,
973
974
) ;
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
+ }
974
985
return {
975
986
name,
976
987
description : config . description ,
977
988
type : config . type ,
978
- defaultValue : config . defaultValue ,
989
+ defaultValue,
979
990
deprecationReason : config . deprecationReason ,
980
991
extensions : config . extensions && toObjMap ( config . extensions ) ,
981
992
astNode : config . astNode ,
@@ -991,7 +1002,12 @@ export function inputValueToConfig(
991
1002
return {
992
1003
description : inputValue . description ,
993
1004
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 ,
995
1011
deprecationReason : inputValue . deprecationReason ,
996
1012
extensions : inputValue . extensions ,
997
1013
astNode : inputValue . astNode ,
@@ -1002,16 +1018,21 @@ export type GraphQLInputValue = {|
1002
1018
name : string ,
1003
1019
description : ?string ,
1004
1020
type : GraphQLInputType ,
1005
- defaultValue : mixed ,
1021
+ defaultValue : ? GraphQLDefaultValueUsage ,
1006
1022
deprecationReason : ?string ,
1007
1023
extensions : ?ReadOnlyObjMap < mixed > ,
1008
1024
astNode : ?InputValueDefinitionNode ,
1009
1025
| } ;
1010
1026
1027
+ export type GraphQLDefaultValueUsage =
1028
+ | { | value : mixed | }
1029
+ | { | literal : ConstValueNode | } ;
1030
+
1011
1031
export type GraphQLInputValueConfig = { |
1012
1032
description ?: ?string ,
1013
1033
type : GraphQLInputType ,
1014
1034
defaultValue ?: mixed ,
1035
+ defaultValueLiteral ?: ?ConstValueNode ,
1015
1036
deprecationReason ?: ?string ,
1016
1037
extensions ?: ?ReadOnlyObjMapLike < mixed > ,
1017
1038
astNode ?: ?InputValueDefinitionNode ,
0 commit comments