@@ -6,32 +6,45 @@ const { getDirectivesUsageStatement } = require('./directiveUsageStatements');
6
6
const { getArgumentDefaultValue } = require ( './argumentDefaultValue' ) ;
7
7
const { joinInlineStatements } = require ( '../helpers/feStatementJoinHelper' ) ;
8
8
const { formatFEStatement } = require ( '../helpers/feStatementFormatHelper' ) ;
9
+ const { addRequired } = require ( '../helpers/addRequiredHelper' ) ;
9
10
10
11
/**
11
12
* Gets the type of the argument with the required keyword.
12
13
* @param {Object } args - arguments object.
13
- * @param {Argument } args.argument - The argument to map.
14
+ * @param {Argument } args.graphqlArgument - The argument to map.
14
15
* @param {IdToNameMap } [args.idToNameMap] - The ID to name map of all available types in model.
15
16
* @returns {string } returns the type of the argument with the required keyword
16
17
*/
17
- const getArgumentType = ( { argument, idToNameMap = { } } ) => {
18
- const argumentType = idToNameMap [ argument . type ] || argument . type ;
19
- return argument . required ? argument . required . replace ( '<Type>' , argumentType ) : argumentType ;
18
+ const getArgumentType = ( { graphqlArgument, idToNameMap = { } } ) => {
19
+ let argumentType = idToNameMap [ graphqlArgument . type ] || graphqlArgument . type ;
20
+
21
+ if ( argumentType === 'List' ) {
22
+ const firstListItem = graphqlArgument . listItems ?. [ 0 ] || { } ;
23
+ const listItemType = idToNameMap [ firstListItem . type ] || firstListItem . type || '' ;
24
+
25
+ if ( ! listItemType ) {
26
+ argumentType = '[]' ;
27
+ } else {
28
+ argumentType = `[${ addRequired ( { type : listItemType , required : firstListItem . required } ) } ]` ;
29
+ }
30
+ }
31
+
32
+ return addRequired ( { type : argumentType , required : graphqlArgument . required } ) ;
20
33
} ;
21
34
22
35
/**
23
36
* Maps an argument to a string with all configured properties.
24
37
* @param {Object } args - arguments object.
25
- * @param {Argument } args.argument - The argument to map.
38
+ * @param {Argument } args.graphqlArgument - The argument to map.
26
39
* @param {IdToNameMap } [args.idToNameMap] - The ID to name map of all available types in model.
27
40
* @returns {FEStatement } returns the argument as a FEStatement
28
41
*/
29
- const mapArgument = ( { argument , idToNameMap = { } } ) => {
30
- const argumentName = `${ argument . name } :` ;
31
- const argumentType = getArgumentType ( { argument , idToNameMap } ) ;
32
- const directivesStatement = getDirectivesUsageStatement ( { directives : argument . directives } ) ;
33
- const defaultValue = argument . default
34
- ? `= ${ getArgumentDefaultValue ( { type : argument . type , defaultValue : argument . default } ) } `
42
+ const mapArgument = ( { graphqlArgument , idToNameMap = { } } ) => {
43
+ const argumentName = `${ graphqlArgument . name } :` ;
44
+ const argumentType = getArgumentType ( { graphqlArgument , idToNameMap } ) ;
45
+ const directivesStatement = getDirectivesUsageStatement ( { directives : graphqlArgument . directives } ) ;
46
+ const defaultValue = graphqlArgument . default
47
+ ? `= ${ getArgumentDefaultValue ( { type : graphqlArgument . type , defaultValue : graphqlArgument . default } ) } `
35
48
: '' ;
36
49
37
50
const statement = joinInlineStatements ( {
@@ -40,7 +53,7 @@ const mapArgument = ({ argument, idToNameMap = {} }) => {
40
53
41
54
return {
42
55
statement,
43
- description : argument . description ,
56
+ description : graphqlArgument . description || '' ,
44
57
} ;
45
58
} ;
46
59
@@ -58,7 +71,11 @@ const getArguments = ({ graphqlArguments, idToNameMap = {} }) => {
58
71
const hasDescription = graphqlArguments . some ( argument => argument . description ) ;
59
72
const argumentStatements = graphqlArguments
60
73
. filter ( argument => argument . name && argument . type )
61
- . map ( argument => mapArgument ( { argument, idToNameMap } ) ) ;
74
+ . map ( graphqlArgument => mapArgument ( { graphqlArgument, idToNameMap } ) ) ;
75
+
76
+ if ( argumentStatements . length === 0 ) {
77
+ return '' ;
78
+ }
62
79
63
80
if ( ! hasDescription ) {
64
81
// For current state of code if arguments don't have any description we return them as a single line
0 commit comments