@@ -821,7 +821,9 @@ function defineFieldMap<TSource, TContext>(
821
821
name : fieldName ,
822
822
description : fieldConfig . description ,
823
823
type : fieldConfig . type ,
824
- args : defineArguments ( argsConfig ) ,
824
+ args : Object . entries ( argsConfig ) . map ( ( [ argName , argConfig ] ) =>
825
+ defineInputValue ( argConfig , argName ) ,
826
+ ) ,
825
827
resolve : fieldConfig . resolve ,
826
828
subscribe : fieldConfig . subscribe ,
827
829
deprecationReason : fieldConfig . deprecationReason ,
@@ -831,20 +833,6 @@ function defineFieldMap<TSource, TContext>(
831
833
} ) ;
832
834
}
833
835
834
- export function defineArguments (
835
- config : GraphQLFieldConfigArgumentMap ,
836
- ) : $ReadOnlyArray < GraphQLArgument > {
837
- return Object . entries ( config ) . map ( ( [ argName , argConfig ] ) => ( {
838
- name : argName ,
839
- description : argConfig . description ,
840
- type : argConfig . type ,
841
- defaultValue : argConfig . defaultValue ,
842
- deprecationReason : argConfig . deprecationReason ,
843
- extensions : argConfig . extensions && toObjMap ( argConfig . extensions ) ,
844
- astNode : argConfig . astNode ,
845
- } ) ) ;
846
- }
847
-
848
836
function isPlainObj ( obj : mixed ) : boolean {
849
837
return isObjectLike ( obj ) && ! Array . isArray ( obj ) ;
850
838
}
@@ -855,7 +843,7 @@ function fieldsToFieldsConfig(
855
843
return mapValue ( fields , ( field ) => ( {
856
844
description : field . description ,
857
845
type : field . type ,
858
- args : argsToArgsConfig ( field . args ) ,
846
+ args : keyValMap ( field . args , ( arg ) => arg . name , inputValueToConfig ) ,
859
847
resolve : field . resolve ,
860
848
subscribe : field . subscribe ,
861
849
deprecationReason : field . deprecationReason ,
@@ -864,26 +852,6 @@ function fieldsToFieldsConfig(
864
852
} ) ) ;
865
853
}
866
854
867
- /**
868
- * @internal
869
- */
870
- export function argsToArgsConfig(
871
- args: $ReadOnlyArray< GraphQLArgument > ,
872
- ): GraphQLFieldConfigArgumentMap {
873
- return keyValMap (
874
- args ,
875
- ( arg ) => arg . name ,
876
- ( arg ) => ( {
877
- description : arg . description ,
878
- type : arg . type ,
879
- defaultValue : arg . defaultValue ,
880
- deprecationReason : arg . deprecationReason ,
881
- extensions : arg . extensions ,
882
- astNode : arg . astNode ,
883
- } ) ,
884
- ) ;
885
- }
886
-
887
855
export type GraphQLObjectTypeConfig < TSource , TContext > = { |
888
856
name : string ,
889
857
description ?: ?string ,
@@ -960,14 +928,7 @@ export type GraphQLFieldConfig<
960
928
961
929
export type GraphQLFieldConfigArgumentMap = ObjMap < GraphQLArgumentConfig > ;
962
930
963
- export type GraphQLArgumentConfig = { |
964
- description ?: ?string ,
965
- type : GraphQLInputType ,
966
- defaultValue ?: mixed ,
967
- extensions ?: ?ReadOnlyObjMapLike < mixed > ,
968
- deprecationReason ?: ?string ,
969
- astNode ?: ?InputValueDefinitionNode ,
970
- | } ;
931
+ export type GraphQLArgumentConfig = GraphQLInputValueConfig ;
971
932
972
933
export type GraphQLFieldConfigMap < TSource , TContext > = ObjMap <
973
934
GraphQLFieldConfig < TSource , TContext > ,
@@ -989,7 +950,55 @@ export type GraphQLField<
989
950
astNode : ?FieldDefinitionNode ,
990
951
| } ;
991
952
992
- export type GraphQLArgument = { |
953
+ export type GraphQLArgument = GraphQLInputValue ;
954
+
955
+ export function isRequiredArgument ( arg : GraphQLArgument ) : boolean % checks {
956
+ return isNonNullType ( arg . type ) && arg . defaultValue === undefined ;
957
+ }
958
+
959
+ export type GraphQLFieldMap < TSource , TContext > = ObjMap <
960
+ GraphQLField < TSource, TContext> ,
961
+ > ;
962
+
963
+ /**
964
+ * @internal
965
+ */
966
+ export function defineInputValue (
967
+ config : GraphQLInputValueConfig ,
968
+ name : string ,
969
+ ) : GraphQLInputValue {
970
+ devAssert (
971
+ ! ( 'resolve' in config ) ,
972
+ `${ name } has a resolve property, but inputs cannot define resolvers.` ,
973
+ ) ;
974
+ return {
975
+ name ,
976
+ description : config . description ,
977
+ type : config . type ,
978
+ defaultValue : config . defaultValue ,
979
+ deprecationReason : config . deprecationReason ,
980
+ extensions : config . extensions && toObjMap ( config . extensions ) ,
981
+ astNode : config . astNode ,
982
+ } ;
983
+ }
984
+
985
+ /**
986
+ * @internal
987
+ */
988
+ export function inputValueToConfig (
989
+ inputValue : GraphQLInputValue ,
990
+ ) : GraphQLInputValueConfig {
991
+ return {
992
+ description : inputValue . description ,
993
+ type : inputValue . type ,
994
+ defaultValue : inputValue . defaultValue ,
995
+ deprecationReason : inputValue . deprecationReason ,
996
+ extensions : inputValue . extensions ,
997
+ astNode : inputValue . astNode ,
998
+ } ;
999
+ }
1000
+
1001
+ export type GraphQLInputValue = { |
993
1002
name : string ,
994
1003
description : ?string ,
995
1004
type : GraphQLInputType ,
@@ -999,13 +1008,14 @@ export type GraphQLArgument = {|
999
1008
astNode : ?InputValueDefinitionNode ,
1000
1009
| } ;
1001
1010
1002
- export function isRequiredArgument ( arg : GraphQLArgument ) : boolean % checks {
1003
- return isNonNullType ( arg . type ) && arg . defaultValue === undefined ;
1004
- }
1005
-
1006
- export type GraphQLFieldMap < TSource , TContext > = ObjMap <
1007
- GraphQLField < TSource, TContext> ,
1008
- > ;
1011
+ export type GraphQLInputValueConfig = { |
1012
+ description ?: ?string ,
1013
+ type : GraphQLInputType ,
1014
+ defaultValue ?: mixed ,
1015
+ deprecationReason ?: ?string ,
1016
+ extensions ?: ?ReadOnlyObjMapLike < mixed > ,
1017
+ astNode ?: ?InputValueDefinitionNode ,
1018
+ | } ;
1009
1019
1010
1020
/**
1011
1021
* Interface Type Definition
@@ -1497,18 +1507,10 @@ export class GraphQLInputObjectType {
1497
1507
}
1498
1508
1499
1509
toConfig ( ) : GraphQLInputObjectTypeNormalizedConfig {
1500
- const fields = mapValue ( this . getFields ( ) , ( field ) => ( {
1501
- description : field . description ,
1502
- type : field . type ,
1503
- defaultValue : field . defaultValue ,
1504
- extensions : field . extensions ,
1505
- astNode : field . astNode ,
1506
- } ) ) ;
1507
-
1508
1510
return {
1509
1511
name : this . name ,
1510
1512
description : this . description ,
1511
- fields,
1513
+ fields : mapValue ( this . getFields ( ) , inputValueToConfig ) ,
1512
1514
extensions : this . extensions ,
1513
1515
astNode : this . astNode ,
1514
1516
extensionASTNodes : this . extensionASTNodes ,
@@ -1542,16 +1544,7 @@ function defineInputFieldMap(
1542
1544
! ( 'resolve' in fieldConfig ) ,
1543
1545
`${ config . name } .${ fieldName } field has a resolve property, but Input Types cannot define resolvers.` ,
1544
1546
) ;
1545
-
1546
- return {
1547
- name : fieldName ,
1548
- description : fieldConfig . description ,
1549
- type : fieldConfig . type ,
1550
- defaultValue : fieldConfig . defaultValue ,
1551
- deprecationReason : fieldConfig . deprecationReason ,
1552
- extensions : fieldConfig . extensions && toObjMap ( fieldConfig . extensions ) ,
1553
- astNode : fieldConfig . astNode ,
1554
- } ;
1547
+ return defineInputValue ( fieldConfig , fieldName ) ;
1555
1548
} ) ;
1556
1549
}
1557
1550
@@ -1571,26 +1564,11 @@ type GraphQLInputObjectTypeNormalizedConfig = {|
1571
1564
extensionASTNodes : $ReadOnlyArray < InputObjectTypeExtensionNode > ,
1572
1565
| } ;
1573
1566
1574
- export type GraphQLInputFieldConfig = { |
1575
- description ?: ?string ,
1576
- type : GraphQLInputType ,
1577
- defaultValue ?: mixed ,
1578
- deprecationReason ?: ?string ,
1579
- extensions ?: ?ReadOnlyObjMapLike < mixed > ,
1580
- astNode ?: ?InputValueDefinitionNode ,
1581
- | } ;
1567
+ export type GraphQLInputFieldConfig = GraphQLInputValueConfig ;
1582
1568
1583
1569
export type GraphQLInputFieldConfigMap = ObjMap < GraphQLInputFieldConfig > ;
1584
1570
1585
- export type GraphQLInputField = { |
1586
- name : string ,
1587
- description : ?string ,
1588
- type : GraphQLInputType ,
1589
- defaultValue : mixed ,
1590
- deprecationReason : ?string ,
1591
- extensions : ?ReadOnlyObjMap < mixed > ,
1592
- astNode : ?InputValueDefinitionNode ,
1593
- | } ;
1571
+ export type GraphQLInputField = GraphQLInputValue ;
1594
1572
1595
1573
export function isRequiredInputField (
1596
1574
field : GraphQLInputField ,
0 commit comments