@@ -821,7 +821,9 @@ function defineFieldMap<TSource, TContext>(
821821 name : fieldName ,
822822 description : fieldConfig . description ,
823823 type : fieldConfig . type ,
824- args : defineArguments ( argsConfig ) ,
824+ args : Object . entries ( argsConfig ) . map ( ( [ argName , argConfig ] ) =>
825+ defineInputValue ( argConfig , argName ) ,
826+ ) ,
825827 resolve : fieldConfig . resolve ,
826828 subscribe : fieldConfig . subscribe ,
827829 deprecationReason : fieldConfig . deprecationReason ,
@@ -831,20 +833,6 @@ function defineFieldMap<TSource, TContext>(
831833 } ) ;
832834}
833835
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-
848836function isPlainObj ( obj : mixed ) : boolean {
849837 return isObjectLike ( obj ) && ! Array . isArray ( obj ) ;
850838}
@@ -855,7 +843,7 @@ function fieldsToFieldsConfig(
855843 return mapValue ( fields , ( field ) => ( {
856844 description : field . description ,
857845 type : field . type ,
858- args : argsToArgsConfig ( field . args ) ,
846+ args : keyValMap ( field . args , ( arg ) => arg . name , inputValueToConfig ) ,
859847 resolve : field . resolve ,
860848 subscribe : field . subscribe ,
861849 deprecationReason : field . deprecationReason ,
@@ -864,26 +852,6 @@ function fieldsToFieldsConfig(
864852 } ) ) ;
865853}
866854
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-
887855export type GraphQLObjectTypeConfig < TSource , TContext > = { |
888856 name : string ,
889857 description ?: ?string ,
@@ -960,14 +928,7 @@ export type GraphQLFieldConfig<
960928
961929export type GraphQLFieldConfigArgumentMap = ObjMap < GraphQLArgumentConfig > ;
962930
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 ;
971932
972933export type GraphQLFieldConfigMap < TSource , TContext > = ObjMap <
973934 GraphQLFieldConfig < TSource , TContext > ,
@@ -989,7 +950,55 @@ export type GraphQLField<
989950 astNode : ?FieldDefinitionNode ,
990951| } ;
991952
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 = { |
9931002 name : string ,
9941003 description : ?string ,
9951004 type : GraphQLInputType ,
@@ -999,13 +1008,14 @@ export type GraphQLArgument = {|
9991008 astNode : ?InputValueDefinitionNode ,
10001009| } ;
10011010
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+ | } ;
10091019
10101020/**
10111021 * Interface Type Definition
@@ -1497,18 +1507,10 @@ export class GraphQLInputObjectType {
14971507 }
14981508
14991509 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-
15081510 return {
15091511 name : this . name ,
15101512 description : this . description ,
1511- fields,
1513+ fields : mapValue ( this . getFields ( ) , inputValueToConfig ) ,
15121514 extensions : this . extensions ,
15131515 astNode : this . astNode ,
15141516 extensionASTNodes : this . extensionASTNodes ,
@@ -1542,16 +1544,7 @@ function defineInputFieldMap(
15421544 ! ( 'resolve' in fieldConfig ) ,
15431545 `${ config . name } .${ fieldName } field has a resolve property, but Input Types cannot define resolvers.` ,
15441546 ) ;
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 ) ;
15551548 } ) ;
15561549}
15571550
@@ -1571,26 +1564,11 @@ type GraphQLInputObjectTypeNormalizedConfig = {|
15711564 extensionASTNodes : $ReadOnlyArray < InputObjectTypeExtensionNode > ,
15721565| } ;
15731566
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 ;
15821568
15831569export type GraphQLInputFieldConfigMap = ObjMap < GraphQLInputFieldConfig > ;
15841570
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 ;
15941572
15951573export function isRequiredInputField (
15961574 field : GraphQLInputField ,
0 commit comments