Skip to content

Commit adfa732

Browse files
committed
Merge remote-tracking branch 'imri/refactor-DefaultTypeFunction' into refactoring
2 parents 25dc14b + ee968e1 commit adfa732

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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-
*
7+
* <p>
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
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.
@@ -36,10 +36,9 @@ public class MethodDataFetcher implements DataFetcher {
3636
private final TypeFunction typeFunction;
3737

3838

39-
40-
public MethodDataFetcher(Method method,TypeFunction typeFunction, ProcessingElementsContainer container) {
39+
public MethodDataFetcher(Method method, TypeFunction typeFunction, ProcessingElementsContainer container) {
4140
this.method = method;
42-
this.typeFunction=typeFunction;
41+
this.typeFunction = typeFunction;
4342
this.container = container;
4443
}
4544

@@ -60,15 +59,15 @@ public Object get(DataFetchingEnvironment environment) {
6059
return null;
6160
}
6261
}
63-
return method.invoke(obj, invocationArgs(environment,container));
62+
return method.invoke(obj, invocationArgs(environment, container));
6463
} catch (IllegalAccessException | InvocationTargetException e) {
6564
throw new RuntimeException(e);
6665
}
6766
}
6867

69-
private Object[] invocationArgs(DataFetchingEnvironment environment,ProcessingElementsContainer container) {
68+
private Object[] invocationArgs(DataFetchingEnvironment environment, ProcessingElementsContainer container) {
7069
List<Object> result = new ArrayList<>();
71-
Map<String,Object> envArgs = environment.getArguments();
70+
Map<String, Object> envArgs = environment.getArguments();
7271
for (Parameter p : method.getParameters()) {
7372
String parameterName;
7473
GraphQLName name = p.getAnnotation(GraphQLName.class);
@@ -84,7 +83,7 @@ private Object[] invocationArgs(DataFetchingEnvironment environment,ProcessingEl
8483
continue;
8584
}
8685

87-
graphql.schema.GraphQLType graphQLType = typeFunction.buildType(true, paramType, p.getAnnotatedType(),container);
86+
graphql.schema.GraphQLType graphQLType = typeFunction.buildType(true, paramType, p.getAnnotatedType(), container);
8887
if (envArgs.containsKey(parameterName)) {
8988
result.add(buildArg(p.getParameterizedType(), graphQLType, envArgs.get(parameterName)));
9089
} else {
@@ -112,15 +111,15 @@ private Object buildArg(Type p, GraphQLType graphQLType, Object arg) {
112111
Map map = (Map) arg;
113112
for (Parameter parameter : parameters) {
114113
String name = toGraphqlName(parameter.getAnnotation(GraphQLName.class) != null ? parameter.getAnnotation(GraphQLName.class).value() : parameter.getName());
115-
objects.add(buildArg(parameter.getParameterizedType(), ((GraphQLInputObjectType)graphQLType).getField(name).getType(),map.get(name)));
114+
objects.add(buildArg(parameter.getParameterizedType(), ((GraphQLInputObjectType) graphQLType).getField(name).getType(), map.get(name)));
116115
}
117116
return constructNewInstance(constructor, objects.toArray(new Object[objects.size()]));
118117
}
119118
}
120119
return null;
121120
} else if (p instanceof ParameterizedType && graphQLType instanceof GraphQLList) {
122121
List<Object> list = new ArrayList<>();
123-
Type subType = ((ParameterizedType)p).getActualTypeArguments()[0];
122+
Type subType = ((ParameterizedType) p).getActualTypeArguments()[0];
124123
GraphQLType wrappedType = ((GraphQLList) graphQLType).getWrappedType();
125124

126125
for (Object item : ((List) arg)) {

src/main/java/graphql/annotations/processor/typeFunctions/TypeFunction.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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.
@@ -42,10 +42,16 @@ default String getTypeName(Class<?> aClass, AnnotatedType annotatedType) {
4242
*/
4343
boolean canBuildType(Class<?> aClass, AnnotatedType annotatedType);
4444

45-
45+
/**
46+
*
47+
* @param aClass The java type to build the type name for
48+
* @param annotatedType The {@link AnnotatedType} of the java type, which may be a {link AnnotatedParameterizedType}
49+
* @param container a class that hold several members that are required in order to build schema
50+
* @return The built
51+
*/
4652

4753
default GraphQLType buildType(Class<?> aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) {
48-
return buildType(false, aClass, annotatedType,container);
54+
return buildType(false, aClass, annotatedType, container);
4955
}
5056

5157
/**

0 commit comments

Comments
 (0)