88import static java .util .stream .Collectors .toList ;
99
1010import java .util .List ;
11- import java .util .function .Function ;
1211import java .util .stream .Stream ;
1312
1413import org .jboss .jandex .MethodParameterInfo ;
@@ -53,15 +52,6 @@ public static ParameterModel of(MethodParameterInfo parameter) {
5352 return new ParameterModel (parameter );
5453 }
5554
56- /**
57- * Checks if the parameter is associated with a {@link Header} annotation, indicating it is a header parameter.
58- *
59- * @return {@code true} if the parameter is a header parameter, otherwise {@code false}.
60- */
61- private boolean isHeaderParameter () {
62- return parameter .hasAnnotation (Header .class );
63- }
64-
6555 /**
6656 * Checks if the parameter is a value parameter, either a root or nested parameter.
6757 *
@@ -125,41 +115,24 @@ public String getDirectiveLocation() {
125115 * @return The GraphQL input type name.
126116 */
127117 public String graphQlInputTypeName () {
128- if (parameter .hasAnnotation (ID )) {
129- if (type .isCollectionOrArray ()) {
130- return "[ID" + arrayOrCollectionHelper (this ::optionalExclamationMark ) + "]" + optionalExclamationMark (type );
131- }
132- return "ID" + optionalExclamationMark (type );
133- } else if (type .isCollectionOrArray ()) {
134- return "[" + arrayOrCollectionHelper (this ::withExclamationMark ) + "]" + optionalExclamationMark (type );
135- } else if (type .isMap ()) {
136- var keyType = type .getMapKeyType ();
137- var valueType = type .getMapValueType ();
138- return "[Entry_" + withExclamationMark (keyType )
139- + "_" + withExclamationMark (valueType ) + "Input]"
140- + optionalExclamationMark (type );
141- } else {
142- return withExclamationMark (type );
143- }
118+ return graphQlInputTypeNameRecursion (type );
144119 }
145120
146- /**
147- * Adds an exclamation mark to the GraphQL input type name if the type is non-nullable.
148- *
149- * @param type The {@link TypeModel} representing the type of the parameter.
150- * @return The GraphQL input type name with an optional exclamation mark.
151- */
152- private String withExclamationMark ( TypeModel type ) {
153- return graphQlInputTypeName ( type ) + optionalExclamationMark ( type ) ;
121+ @ Override
122+ public boolean hasDirectives () {
123+ return ! directives . isEmpty ();
124+ }
125+
126+ @ Override
127+ public List < DirectiveInstance > getDirectives ( ) {
128+ return directives ;
154129 }
155130
156131 /**
157- * Gets the GraphQL input type name for the specified {@code TypeModel}.
158- *
159- * @param type The {@link TypeModel} for which to get the GraphQL input type name.
160- * @return The GraphQL input type name.
132+ * Base type name without container wrappers (no [] for collections/maps) and
133+ * without trailing nullability marker.
161134 */
162- private String graphQlInputTypeName (TypeModel type ) {
135+ private String baseTypeName (TypeModel type ) {
163136 if (type .isSimpleClassType () && !type .isScalar ()) {
164137 if (type .hasClassAnnotation (INPUT )) {
165138 String value = type .getClassAnnotation (INPUT ).orElseThrow ().valueWithDefault (getIndex ()).asString ();
@@ -172,7 +145,7 @@ private String graphQlInputTypeName(TypeModel type) {
172145 }
173146 }
174147 if (Scalars .isScalar (type .getName ())) {
175- return Scalars .getScalar (type .getName ()); // returns simplified name
148+ return Scalars .getScalar (type .getName ());
176149 }
177150 return type .getSimpleName () + (type .isEnum () ? "" : "Input" );
178151 }
@@ -188,22 +161,56 @@ private String optionalExclamationMark(TypeModel type) {
188161 }
189162
190163 /**
191- * Helper method for handling array or collection types in GraphQL input type names.
164+ * Checks if the parameter is associated with a {@link Header} annotation,
165+ * indicating it is a header parameter.
192166 *
193- * @param function The function to apply to the array or collection element type.
194- * @return The GraphQL input type name for array or collection types .
167+ * @return {@code true} if the parameter is a header parameter, otherwise
168+ * {@code false} .
195169 */
196- private String arrayOrCollectionHelper ( Function < TypeModel , String > function ) {
197- return function . apply (( type . isArray () ? type . getArrayElementType () : type . getCollectionElementType ()) );
170+ private boolean isHeaderParameter ( ) {
171+ return parameter . hasAnnotation ( Header . class );
198172 }
199173
200- @ Override
201- public boolean hasDirectives () {
202- return !directives .isEmpty ();
203- }
174+ /**
175+ * Gets the GraphQL input type name for the specified {@code TypeModel}.
176+ *
177+ * @param type The {@link TypeModel} for which to get the GraphQL input type
178+ * name.
179+ * @return The GraphQL input type name.
180+ */
181+ private String graphQlInputTypeNameRecursion (TypeModel type ) {
182+ if (type .isCollectionOrArray ()) {
183+ TypeModel elementType = type .isArray () ? type .getArrayElementType () : type .getCollectionElementType ();
184+ return "[" + graphQlInputTypeNameRecursion (elementType ) + "]" + optionalExclamationMark (type );
185+ }
204186
205- @ Override
206- public List <DirectiveInstance > getDirectives () {
207- return directives ;
187+ if (type .isMap ()) {
188+ var keyType = type .getMapKeyType ();
189+ var valueType = type .getMapValueType ();
190+ String key = baseTypeName (keyType ) + optionalExclamationMark (keyType );
191+ String value = baseTypeName (valueType ) + optionalExclamationMark (valueType );
192+ return "[Entry_" + key + "_" + value + "Input]" + optionalExclamationMark (type );
193+ }
194+
195+ if (parameter .hasAnnotation (ID )) {
196+ return "ID" + optionalExclamationMark (type );
197+ }
198+
199+ if (type .isSimpleClassType () && !type .isScalar ()) {
200+ if (type .hasClassAnnotation (INPUT )) {
201+ String value = type .getClassAnnotation (INPUT ).orElseThrow ().valueWithDefault (getIndex ()).asString ();
202+ if (!value .isEmpty ()) {
203+ return value + optionalExclamationMark (type );
204+ }
205+ }
206+ if (type .hasClassAnnotation (NAME )) {
207+ return type .getClassAnnotation (NAME ).orElseThrow ().value ().asString () + optionalExclamationMark (type );
208+ }
209+ }
210+
211+ if (Scalars .isScalar (type .getName ())) {
212+ return Scalars .getScalar (type .getName ()) + optionalExclamationMark (type );
213+ }
214+ return type .getSimpleName () + (type .isEnum () ? "" : "Input" ) + optionalExclamationMark (type );
208215 }
209216}
0 commit comments