@@ -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,22 @@ 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 = {
982
+ value : config . defaultValue ,
983
+ literal : config . defaultValueLiteral ,
984
+ } ;
985
+ }
974
986
return {
975
987
name,
976
988
description : config . description ,
977
989
type : config . type ,
978
- defaultValue : config . defaultValue ,
990
+ defaultValue,
979
991
deprecationReason : config . deprecationReason ,
980
992
extensions : config . extensions && toObjMap ( config . extensions ) ,
981
993
astNode : config . astNode ,
@@ -991,7 +1003,8 @@ export function inputValueToConfig(
991
1003
return {
992
1004
description : inputValue . description ,
993
1005
type : inputValue . type ,
994
- defaultValue : inputValue . defaultValue ,
1006
+ defaultValue : inputValue . defaultValue ?. value ,
1007
+ defaultValueLiteral : inputValue . defaultValue ?. literal ,
995
1008
deprecationReason : inputValue . deprecationReason ,
996
1009
extensions : inputValue . extensions ,
997
1010
astNode : inputValue . astNode ,
@@ -1002,16 +1015,22 @@ export type GraphQLInputValue = {|
1002
1015
name : string ,
1003
1016
description : ?string ,
1004
1017
type : GraphQLInputType ,
1005
- defaultValue : mixed ,
1018
+ defaultValue : ? GraphQLDefaultValueUsage ,
1006
1019
deprecationReason : ?string ,
1007
1020
extensions : ?ReadOnlyObjMap < mixed > ,
1008
1021
astNode : ?InputValueDefinitionNode ,
1009
1022
| } ;
1010
1023
1024
+ export type GraphQLDefaultValueUsage = { |
1025
+ value : mixed ,
1026
+ literal : ?ConstValueNode ,
1027
+ | } ;
1028
+
1011
1029
export type GraphQLInputValueConfig = { |
1012
1030
description ?: ?string ,
1013
1031
type : GraphQLInputType ,
1014
1032
defaultValue ?: mixed ,
1033
+ defaultValueLiteral ?: ?ConstValueNode ,
1015
1034
deprecationReason ?: ?string ,
1016
1035
extensions ?: ?ReadOnlyObjMapLike < mixed > ,
1017
1036
astNode ?: ?InputValueDefinitionNode ,
0 commit comments