11/**
22 * Copyright 2016 Yurii Rashkovskii
3- *
3+ * <p>
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
66 * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
7+ * <p>
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ * <p>
1010 * Unless required by applicable law or agreed to in writing, software
1111 * distributed under the License is distributed on an "AS IS" BASIS,
1212 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -104,7 +104,7 @@ public GraphQLFieldDefinition getField(Method method, ProcessingElementsContaine
104104 GraphQLFieldDefinition .Builder builder = newFieldDefinition ();
105105 TypeFunction typeFunction = getTypeFunction (method , container );
106106 builder .name (new MethodNameBuilder (method ).build ());
107- GraphQLOutputType outputType = new MethodTypeBuilder (method , typeFunction , container ).build ();
107+ GraphQLOutputType outputType = ( GraphQLOutputType ) new MethodTypeBuilder (method , typeFunction , container , false ).build ();
108108
109109 boolean isConnection = ConnectionUtil .isConnection (method , outputType );
110110 if (isConnection ) {
@@ -120,12 +120,46 @@ public GraphQLFieldDefinition getField(Method method, ProcessingElementsContaine
120120 return new GraphQLFieldDefinitionWrapper (builder .build ());
121121 }
122122
123+ public GraphQLFieldDefinition getField (Field field , ProcessingElementsContainer container ) throws GraphQLAnnotationsException {
124+ GraphQLFieldDefinition .Builder builder = newFieldDefinition ();
125+ builder .name (new FieldNameBuilder (field ).build ());
126+ TypeFunction typeFunction = getTypeFunction (field , container );
127+
128+ graphql .schema .GraphQLType outputType = typeFunction .buildType (field .getType (), field .getAnnotatedType (), container );
129+ boolean isConnection = ConnectionUtil .isConnection (field , outputType );
130+ if (isConnection ) {
131+ outputType = getGraphQLConnection (field , outputType , container .getRelay (), container .getTypeRegistry ());
132+ builder .argument (container .getRelay ().getConnectionFieldArguments ());
133+ }
134+
135+ builder .type ((GraphQLOutputType ) outputType ).description (new DescriptionBuilder (field ).build ())
136+ .deprecate (new DeprecateBuilder (field ).build ())
137+ .dataFetcher (new FieldDataFetcherBuilder (field , dataFetcherConstructor , outputType , typeFunction , container , isConnection ).build ());
138+
139+ return new GraphQLFieldDefinitionWrapper (builder .build ());
140+ }
141+
142+ public GraphQLInputObjectField getInputField (Method method , ProcessingElementsContainer container ) throws GraphQLAnnotationsException {
143+ GraphQLInputObjectField .Builder builder = newInputObjectField ();
144+ builder .name (new MethodNameBuilder (method ).build ());
145+ TypeFunction typeFunction = getTypeFunction (method , container );
146+ GraphQLInputType inputType = (GraphQLInputType ) new MethodTypeBuilder (method , typeFunction , container , true ).build ();
147+ return builder .type (inputType ).description (new DescriptionBuilder (method ).build ()).build ();
148+ }
149+
150+ public GraphQLInputObjectField getInputField (Field field , ProcessingElementsContainer container ) throws GraphQLAnnotationsException {
151+ GraphQLInputObjectField .Builder builder = newInputObjectField ();
152+ builder .name (new FieldNameBuilder (field ).build ());
153+ TypeFunction typeFunction = getTypeFunction (field , container );
154+ graphql .schema .GraphQLType graphQLType = typeFunction .buildType (true ,field .getType (), field .getAnnotatedType (), container );
155+ return builder .type ((GraphQLInputType ) graphQLType ).description (new DescriptionBuilder (field ).build ()).build ();
156+ }
157+
123158 private GraphQLFieldDefinition handleRelayArguments (Method method , ProcessingElementsContainer container , GraphQLFieldDefinition .Builder builder , GraphQLOutputType outputType , List <GraphQLArgument > args ) {
124159 GraphQLFieldDefinition relayFieldDefinition = null ;
125160 if (method .isAnnotationPresent (GraphQLRelayMutation .class )) {
126161 relayFieldDefinition = buildRelayMutation (method , container , builder , outputType , args );
127- }
128- else {
162+ } else {
129163 builder .argument (args );
130164 }
131165 return relayFieldDefinition ;
@@ -166,24 +200,6 @@ private GraphQLFieldDefinition buildRelayMutation(Method method, ProcessingEleme
166200 return relayFieldDefinition ;
167201 }
168202
169- public GraphQLFieldDefinition getField (Field field , ProcessingElementsContainer container ) throws GraphQLAnnotationsException {
170- GraphQLFieldDefinition .Builder builder = newFieldDefinition ();
171- builder .name (new FieldNameBuilder (field ).build ());
172- TypeFunction typeFunction = getTypeFunction (field , container );
173-
174- GraphQLOutputType outputType = (GraphQLOutputType ) typeFunction .buildType (field .getType (), field .getAnnotatedType (), container );
175- boolean isConnection = ConnectionUtil .isConnection (field , outputType );
176- if (isConnection ) {
177- outputType = getGraphQLConnection (field , outputType , container .getRelay (), container .getTypeRegistry ());
178- builder .argument (container .getRelay ().getConnectionFieldArguments ());
179- }
180-
181- builder .type (outputType ).description (new DescriptionBuilder (field ).build ())
182- .deprecate (new DeprecateBuilder (field ).build ())
183- .dataFetcher (new FieldDataFetcherBuilder (field , dataFetcherConstructor , outputType , typeFunction , container , isConnection ).build ());
184-
185- return new GraphQLFieldDefinitionWrapper (builder .build ());
186- }
187203
188204 private TypeFunction getTypeFunction (Field field , ProcessingElementsContainer container ) {
189205 GraphQLType annotation = field .getAnnotation (GraphQLType .class );
@@ -196,7 +212,7 @@ private TypeFunction getTypeFunction(Field field, ProcessingElementsContainer co
196212 return typeFunction ;
197213 }
198214
199- private GraphQLOutputType getGraphQLConnection (AccessibleObject field , GraphQLOutputType type , Relay relay , Map <String , graphql .schema .GraphQLType > typeRegistry ) {
215+ private GraphQLOutputType getGraphQLConnection (AccessibleObject field , graphql . schema . GraphQLType type , Relay relay , Map <String , graphql .schema .GraphQLType > typeRegistry ) {
200216 if (type instanceof GraphQLNonNull ) {
201217 GraphQLList listType = (GraphQLList ) ((GraphQLNonNull ) type ).getWrappedType ();
202218 return new GraphQLNonNull (internalGetGraphQLConnection (field , listType , relay , typeRegistry ));
@@ -231,5 +247,4 @@ private GraphQLObjectType getActualType(GraphQLObjectType type, Map<String, grap
231247 return type ;
232248 }
233249
234-
235250}
0 commit comments