1717
1818import graphql .schema .*;
1919import graphql .schema .GraphQLNonNull ;
20+ import graphql .schema .GraphQLType ;
2021
2122import java .util .Map ;
2223import java .util .stream .Collectors ;
@@ -25,29 +26,35 @@ public class GraphQLInputObjectRetriever {
2526
2627 public GraphQLInputType getInputObject (graphql .schema .GraphQLType graphQLType , String newNamePrefix , Map <String , graphql .schema .GraphQLType > typeRegistry ) {
2728 if (graphQLType instanceof GraphQLObjectType ) {
28- GraphQLObjectType object = (GraphQLObjectType ) graphQLType ;
29- if (typeRegistry .containsKey (newNamePrefix + object .getName ()) && typeRegistry .get (newNamePrefix + object .getName ()) instanceof GraphQLInputType ) {
30- return (GraphQLInputType ) typeRegistry .get (newNamePrefix + object .getName ());
31- }
32- GraphQLInputObjectType inputObjectType = new GraphQLInputObjectType (newNamePrefix + object .getName (), object .getDescription (),
33- object .getFieldDefinitions ().stream ().
34- map (field -> {
35- GraphQLOutputType type = field .getType ();
36- GraphQLInputType inputType = getInputObject (type , newNamePrefix ,typeRegistry );
37- return new GraphQLInputObjectField (field .getName (), field .getDescription (), inputType , null );
38- }).
39- collect (Collectors .toList ()));
40- typeRegistry .put (inputObjectType .getName (), inputObjectType );
41- return inputObjectType ;
29+ return HandleGraphQLObjectType ((GraphQLObjectType ) graphQLType , newNamePrefix , typeRegistry );
4230 } else if (graphQLType instanceof GraphQLList ) {
4331 return new GraphQLList (getInputObject (((GraphQLList )graphQLType ).getWrappedType (), newNamePrefix ,typeRegistry ));
4432 } else if (graphQLType instanceof graphql .schema .GraphQLNonNull ) {
4533 return new graphql .schema .GraphQLNonNull (getInputObject (((GraphQLNonNull )graphQLType ).getWrappedType (), newNamePrefix ,typeRegistry ));
4634 } else if (graphQLType instanceof GraphQLTypeReference ) {
47- return new GraphQLTypeReference (newNamePrefix + (( GraphQLTypeReference ) graphQLType ).getName ());
35+ return new GraphQLTypeReference (newNamePrefix + (graphQLType ).getName ());
4836 } else if (graphQLType instanceof GraphQLInputType ){
4937 return (GraphQLInputType ) graphQLType ;
5038 }
5139 throw new IllegalArgumentException ("Cannot convert type to input : " +graphQLType );
5240 }
41+
42+ private GraphQLInputType HandleGraphQLObjectType (GraphQLObjectType graphQLType , String newNamePrefix , Map <String , GraphQLType > typeRegistry ) {
43+ GraphQLObjectType object = graphQLType ;
44+ String newObjectName =newNamePrefix + object .getName ();
45+ GraphQLType objectInTypeRegistry =typeRegistry .get (newObjectName );
46+ if (objectInTypeRegistry !=null && objectInTypeRegistry instanceof GraphQLInputType ) {
47+ return (GraphQLInputType ) objectInTypeRegistry ;
48+ }
49+ GraphQLInputObjectType inputObjectType = new GraphQLInputObjectType (newObjectName , object .getDescription (),
50+ object .getFieldDefinitions ().stream ().
51+ map (field -> {
52+ GraphQLOutputType type = field .getType ();
53+ GraphQLInputType inputType = getInputObject (type , newNamePrefix ,typeRegistry );
54+ return new GraphQLInputObjectField (field .getName (), field .getDescription (), inputType , null );
55+ }).
56+ collect (Collectors .toList ()));
57+ typeRegistry .put (inputObjectType .getName (), inputObjectType );
58+ return inputObjectType ;
59+ }
5360}
0 commit comments