From 69bced4ad4c313e1bc68c7415d48df5c6267059c Mon Sep 17 00:00:00 2001 From: guy120494 Date: Wed, 25 Oct 2017 14:31:23 +0300 Subject: [PATCH 01/25] changed groupid --- build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 74253f69..8287cf28 100644 --- a/build.gradle +++ b/build.gradle @@ -85,7 +85,7 @@ publishing { publications { maven(MavenPublication) { from components.java - groupId 'com.graphql-java' + groupId 'io.github.graphql-java' artifactId project.name version project.version @@ -145,7 +145,6 @@ bintray { publications = ['maven'] publish = true pkg { - userOrg = 'graphql-java' desc = 'This library offers an annotations-based syntax for GraphQL schema definition.' repo = 'graphql-java-annotations' name = 'graphql-java-annotations' From afebbd4270f989da1cba2e8daad2bde9d65d6232 Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 25 Oct 2017 14:35:21 +0200 Subject: [PATCH 02/25] add package typeFunctions with all typeFunction instead of one big class as DefaultTypeFunction --- .../BatchedTypeFunction.java | 10 +- .../typeFunctions/BooleanFunction.java | 45 +++++++ .../typeFunctions/DefaultTypeFunction.java | 120 ++++++++++++++++++ .../typeFunctions/FloatFunction.java | 45 +++++++ .../annotations/typeFunctions/IDFunction.java | 47 +++++++ .../typeFunctions/IntegerFunction.java | 45 +++++++ .../typeFunctions/IterableFunction.java | 57 +++++++++ .../typeFunctions/LongFunction.java | 46 +++++++ .../typeFunctions/ObjectFunction.java | 60 +++++++++ .../typeFunctions/OptionalFunction.java | 69 ++++++++++ .../typeFunctions/StreamFunction.java | 56 ++++++++ .../typeFunctions/StringFunction.java | 44 +++++++ 12 files changed, 641 insertions(+), 3 deletions(-) rename src/main/java/graphql/annotations/{ => typeFunctions}/BatchedTypeFunction.java (84%) create mode 100644 src/main/java/graphql/annotations/typeFunctions/BooleanFunction.java create mode 100644 src/main/java/graphql/annotations/typeFunctions/DefaultTypeFunction.java create mode 100644 src/main/java/graphql/annotations/typeFunctions/FloatFunction.java create mode 100644 src/main/java/graphql/annotations/typeFunctions/IDFunction.java create mode 100644 src/main/java/graphql/annotations/typeFunctions/IntegerFunction.java create mode 100644 src/main/java/graphql/annotations/typeFunctions/IterableFunction.java create mode 100644 src/main/java/graphql/annotations/typeFunctions/LongFunction.java create mode 100644 src/main/java/graphql/annotations/typeFunctions/ObjectFunction.java create mode 100644 src/main/java/graphql/annotations/typeFunctions/OptionalFunction.java create mode 100644 src/main/java/graphql/annotations/typeFunctions/StreamFunction.java create mode 100644 src/main/java/graphql/annotations/typeFunctions/StringFunction.java diff --git a/src/main/java/graphql/annotations/BatchedTypeFunction.java b/src/main/java/graphql/annotations/typeFunctions/BatchedTypeFunction.java similarity index 84% rename from src/main/java/graphql/annotations/BatchedTypeFunction.java rename to src/main/java/graphql/annotations/typeFunctions/BatchedTypeFunction.java index 705e133c..46d46640 100644 --- a/src/main/java/graphql/annotations/BatchedTypeFunction.java +++ b/src/main/java/graphql/annotations/typeFunctions/BatchedTypeFunction.java @@ -12,7 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.typeFunctions; + +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedParameterizedType; import java.lang.reflect.AnnotatedType; @@ -37,7 +41,7 @@ public boolean canBuildType(final Class aClass, final AnnotatedType type) { } @Override - public graphql.schema.GraphQLType buildType(final boolean inputType, final Class aClass, final AnnotatedType annotatedType) { + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { if (!aClass.isAssignableFrom(List.class)) { throw new IllegalArgumentException("Batched method should return a List"); } @@ -52,6 +56,6 @@ public graphql.schema.GraphQLType buildType(final boolean inputType, final Class } else { klass = (Class) arg.getType(); } - return defaultTypeFunction.buildType(inputType, klass, arg); + return defaultTypeFunction.buildType(input, klass, arg,container); } } diff --git a/src/main/java/graphql/annotations/typeFunctions/BooleanFunction.java b/src/main/java/graphql/annotations/typeFunctions/BooleanFunction.java new file mode 100644 index 00000000..57d6e4d0 --- /dev/null +++ b/src/main/java/graphql/annotations/typeFunctions/BooleanFunction.java @@ -0,0 +1,45 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.typeFunctions; + +import graphql.Scalars; +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLType; + +import java.lang.reflect.AnnotatedType; + +class BooleanFunction implements TypeFunction { + + @Override + public String getTypeName(Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLBoolean.getName(); + } + + @Override + public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { + return aClass == Boolean.class || aClass == boolean.class; + } + + @Override + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + return buildType(input,aClass,annotatedType); + } + + private GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLBoolean; + } + +} diff --git a/src/main/java/graphql/annotations/typeFunctions/DefaultTypeFunction.java b/src/main/java/graphql/annotations/typeFunctions/DefaultTypeFunction.java new file mode 100644 index 00000000..6f0c4b4d --- /dev/null +++ b/src/main/java/graphql/annotations/typeFunctions/DefaultTypeFunction.java @@ -0,0 +1,120 @@ +/** + * Copyright 2016 Yurii Rashkovskii + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.typeFunctions; + +import graphql.annotations.GraphQLAnnotationsProcessor; +import graphql.annotations.GraphQLNonNull; +import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLType; +import org.osgi.service.component.annotations.*; + +import java.lang.reflect.AnnotatedType; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +@Component(property = "type=default") +public class DefaultTypeFunction implements TypeFunction { + + protected List otherFunctions = new ArrayList<>(); + + private CopyOnWriteArrayList typeFunctions; + + GraphQLAnnotationsProcessor annotationsProcessor; + + @Override + public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { + return getTypeFunction(aClass, annotatedType) != null; + } + + public void setAnnotationsProcessor(GraphQLAnnotationsProcessor annotationsProcessor) { + this.annotationsProcessor = annotationsProcessor; + } + + + public DefaultTypeFunction(GraphQLInputProcessor graphQLInputProcessor, GraphQLOutputProcessor graphQLOutputProcessor) { + typeFunctions = new CopyOnWriteArrayList<>(); + + typeFunctions.add(new IDFunction()); + typeFunctions.add(new StringFunction()); + typeFunctions.add(new BooleanFunction()); + typeFunctions.add(new FloatFunction()); + typeFunctions.add(new IntegerFunction()); + typeFunctions.add(new LongFunction()); + typeFunctions.add(new IterableFunction(DefaultTypeFunction.this)); + typeFunctions.add(new StreamFunction(DefaultTypeFunction.this)); + typeFunctions.add(new OptionalFunction(DefaultTypeFunction.this)); + typeFunctions.add(new ObjectFunction(graphQLInputProcessor, graphQLOutputProcessor)); + } + + @Reference(cardinality = ReferenceCardinality.MULTIPLE, + policy = ReferencePolicy.DYNAMIC, + service = TypeFunction.class, + target = "(!(type=default))") + void addFunction(TypeFunction function) { + this.otherFunctions.add(function); + } + + void removeFunction(TypeFunction function) { + this.otherFunctions.remove(function); + } + + @Activate + protected void activate() { + for (TypeFunction function : otherFunctions) { + register(function); + } + } + + public Class register(TypeFunction function) { + typeFunctions.add(0, function); + return DefaultTypeFunction.class; + } + + @Override + public String getTypeName(Class aClass, AnnotatedType annotatedType) { + TypeFunction typeFunction = getTypeFunction(aClass, annotatedType); + if (typeFunction == null) { + throw new IllegalArgumentException("unsupported type"); + } + return typeFunction.getTypeName(aClass, annotatedType); + } + + @Override + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + TypeFunction typeFunction = getTypeFunction(aClass, annotatedType); + if (typeFunction == null) { + throw new IllegalArgumentException("unsupported type"); + } + + GraphQLType result = typeFunction.buildType(input, aClass, annotatedType, container); + if (annotatedType != null && annotatedType.isAnnotationPresent(GraphQLNonNull.class)) { + result = new graphql.schema.GraphQLNonNull(result); + } + return result; + } + + private TypeFunction getTypeFunction(Class aClass, AnnotatedType annotatedType) { + for (TypeFunction typeFunction : typeFunctions) { + if (typeFunction.canBuildType(aClass, annotatedType)) { + return typeFunction; + } + } + return null; + } +} diff --git a/src/main/java/graphql/annotations/typeFunctions/FloatFunction.java b/src/main/java/graphql/annotations/typeFunctions/FloatFunction.java new file mode 100644 index 00000000..4131470f --- /dev/null +++ b/src/main/java/graphql/annotations/typeFunctions/FloatFunction.java @@ -0,0 +1,45 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.typeFunctions; + +import graphql.Scalars; +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLType; + +import java.lang.reflect.AnnotatedType; + +class FloatFunction implements TypeFunction { + + @Override + public String getTypeName(Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLFloat.getName(); + } + + @Override + public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { + return aClass == Float.class || aClass == float.class || aClass == Double.class || aClass == double.class; + } + + @Override + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + return buildType(input,aClass,annotatedType); + } + + private GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLFloat; + } + +} diff --git a/src/main/java/graphql/annotations/typeFunctions/IDFunction.java b/src/main/java/graphql/annotations/typeFunctions/IDFunction.java new file mode 100644 index 00000000..cce8dd80 --- /dev/null +++ b/src/main/java/graphql/annotations/typeFunctions/IDFunction.java @@ -0,0 +1,47 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.typeFunctions; + +import graphql.Scalars; +import graphql.annotations.GraphQLID; +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLType; + +import java.lang.reflect.AnnotatedType; + + +class IDFunction implements TypeFunction { + @Override + public String getTypeName(Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLID.getName(); + } + + @Override + public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { + return annotatedType != null + && (aClass == Integer.class || aClass == int.class || aClass == String.class) + && annotatedType.isAnnotationPresent(GraphQLID.class); + } + + @Override + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + return buildType(input,aClass,annotatedType); + } + + private GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLID; + } +} diff --git a/src/main/java/graphql/annotations/typeFunctions/IntegerFunction.java b/src/main/java/graphql/annotations/typeFunctions/IntegerFunction.java new file mode 100644 index 00000000..9888f81f --- /dev/null +++ b/src/main/java/graphql/annotations/typeFunctions/IntegerFunction.java @@ -0,0 +1,45 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.typeFunctions; + +import graphql.Scalars; +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLType; + +import java.lang.reflect.AnnotatedType; + +class IntegerFunction implements TypeFunction { + + @Override + public String getTypeName(Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLInt.getName(); + } + + @Override + public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { + return aClass == Integer.class || aClass == int.class; + } + + @Override + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + return buildType(input,aClass,annotatedType); + } + + private GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLInt; + } + +} diff --git a/src/main/java/graphql/annotations/typeFunctions/IterableFunction.java b/src/main/java/graphql/annotations/typeFunctions/IterableFunction.java new file mode 100644 index 00000000..7f4af80c --- /dev/null +++ b/src/main/java/graphql/annotations/typeFunctions/IterableFunction.java @@ -0,0 +1,57 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.typeFunctions; + +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLList; +import graphql.schema.GraphQLType; + +import java.lang.reflect.AnnotatedParameterizedType; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.ParameterizedType; + +/** + * Support for the Iterable things like Lists / Sets / Collections and so on.. + */ +class IterableFunction implements TypeFunction { + + private DefaultTypeFunction defaultTypeFunction; + + public IterableFunction(DefaultTypeFunction defaultTypeFunction){ + this.defaultTypeFunction=defaultTypeFunction; + } + + @Override + public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { + return Iterable.class.isAssignableFrom(aClass); + } + + @Override + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + if (!(annotatedType instanceof AnnotatedParameterizedType)) { + throw new IllegalArgumentException("List type parameter should be specified"); + } + AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) annotatedType; + AnnotatedType arg = parameterizedType.getAnnotatedActualTypeArguments()[0]; + Class klass; + if (arg.getType() instanceof ParameterizedType) { + klass = (Class) ((ParameterizedType) (arg.getType())).getRawType(); + } else { + klass = (Class) arg.getType(); + } + return new GraphQLList(defaultTypeFunction.buildType(input, klass, arg,container)); + } +} \ No newline at end of file diff --git a/src/main/java/graphql/annotations/typeFunctions/LongFunction.java b/src/main/java/graphql/annotations/typeFunctions/LongFunction.java new file mode 100644 index 00000000..7851d395 --- /dev/null +++ b/src/main/java/graphql/annotations/typeFunctions/LongFunction.java @@ -0,0 +1,46 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.typeFunctions; + +import graphql.Scalars; +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLType; + +import java.lang.reflect.AnnotatedType; + + +class LongFunction implements TypeFunction { + + @Override + public String getTypeName(Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLLong.getName(); + } + + @Override + public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { + return aClass == Long.class || aClass == long.class; + } + + @Override + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + return buildType(input,aClass,annotatedType); + } + + private GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLLong; + } + +} diff --git a/src/main/java/graphql/annotations/typeFunctions/ObjectFunction.java b/src/main/java/graphql/annotations/typeFunctions/ObjectFunction.java new file mode 100644 index 00000000..edbd28a1 --- /dev/null +++ b/src/main/java/graphql/annotations/typeFunctions/ObjectFunction.java @@ -0,0 +1,60 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.typeFunctions; + +import graphql.annotations.GraphQLName; +import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLType; + +import java.lang.reflect.AnnotatedType; + +import static graphql.annotations.util.NamingKit.toGraphqlName; + + +class ObjectFunction implements TypeFunction { + + GraphQLInputProcessor graphQLInputProcessor; + GraphQLOutputProcessor graphQLOutputProcessor; + + public ObjectFunction(GraphQLInputProcessor graphQLInputProcessor,GraphQLOutputProcessor graphQLOutputProcessor) { + this.graphQLInputProcessor = graphQLInputProcessor; + this.graphQLOutputProcessor=graphQLOutputProcessor; + } + + + @Override + public String getTypeName(Class aClass, AnnotatedType annotatedType) { + GraphQLName name = aClass.getAnnotation(GraphQLName.class); + return toGraphqlName(name == null ? aClass.getSimpleName() : name.value()); + } + + @Override + public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { + return true; + } + + @Override + public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + if (inputType) { + return graphQLInputProcessor.getInputObject(aClass, container); + } else { + return graphQLOutputProcessor.getOutputTypeOrRef(aClass,container); + } + } + +} diff --git a/src/main/java/graphql/annotations/typeFunctions/OptionalFunction.java b/src/main/java/graphql/annotations/typeFunctions/OptionalFunction.java new file mode 100644 index 00000000..922b9a6c --- /dev/null +++ b/src/main/java/graphql/annotations/typeFunctions/OptionalFunction.java @@ -0,0 +1,69 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.typeFunctions; + +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLType; + +import java.lang.reflect.AnnotatedParameterizedType; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.ParameterizedType; +import java.util.Optional; + +class OptionalFunction implements TypeFunction { + + private DefaultTypeFunction defaultTypeFunction; + + public OptionalFunction(DefaultTypeFunction defaultTypeFunction){ + this.defaultTypeFunction=defaultTypeFunction; + } + + @Override + public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { + return aClass == Optional.class; + } + + @Override + public String getTypeName(Class aClass, AnnotatedType annotatedType) { + AnnotatedType arg = getAnnotatedType(annotatedType); + return defaultTypeFunction.getTypeName(getClass(annotatedType), arg); + } + + @Override + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + AnnotatedType arg = getAnnotatedType(annotatedType); + return defaultTypeFunction.buildType(input, getClass(annotatedType), arg,container); + } + + private AnnotatedType getAnnotatedType(AnnotatedType annotatedType) { + if (!(annotatedType instanceof AnnotatedParameterizedType)) { + throw new IllegalArgumentException("Optional type parameter should be specified"); + } + AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) annotatedType; + return parameterizedType.getAnnotatedActualTypeArguments()[0]; + } + + private Class getClass(AnnotatedType annotatedType) { + AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) annotatedType; + AnnotatedType arg = parameterizedType.getAnnotatedActualTypeArguments()[0]; + if (arg.getType() instanceof ParameterizedType) { + return (Class) ((ParameterizedType) (arg.getType())).getRawType(); + } else { + return (Class) arg.getType(); + } + } +} + diff --git a/src/main/java/graphql/annotations/typeFunctions/StreamFunction.java b/src/main/java/graphql/annotations/typeFunctions/StreamFunction.java new file mode 100644 index 00000000..171df56f --- /dev/null +++ b/src/main/java/graphql/annotations/typeFunctions/StreamFunction.java @@ -0,0 +1,56 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.typeFunctions; + +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLList; +import graphql.schema.GraphQLType; + +import java.lang.reflect.AnnotatedParameterizedType; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.ParameterizedType; +import java.util.stream.Stream; + +class StreamFunction implements TypeFunction { + + private DefaultTypeFunction defaultTypeFunction; + + public StreamFunction(DefaultTypeFunction defaultTypeFunction){ + this.defaultTypeFunction=defaultTypeFunction; + } + + @Override + public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { + return Stream.class.isAssignableFrom(aClass); + } + + + @Override + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + if (!(annotatedType instanceof AnnotatedParameterizedType)) { + throw new IllegalArgumentException("Stream type parameter should be specified"); + } + AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) annotatedType; + AnnotatedType arg = parameterizedType.getAnnotatedActualTypeArguments()[0]; + Class klass; + if (arg.getType() instanceof ParameterizedType) { + klass = (Class) ((ParameterizedType) (arg.getType())).getRawType(); + } else { + klass = (Class) arg.getType(); + } + return new GraphQLList(defaultTypeFunction.buildType(input, klass, arg,container)); + } +} diff --git a/src/main/java/graphql/annotations/typeFunctions/StringFunction.java b/src/main/java/graphql/annotations/typeFunctions/StringFunction.java new file mode 100644 index 00000000..b8d5fe06 --- /dev/null +++ b/src/main/java/graphql/annotations/typeFunctions/StringFunction.java @@ -0,0 +1,44 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.typeFunctions; + +import graphql.Scalars; +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.TypeFunction; +import graphql.schema.GraphQLType; + +import java.lang.reflect.AnnotatedType; + +class StringFunction implements TypeFunction { + + @Override + public String getTypeName(Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLString.getName(); + } + + @Override + public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { + return aClass == String.class; + } + + @Override + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + return buildType(input,aClass,annotatedType); + } + + private GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { + return Scalars.GraphQLString; + } +} \ No newline at end of file From 3c8ac4d24c683f4ca03a80e26225c8e687b58e2a Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 13:05:16 +0200 Subject: [PATCH 03/25] create package builders --- .../annotations/builders/EnumBuilder.java | 63 +++++++++++ .../builders/InterfaceBuilder.java | 67 ++++++++++++ .../annotations/builders/ObjectBuilder.java | 102 ++++++++++++++++++ .../annotations/builders/UnionBuilder.java | 70 ++++++++++++ 4 files changed, 302 insertions(+) create mode 100644 src/main/java/graphql/annotations/builders/EnumBuilder.java create mode 100644 src/main/java/graphql/annotations/builders/InterfaceBuilder.java create mode 100644 src/main/java/graphql/annotations/builders/ObjectBuilder.java create mode 100644 src/main/java/graphql/annotations/builders/UnionBuilder.java diff --git a/src/main/java/graphql/annotations/builders/EnumBuilder.java b/src/main/java/graphql/annotations/builders/EnumBuilder.java new file mode 100644 index 00000000..89073de5 --- /dev/null +++ b/src/main/java/graphql/annotations/builders/EnumBuilder.java @@ -0,0 +1,63 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.builders; + +import graphql.annotations.GraphQLDescription; +import graphql.annotations.GraphQLName; +import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.schema.GraphQLEnumType; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.List; + +import static graphql.schema.GraphQLEnumType.newEnum; + +public class EnumBuilder { + + private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; + + public EnumBuilder(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever) { + this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; + } + + public GraphQLEnumType.Builder getEnumBuilder(Class aClass) { + String typeName = graphQLObjectInfoRetriever.getTypeName(aClass); + //noinspection unchecked + Class enumClass = (Class) aClass; + GraphQLEnumType.Builder builder = newEnum(); + builder.name(typeName); + + GraphQLDescription description = aClass.getAnnotation(GraphQLDescription.class); + if (description != null) { + builder.description(description.value()); + } + + List constants = Arrays.asList(enumClass.getEnumConstants()); + + Arrays.stream(enumClass.getEnumConstants()).map(Enum::name).forEachOrdered(n -> { + try { + Field field = aClass.getField(n); + GraphQLName fieldName = field.getAnnotation(GraphQLName.class); + GraphQLDescription fieldDescription = field.getAnnotation(GraphQLDescription.class); + Enum constant = constants.stream().filter(c -> c.name().contentEquals(n)).findFirst().get(); + String name_ = fieldName == null ? n : fieldName.value(); + builder.value(name_, constant, fieldDescription == null ? name_ : fieldDescription.value()); + } catch (NoSuchFieldException ignore) { + } + }); + return builder; + } +} diff --git a/src/main/java/graphql/annotations/builders/InterfaceBuilder.java b/src/main/java/graphql/annotations/builders/InterfaceBuilder.java new file mode 100644 index 00000000..4dbe5f3e --- /dev/null +++ b/src/main/java/graphql/annotations/builders/InterfaceBuilder.java @@ -0,0 +1,67 @@ +package graphql.annotations.builders; + +import graphql.annotations.*; +import graphql.annotations.searchAlgorithms.CannotCastMemberException; +import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.schema.GraphQLFieldDefinition; +import graphql.schema.GraphQLInterfaceType; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import static graphql.annotations.ReflectionKit.newInstance; +import static graphql.schema.GraphQLInterfaceType.newInterface; +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +public class InterfaceBuilder { + + private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; + private GraphQLFieldRetriever graphQLFieldRetriever; + + public InterfaceBuilder(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever,GraphQLFieldRetriever graphQLFieldRetriever) { + this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; + this.graphQLFieldRetriever=graphQLFieldRetriever; + } + public GraphQLInterfaceType.Builder getInterfaceBuilder(Class iface, ProcessingElementsContainer container) throws GraphQLAnnotationsException, + IllegalArgumentException, CannotCastMemberException { + if (!iface.isInterface()) { + throw new IllegalArgumentException(iface + " is not an interface"); + } + GraphQLInterfaceType.Builder builder = newInterface(); + + builder.name(graphQLObjectInfoRetriever.getTypeName(iface)); + GraphQLDescription description = iface.getAnnotation(GraphQLDescription.class); + if (description != null) { + builder.description(description.value()); + } + List definedFields = new ArrayList<>(); + for (Method method : graphQLObjectInfoRetriever.getOrderedMethods(iface)) { + boolean valid = !Modifier.isStatic(method.getModifiers()) && + method.getAnnotation(GraphQLField.class) != null; + if (valid) { + GraphQLFieldDefinition gqlField = graphQLFieldRetriever.getField(method,container); + definedFields.add(gqlField.getName()); + builder.field(gqlField); + } + } + builder.fields(graphQLFieldRetriever.getExtensionFields(iface, definedFields,container)); + + GraphQLTypeResolver typeResolver = iface.getAnnotation(GraphQLTypeResolver.class); + builder.typeResolver(newInstance(typeResolver.value())); + return builder; + } +} diff --git a/src/main/java/graphql/annotations/builders/ObjectBuilder.java b/src/main/java/graphql/annotations/builders/ObjectBuilder.java new file mode 100644 index 00000000..d4e9f9b6 --- /dev/null +++ b/src/main/java/graphql/annotations/builders/ObjectBuilder.java @@ -0,0 +1,102 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.builders; + +import graphql.annotations.*; +import graphql.annotations.searchAlgorithms.BreadthFirstSearch; +import graphql.annotations.searchAlgorithms.ParentalSearch; +import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.annotations.util.GraphQLOutputObjectRetriever; +import graphql.schema.GraphQLFieldDefinition; +import graphql.schema.GraphQLInterfaceType; +import graphql.schema.GraphQLObjectType; +import graphql.schema.GraphQLTypeReference; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import static graphql.annotations.util.ObjectUtil.getAllFields; +import static graphql.schema.GraphQLObjectType.newObject; + + +public class ObjectBuilder { + private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; + private BreadthFirstSearch breadthFirstSearch; + private ParentalSearch parentalSearch; + private GraphQLFieldRetriever graphQLFieldRetriever; + private InterfaceBuilder interfaceBuilder; + private GraphQLInterfaceRetriever graphQLInterfaceRetriever; + + public ObjectBuilder(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, ParentalSearch parentalSearch, BreadthFirstSearch breadthFirstSearch,GraphQLFieldRetriever graphQLFieldRetriever,InterfaceBuilder interfaceBuilder,GraphQLInterfaceRetriever graphQLInterfaceRetriever) { + this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; + this.breadthFirstSearch=breadthFirstSearch; + this.parentalSearch=parentalSearch; + this.graphQLFieldRetriever=graphQLFieldRetriever; + this.interfaceBuilder=interfaceBuilder; + this.graphQLInterfaceRetriever=graphQLInterfaceRetriever; + } + + public GraphQLObjectType.Builder getObjectBuilder(Class object, ProcessingElementsContainer container, GraphQLOutputObjectRetriever outputObjectRetriever) throws GraphQLAnnotationsException { + GraphQLObjectType.Builder builder = newObject(); + builder.name(graphQLObjectInfoRetriever.getTypeName(object)); + GraphQLDescription description = object.getAnnotation(GraphQLDescription.class); + if (description != null) { + builder.description(description.value()); + } + List fieldsDefined = new ArrayList<>(); + for (Method method : graphQLObjectInfoRetriever.getOrderedMethods(object)) { + if (method.isBridge() || method.isSynthetic()) { + continue; + } + if (breadthFirstSearch.search(method)) { + GraphQLFieldDefinition gqlField = graphQLFieldRetriever.getField(method,container); + fieldsDefined.add(gqlField.getName()); + builder.field(gqlField); + } + } + + for (Field field : getAllFields(object).values()) { + if (Modifier.isStatic(field.getModifiers())) { + continue; + } + if (parentalSearch.search(field)) { + GraphQLFieldDefinition gqlField = graphQLFieldRetriever.getField(field,container); + fieldsDefined.add(gqlField.getName()); + builder.field(gqlField); + } + } + + for (Class iface : object.getInterfaces()) { + if (iface.getAnnotation(GraphQLTypeResolver.class) != null) { + String ifaceName = graphQLObjectInfoRetriever.getTypeName(iface); + if (container.getProcessing().contains(ifaceName)) { + builder.withInterface(new GraphQLTypeReference(ifaceName)); + } else { + builder.withInterface((GraphQLInterfaceType) graphQLInterfaceRetriever.getInterface(iface,container)); + } + builder.fields(graphQLFieldRetriever.getExtensionFields(iface, fieldsDefined,container)); + } + } + + builder.fields(graphQLFieldRetriever.getExtensionFields(object, fieldsDefined,container)); + + return builder; + } + + +} diff --git a/src/main/java/graphql/annotations/builders/UnionBuilder.java b/src/main/java/graphql/annotations/builders/UnionBuilder.java new file mode 100644 index 00000000..dd36e57f --- /dev/null +++ b/src/main/java/graphql/annotations/builders/UnionBuilder.java @@ -0,0 +1,70 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.builders; + + +import graphql.annotations.*; +import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.schema.GraphQLObjectType; +import graphql.schema.GraphQLUnionType; + +import java.util.Arrays; +import java.util.function.Function; + +import static graphql.schema.GraphQLUnionType.newUnionType; + +public class UnionBuilder { + + private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; + + public UnionBuilder(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever) { + this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; + } + + public GraphQLUnionType.Builder getUnionBuilder(Class iface, ProcessingElementsContainer container) throws GraphQLAnnotationsException, IllegalArgumentException { + if (!iface.isInterface()) { + throw new IllegalArgumentException(iface + " is not an interface"); + } + GraphQLUnionType.Builder builder = newUnionType(); + + GraphQLUnion unionAnnotation = iface.getAnnotation(GraphQLUnion.class); + builder.name(graphQLObjectInfoRetriever.getTypeName(iface)); + GraphQLDescription description = iface.getAnnotation(GraphQLDescription.class); + if (description != null) { + builder.description(description.value()); + } + graphql.annotations.GraphQLType typeAnnotation = iface.getAnnotation(graphql.annotations.GraphQLType.class); + + TypeFunction typeFunction = container.getDefaultTypeFunction(); + + if (typeAnnotation != null) { + typeFunction = ReflectionKit.newInstance(typeAnnotation.value()); + } + + TypeFunction finalTypeFunction = typeFunction; + Arrays.asList(unionAnnotation.possibleTypes()).stream() + .map(new Function, graphql.schema.GraphQLType>() { + @Override + public graphql.schema.GraphQLType apply(Class aClass) { + return finalTypeFunction.buildType(aClass, null,container); + } + }) + .map(v -> (GraphQLObjectType) v) + .forEach(builder::possibleType); + + builder.typeResolver(new UnionTypeResolver(unionAnnotation.possibleTypes(), container)); + return builder; + } +} From de906ac00101b46f628159a1cfe1ac060379e44d Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 13:07:02 +0200 Subject: [PATCH 04/25] create graphQLProcessors for input and output --- .../GraphQLInputProcessor.java | 59 +++++++++++++++++++ .../GraphQLOutputProcessor.java | 49 +++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java create mode 100644 src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java diff --git a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java new file mode 100644 index 00000000..7f989b63 --- /dev/null +++ b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java @@ -0,0 +1,59 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.graphQLProcessors; + + +import graphql.annotations.GraphQLInputObjectRetriever; +import graphql.annotations.GraphQLObjectHandler; +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.schema.GraphQLInputObjectType; +import graphql.schema.GraphQLType; + +import java.util.Map; + +public class GraphQLInputProcessor { + + private static final String DEFAULT_INPUT_PREFIX = "Input"; + + private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; + private GraphQLObjectHandler graphQLObjectHandler; + private GraphQLInputObjectRetriever graphQLInputObjectRetriever; + + public GraphQLInputProcessor(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever,GraphQLObjectHandler graphQLObjectHandler,GraphQLInputObjectRetriever graphQLInputObjectRetriever){ + this.graphQLObjectInfoRetriever=graphQLObjectInfoRetriever; + this.graphQLObjectHandler=graphQLObjectHandler; + this.graphQLInputObjectRetriever=graphQLInputObjectRetriever; + } + + public GraphQLInputProcessor(){ + this(new GraphQLObjectInfoRetriever(), new GraphQLObjectHandler(),new GraphQLInputObjectRetriever()); + } + public GraphQLInputObjectType getInputObject(Class object, ProcessingElementsContainer container) { + String typeName = DEFAULT_INPUT_PREFIX + graphQLObjectInfoRetriever.getTypeName(object); + Map typeRegistry = container.getTypeRegistry(); + + if (typeRegistry.containsKey(typeName)) { + return (GraphQLInputObjectType) container.getTypeRegistry().get(typeName); + } else { + graphql.schema.GraphQLType graphQLType = graphQLObjectHandler.getObject(object,container); + GraphQLInputObjectType inputObject = (GraphQLInputObjectType) graphQLInputObjectRetriever.getInputObject(graphQLType, DEFAULT_INPUT_PREFIX,typeRegistry); + typeRegistry.put(inputObject.getName(), inputObject); + return inputObject; + } + } + + +} diff --git a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java new file mode 100644 index 00000000..98efb7d5 --- /dev/null +++ b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java @@ -0,0 +1,49 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.graphQLProcessors; + + +import graphql.annotations.GraphQLAnnotationsException; +import graphql.annotations.ProcessingElementsContainer; +import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.annotations.util.GraphQLOutputObjectRetriever; +import graphql.schema.GraphQLOutputType; +import graphql.schema.GraphQLTypeReference; + +public class GraphQLOutputProcessor { + + private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; + private GraphQLOutputObjectRetriever outputObjectRetriever; + + + public GraphQLOutputProcessor(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLOutputObjectRetriever outputObjectRetriever) { + this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; + this.outputObjectRetriever = outputObjectRetriever; + } + + public GraphQLOutputProcessor() { + this(new GraphQLObjectInfoRetriever(), new GraphQLOutputObjectRetriever()); + } + + public GraphQLOutputType getOutputTypeOrRef(Class object, ProcessingElementsContainer container) throws GraphQLAnnotationsException { + String typeName = graphQLObjectInfoRetriever.getTypeName(object); + if (container.getProcessing().contains(typeName)) { + return new GraphQLTypeReference(typeName); + } + + return outputObjectRetriever.getOutputType(object, container); + } + +} From 19552eacf8bab22cf54514e1b35976df1bc1db82 Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 13:08:14 +0200 Subject: [PATCH 05/25] create package with searchAlgorithms --- .../searchAlgorithms/BreadthFirstSearch.java | 78 +++++++++++++++++++ .../CannotCastMemberException.java | 25 ++++++ .../searchAlgorithms/ParentalSearch.java | 59 ++++++++++++++ .../searchAlgorithms/SearchAlgorithm.java | 21 +++++ 4 files changed, 183 insertions(+) create mode 100644 src/main/java/graphql/annotations/searchAlgorithms/BreadthFirstSearch.java create mode 100644 src/main/java/graphql/annotations/searchAlgorithms/CannotCastMemberException.java create mode 100644 src/main/java/graphql/annotations/searchAlgorithms/ParentalSearch.java create mode 100644 src/main/java/graphql/annotations/searchAlgorithms/SearchAlgorithm.java diff --git a/src/main/java/graphql/annotations/searchAlgorithms/BreadthFirstSearch.java b/src/main/java/graphql/annotations/searchAlgorithms/BreadthFirstSearch.java new file mode 100644 index 00000000..4a08a8ea --- /dev/null +++ b/src/main/java/graphql/annotations/searchAlgorithms/BreadthFirstSearch.java @@ -0,0 +1,78 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.searchAlgorithms; + +import graphql.annotations.util.GraphQLObjectInfoRetriever; + +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.util.LinkedList; +import java.util.List; + + +public class BreadthFirstSearch implements SearchAlgorithm { + + private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; + + public BreadthFirstSearch(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever) { + this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; + } + + @Override + public boolean search(Member member) throws CannotCastMemberException { + Method method=CastToMethod(member); + final List> queue = new LinkedList<>(); + final String methodName = method.getName(); + final Class[] parameterTypes = method.getParameterTypes(); + queue.add(method.getDeclaringClass()); + do { + Class cls = queue.remove(0); + + try { + method = cls.getDeclaredMethod(methodName, parameterTypes); + Boolean gqf = graphQLObjectInfoRetriever.isGraphQLField(method); + if (gqf != null) { + return gqf; + } + } catch (NoSuchMethodException e) { + } + + Boolean gqf = graphQLObjectInfoRetriever.isGraphQLField(cls); + if (gqf != null) { + return gqf; + } + + // add interfaces to places to search + for (Class iface : cls.getInterfaces()) { + queue.add(iface); + } + // add parent class to places to search + Class nxt = cls.getSuperclass(); + if (nxt != null) { + queue.add(nxt); + } + } while (!queue.isEmpty()); + return false; + } + + private Method CastToMethod(Member member) throws CannotCastMemberException { + if(!(member instanceof Method)){ + throw new CannotCastMemberException(member.getName(),"Method"); + } + else { + return (Method)member; + } + } +} diff --git a/src/main/java/graphql/annotations/searchAlgorithms/CannotCastMemberException.java b/src/main/java/graphql/annotations/searchAlgorithms/CannotCastMemberException.java new file mode 100644 index 00000000..23c88acc --- /dev/null +++ b/src/main/java/graphql/annotations/searchAlgorithms/CannotCastMemberException.java @@ -0,0 +1,25 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.searchAlgorithms; + + +public class CannotCastMemberException extends RuntimeException { + + private static final String message = "expected member {0} to be {1},but wasn't. Could not cast"; + + public CannotCastMemberException(String memberName, String memberType) { + super(String.format(message, memberName, memberType)); + } +} diff --git a/src/main/java/graphql/annotations/searchAlgorithms/ParentalSearch.java b/src/main/java/graphql/annotations/searchAlgorithms/ParentalSearch.java new file mode 100644 index 00000000..9c4120e5 --- /dev/null +++ b/src/main/java/graphql/annotations/searchAlgorithms/ParentalSearch.java @@ -0,0 +1,59 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.searchAlgorithms; + +import graphql.annotations.util.GraphQLObjectInfoRetriever; + +import java.lang.reflect.Field; +import java.lang.reflect.Member; + + +public class ParentalSearch implements SearchAlgorithm { + private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; + + public ParentalSearch(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever) { + this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; + } + + @Override + public boolean search(Member member) throws CannotCastMemberException { + Field field=CastToField(member); + Boolean gqf = graphQLObjectInfoRetriever.isGraphQLField(field); + if (gqf != null) { + return gqf; + } + Class cls = field.getDeclaringClass(); + + do { + gqf = graphQLObjectInfoRetriever.isGraphQLField(cls); + if (gqf != null) { + return gqf; + } + cls = cls.getSuperclass(); + } while (cls != null); + return false; + } + + private Field CastToField(Member member) throws CannotCastMemberException { + if(!(member instanceof Field)){ + throw new CannotCastMemberException(member.getName(),"Field"); + } + else + { + return (Field) member; + } + + } +} diff --git a/src/main/java/graphql/annotations/searchAlgorithms/SearchAlgorithm.java b/src/main/java/graphql/annotations/searchAlgorithms/SearchAlgorithm.java new file mode 100644 index 00000000..d57702d0 --- /dev/null +++ b/src/main/java/graphql/annotations/searchAlgorithms/SearchAlgorithm.java @@ -0,0 +1,21 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.searchAlgorithms; + +import java.lang.reflect.Member; + +public interface SearchAlgorithm { + boolean search(Member member) throws CannotCastMemberException; +} From 442f3442143d6bc959a6eadf78109c3d33bb8dd5 Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 13:11:05 +0200 Subject: [PATCH 06/25] refactor annotation --- .../annotations/BatchedMethodDataFetcher.java | 11 +- .../annotations/ConnectionDataFetcher.java | 63 ++ .../annotations/DefaultTypeFunction.java | 345 -------- .../annotations/GraphQLAnnotations.java | 818 +----------------- .../GraphQLAnnotationsProcessor.java | 216 ++--- .../annotations/GraphQLFieldRetriever.java | 372 ++++++++ .../GraphQLInputObjectRetriever.java | 53 ++ .../GraphQLInterfaceRetriever.java | 19 + .../annotations/GraphQLObjectHandler.java | 42 + .../java/graphql/annotations/GraphQLType.java | 2 + .../annotations/MethodDataFetcher.java | 26 +- .../ProcessingElementsContainer.java | 87 ++ .../graphql/annotations/ReflectionKit.java | 10 +- .../graphql/annotations/TypeFunction.java | 17 +- .../annotations/UnionTypeResolver.java | 45 + .../util/GraphQLObjectInfoRetriever.java | 52 ++ .../util/GraphQLOutputObjectRetriever.java | 71 ++ .../graphql/annotations/util/ObjectUtil.java | 38 + 18 files changed, 1014 insertions(+), 1273 deletions(-) create mode 100644 src/main/java/graphql/annotations/ConnectionDataFetcher.java delete mode 100644 src/main/java/graphql/annotations/DefaultTypeFunction.java create mode 100644 src/main/java/graphql/annotations/GraphQLFieldRetriever.java create mode 100644 src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java create mode 100644 src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java create mode 100644 src/main/java/graphql/annotations/GraphQLObjectHandler.java create mode 100644 src/main/java/graphql/annotations/ProcessingElementsContainer.java create mode 100644 src/main/java/graphql/annotations/UnionTypeResolver.java create mode 100644 src/main/java/graphql/annotations/util/GraphQLObjectInfoRetriever.java create mode 100644 src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java create mode 100644 src/main/java/graphql/annotations/util/ObjectUtil.java diff --git a/src/main/java/graphql/annotations/BatchedMethodDataFetcher.java b/src/main/java/graphql/annotations/BatchedMethodDataFetcher.java index bbacef8a..821a372f 100644 --- a/src/main/java/graphql/annotations/BatchedMethodDataFetcher.java +++ b/src/main/java/graphql/annotations/BatchedMethodDataFetcher.java @@ -21,15 +21,10 @@ import java.lang.reflect.Modifier; public class BatchedMethodDataFetcher extends MethodDataFetcher { - public BatchedMethodDataFetcher(Method method) { - super(method); - if (!Modifier.isStatic(method.getModifiers())) { - throw new IllegalArgumentException("Batched method should be static"); - } - } - public BatchedMethodDataFetcher(Method method, TypeFunction typeFunction) { - super(method, typeFunction); + + public BatchedMethodDataFetcher(Method method,TypeFunction typeFunction, ProcessingElementsContainer container) { + super(method,typeFunction, container); if (!Modifier.isStatic(method.getModifiers())) { throw new IllegalArgumentException("Batched method should be static"); } diff --git a/src/main/java/graphql/annotations/ConnectionDataFetcher.java b/src/main/java/graphql/annotations/ConnectionDataFetcher.java new file mode 100644 index 00000000..8e95bc9c --- /dev/null +++ b/src/main/java/graphql/annotations/ConnectionDataFetcher.java @@ -0,0 +1,63 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations; + +import graphql.schema.DataFetcher; +import graphql.schema.DataFetchingEnvironment; +import graphql.schema.DataFetchingEnvironmentImpl; + +import java.lang.reflect.Constructor; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Optional; + +import static graphql.annotations.ReflectionKit.constructNewInstance; + + class ConnectionDataFetcher implements DataFetcher { + private final Class connection; + private final DataFetcher actualDataFetcher; + private final Constructor constructor; + + public ConnectionDataFetcher(Class connection, DataFetcher actualDataFetcher) { + this.connection = connection; + Optional> constructor = + Arrays.asList(connection.getConstructors()).stream(). + filter(c -> c.getParameterCount() == 1). + map(c -> (Constructor) c). + findFirst(); + if (constructor.isPresent()) { + this.constructor = constructor.get(); + } else { + throw new IllegalArgumentException(connection + " doesn't have a single argument constructor"); + } + this.actualDataFetcher = actualDataFetcher; + } + + @Override + public Object get(DataFetchingEnvironment environment) { + // Create a list of arguments with connection specific arguments excluded + HashMap arguments = new HashMap<>(environment.getArguments()); + arguments.keySet().removeAll(Arrays.asList("first", "last", "before", "after")); + DataFetchingEnvironment env = new DataFetchingEnvironmentImpl(environment.getSource(), arguments, environment.getContext(), + environment.getRoot(), environment.getFieldDefinition(), environment.getFields(), environment.getFieldType(), environment.getParentType(), environment.getGraphQLSchema(), + environment.getFragmentsByName(), environment.getExecutionId(), environment.getSelectionSet(), environment.getFieldTypeInfo()); + Object data = actualDataFetcher.get(env); + if (data != null) { + Connection conn = constructNewInstance(constructor, data); + return conn.get(environment); + } + return null; + } +} diff --git a/src/main/java/graphql/annotations/DefaultTypeFunction.java b/src/main/java/graphql/annotations/DefaultTypeFunction.java deleted file mode 100644 index 7489387b..00000000 --- a/src/main/java/graphql/annotations/DefaultTypeFunction.java +++ /dev/null @@ -1,345 +0,0 @@ -/** - * Copyright 2016 Yurii Rashkovskii - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - */ -package graphql.annotations; - -import graphql.Scalars; -import graphql.schema.GraphQLList; -import graphql.schema.GraphQLType; -import org.osgi.service.component.annotations.*; - -import java.lang.reflect.AnnotatedParameterizedType; -import java.lang.reflect.AnnotatedType; -import java.lang.reflect.ParameterizedType; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.stream.Stream; - -import static graphql.annotations.util.NamingKit.toGraphqlName; - -@Component(property = "type=default") -public class DefaultTypeFunction implements TypeFunction { - - protected List otherFunctions = new ArrayList<>(); - - private CopyOnWriteArrayList typeFunctions; - - GraphQLAnnotationsProcessor annotationsProcessor; - - @Override - public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { - return getTypeFunction(aClass, annotatedType) != null; - } - - void setAnnotationsProcessor(GraphQLAnnotationsProcessor annotationsProcessor) { - this.annotationsProcessor = annotationsProcessor; - } - - private class IDFunction implements TypeFunction { - @Override - public String getTypeName(Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLID.getName(); - } - - @Override - public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { - return annotatedType != null - && (aClass == Integer.class || aClass == int.class || aClass == String.class) - && annotatedType.isAnnotationPresent(GraphQLID.class); - } - - @Override - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLID; - } - } - - private class StringFunction implements TypeFunction { - - @Override - public String getTypeName(Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLString.getName(); - } - - @Override - public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { - return aClass == String.class; - } - - @Override - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLString; - } - } - - private class BooleanFunction implements TypeFunction { - - @Override - public String getTypeName(Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLBoolean.getName(); - } - - @Override - public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { - return aClass == Boolean.class || aClass == boolean.class; - } - - @Override - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLBoolean; - } - } - - private class FloatFunction implements TypeFunction { - - @Override - public String getTypeName(Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLFloat.getName(); - } - - @Override - public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { - return aClass == Float.class || aClass == float.class || aClass == Double.class || aClass == double.class; - } - - @Override - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLFloat; - } - } - - private class IntegerFunction implements TypeFunction { - - @Override - public String getTypeName(Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLInt.getName(); - } - - @Override - public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { - return aClass == Integer.class || aClass == int.class; - } - - @Override - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLInt; - } - } - - private class LongFunction implements TypeFunction { - - @Override - public String getTypeName(Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLLong.getName(); - } - - @Override - public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { - return aClass == Long.class || aClass == long.class; - } - - @Override - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - return Scalars.GraphQLLong; - } - } - - /** - * Support for the Iterable things like Lists / Sets / Collections and so on.. - */ - private class IterableFunction implements TypeFunction { - - @Override - public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { - return Iterable.class.isAssignableFrom(aClass); - } - - @Override - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - if (!(annotatedType instanceof AnnotatedParameterizedType)) { - throw new IllegalArgumentException("List type parameter should be specified"); - } - AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) annotatedType; - AnnotatedType arg = parameterizedType.getAnnotatedActualTypeArguments()[0]; - Class klass; - if (arg.getType() instanceof ParameterizedType) { - klass = (Class) ((ParameterizedType) (arg.getType())).getRawType(); - } else { - klass = (Class) arg.getType(); - } - return new GraphQLList(DefaultTypeFunction.this.buildType(inputType, klass, arg)); - } - } - - private class StreamFunction implements TypeFunction { - - @Override - public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { - return Stream.class.isAssignableFrom(aClass); - } - - @Override - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - if (!(annotatedType instanceof AnnotatedParameterizedType)) { - throw new IllegalArgumentException("Stream type parameter should be specified"); - } - AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) annotatedType; - AnnotatedType arg = parameterizedType.getAnnotatedActualTypeArguments()[0]; - Class klass; - if (arg.getType() instanceof ParameterizedType) { - klass = (Class) ((ParameterizedType) (arg.getType())).getRawType(); - } else { - klass = (Class) arg.getType(); - } - return new GraphQLList(DefaultTypeFunction.this.buildType(inputType, klass, arg)); - } - } - - private class OptionalFunction implements TypeFunction { - - @Override - public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { - return aClass == Optional.class; - } - - @Override - public String getTypeName(Class aClass, AnnotatedType annotatedType) { - AnnotatedType arg = getAnnotatedType(annotatedType); - return DefaultTypeFunction.this.getTypeName(getClass(annotatedType), arg); - } - - @Override - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - AnnotatedType arg = getAnnotatedType(annotatedType); - return DefaultTypeFunction.this.buildType(inputType, getClass(annotatedType), arg); - } - - private AnnotatedType getAnnotatedType(AnnotatedType annotatedType) { - if (!(annotatedType instanceof AnnotatedParameterizedType)) { - throw new IllegalArgumentException("Optional type parameter should be specified"); - } - AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) annotatedType; - return parameterizedType.getAnnotatedActualTypeArguments()[0]; - } - - private Class getClass(AnnotatedType annotatedType) { - AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) annotatedType; - AnnotatedType arg = parameterizedType.getAnnotatedActualTypeArguments()[0]; - if (arg.getType() instanceof ParameterizedType) { - return (Class) ((ParameterizedType) (arg.getType())).getRawType(); - } else { - return (Class) arg.getType(); - } - } - } - - private class ObjectFunction implements TypeFunction { - @Override - public String getTypeName(Class aClass, AnnotatedType annotatedType) { - GraphQLName name = aClass.getAnnotation(GraphQLName.class); - return toGraphqlName(name == null ? aClass.getSimpleName() : name.value()); - } - - @Override - public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { - return true; - } - - @Override - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - if (inputType) { - return annotationsProcessor.getInputObject(aClass); - } else { - return annotationsProcessor.getOutputTypeOrRef(aClass); - } - } - } - - public DefaultTypeFunction() { - typeFunctions = new CopyOnWriteArrayList<>(); - - typeFunctions.add(new IDFunction()); - typeFunctions.add(new StringFunction()); - typeFunctions.add(new BooleanFunction()); - typeFunctions.add(new FloatFunction()); - typeFunctions.add(new IntegerFunction()); - - typeFunctions.add(new LongFunction()); - - typeFunctions.add(new IterableFunction()); - typeFunctions.add(new StreamFunction()); - - typeFunctions.add(new OptionalFunction()); - - typeFunctions.add(new ObjectFunction()); - } - - @Reference(cardinality = ReferenceCardinality.MULTIPLE, - policy = ReferencePolicy.DYNAMIC, - service = TypeFunction.class, - target = "(!(type=default))") - void addFunction(TypeFunction function) { - this.otherFunctions.add(function); - } - - void removeFunction(TypeFunction function) { - this.otherFunctions.remove(function); - } - - @Activate - protected void activate() { - for (TypeFunction function : otherFunctions) { - register(function); - } - } - - public Class register(TypeFunction function) { - typeFunctions.add(0, function); - return DefaultTypeFunction.class; - } - - @Override - public String getTypeName(Class aClass, AnnotatedType annotatedType) { - TypeFunction typeFunction = getTypeFunction(aClass, annotatedType); - if (typeFunction == null) { - throw new IllegalArgumentException("unsupported type"); - } - return typeFunction.getTypeName(aClass, annotatedType); - } - - @Override - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - TypeFunction typeFunction = getTypeFunction(aClass, annotatedType); - if (typeFunction == null) { - throw new IllegalArgumentException("unsupported type"); - } - - GraphQLType result = typeFunction.buildType(inputType, aClass, annotatedType); - if (annotatedType != null && annotatedType.isAnnotationPresent(GraphQLNonNull.class)) { - result = new graphql.schema.GraphQLNonNull(result); - } - return result; - } - - private TypeFunction getTypeFunction(Class aClass, AnnotatedType annotatedType) { - for (TypeFunction typeFunction : typeFunctions) { - if (typeFunction.canBuildType(aClass, annotatedType)) { - return typeFunction; - } - } - return null; - } -} diff --git a/src/main/java/graphql/annotations/GraphQLAnnotations.java b/src/main/java/graphql/annotations/GraphQLAnnotations.java index 12f7e065..e1e0fc52 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/GraphQLAnnotations.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,32 +14,18 @@ */ package graphql.annotations; -import graphql.TypeResolutionEnvironment; +import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.typeFunctions.DefaultTypeFunction; +import graphql.annotations.util.GraphQLObjectInfoRetriever; import graphql.relay.Relay; -import graphql.schema.*; -import graphql.schema.GraphQLNonNull; +import graphql.schema.GraphQLFieldDefinition; +import graphql.schema.GraphQLObjectType; import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; -import java.lang.reflect.*; import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import static graphql.Scalars.GraphQLBoolean; -import static graphql.annotations.ReflectionKit.constructNewInstance; -import static graphql.annotations.ReflectionKit.newInstance; import static graphql.annotations.util.NamingKit.toGraphqlName; -import static graphql.schema.GraphQLArgument.newArgument; -import static graphql.schema.GraphQLEnumType.newEnum; -import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; -import static graphql.schema.GraphQLInputObjectField.newInputObjectField; -import static graphql.schema.GraphQLInterfaceType.newInterface; -import static graphql.schema.GraphQLObjectType.newObject; -import static graphql.schema.GraphQLUnionType.newUnionType; -import static java.util.Arrays.stream; -import static java.util.Objects.nonNull; /** * A utility class for extracting GraphQL data structures from annotated @@ -48,22 +34,29 @@ @Component public class GraphQLAnnotations implements GraphQLAnnotationsProcessor { - private static final List TYPES_FOR_CONNECTION = Arrays.asList(GraphQLObjectType.class, GraphQLInterfaceType.class, GraphQLUnionType.class, GraphQLTypeReference.class); + private GraphQLObjectHandler graphQLObjectHandler; + private ProcessingElementsContainer container; - private static final String DEFAULT_INPUT_PREFIX = "Input"; - - private Map typeRegistry = new HashMap<>(); - private Map, Set>> extensionsTypeRegistry = new HashMap<>(); - private final Stack processing = new Stack<>(); - private Relay relay = new Relay(); + private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; public GraphQLAnnotations() { - this(new DefaultTypeFunction()); - ((DefaultTypeFunction) defaultTypeFunction).setAnnotationsProcessor(this); + this(new DefaultTypeFunction(new GraphQLInputProcessor(), new GraphQLOutputProcessor()), new GraphQLObjectInfoRetriever(), new GraphQLObjectHandler()); } - public GraphQLAnnotations(TypeFunction defaultTypeFunction) { + public GraphQLAnnotations(TypeFunction defaultTypeFunction, GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLObjectHandler graphQLObjectHandler) { + this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; this.defaultTypeFunction = defaultTypeFunction; + this.graphQLObjectHandler = graphQLObjectHandler; + this.container = initializeContainer(this.defaultTypeFunction); + } + + private ProcessingElementsContainer initializeContainer(TypeFunction defaultTypeFunction) { + Map typeRegistry = new HashMap<>(); + Map, Set>> extensionsTypeRegistry = new HashMap<>(); + final Stack processing = new Stack<>(); + Relay relay = new Relay(); + ProcessingElementsContainer container = new ProcessingElementsContainer(defaultTypeFunction, relay, typeRegistry, extensionsTypeRegistry, processing); + return container; } public static GraphQLAnnotations instance = new GraphQLAnnotations(); @@ -73,264 +66,17 @@ public static GraphQLAnnotations getInstance() { } public void setRelay(Relay relay) { - this.relay = relay; - } - - @Override - public graphql.schema.GraphQLOutputType getInterface(Class iface) throws GraphQLAnnotationsException { - return getOutputType(iface); - } - - public static graphql.schema.GraphQLType iface(Class iface) throws GraphQLAnnotationsException { - return getInstance().getInterface(iface); - } - - @Override - public GraphQLUnionType.Builder getUnionBuilder(Class iface) throws GraphQLAnnotationsException, IllegalArgumentException { - if (!iface.isInterface()) { - throw new IllegalArgumentException(iface + " is not an interface"); - } - GraphQLUnionType.Builder builder = newUnionType(); - - GraphQLUnion unionAnnotation = iface.getAnnotation(GraphQLUnion.class); - builder.name(getTypeName(iface)); - GraphQLDescription description = iface.getAnnotation(GraphQLDescription.class); - if (description != null) { - builder.description(description.value()); - } - GraphQLType typeAnnotation = iface.getAnnotation(GraphQLType.class); - - TypeFunction typeFunction = defaultTypeFunction; - - if (typeAnnotation != null) { - typeFunction = newInstance(typeAnnotation.value()); - } - - TypeFunction finalTypeFunction = typeFunction; - Arrays.asList(unionAnnotation.possibleTypes()).stream() - .map(new Function, graphql.schema.GraphQLType>() { - @Override - public graphql.schema.GraphQLType apply(Class aClass) { - return finalTypeFunction.buildType(aClass, null); - } - }) - .map(v -> (GraphQLObjectType) v) - .forEach(builder::possibleType); - - builder.typeResolver(new UnionTypeResolver(unionAnnotation.possibleTypes())); - return builder; + this.container.setRelay(relay); } - public static GraphQLUnionType.Builder unionBuilder(Class iface) throws GraphQLAnnotationsException { - return getInstance().getUnionBuilder(iface); - } public String getTypeName(Class objectClass) { GraphQLName name = objectClass.getAnnotation(GraphQLName.class); return toGraphqlName(name == null ? objectClass.getSimpleName() : name.value()); } - @Override - public GraphQLInterfaceType.Builder getIfaceBuilder(Class iface) throws GraphQLAnnotationsException, - IllegalArgumentException { - if (!iface.isInterface()) { - throw new IllegalArgumentException(iface + " is not an interface"); - } - GraphQLInterfaceType.Builder builder = newInterface(); - - builder.name(getTypeName(iface)); - GraphQLDescription description = iface.getAnnotation(GraphQLDescription.class); - if (description != null) { - builder.description(description.value()); - } - List definedFields = new ArrayList<>(); - for (Method method : getOrderedMethods(iface)) { - boolean valid = !Modifier.isStatic(method.getModifiers()) && - method.getAnnotation(GraphQLField.class) != null; - if (valid) { - GraphQLFieldDefinition gqlField = getField(method); - definedFields.add(gqlField.getName()); - builder.field(gqlField); - } - } - builder.fields(getExtensionFields(iface, definedFields)); - - GraphQLTypeResolver typeResolver = iface.getAnnotation(GraphQLTypeResolver.class); - builder.typeResolver(newInstance(typeResolver.value())); - return builder; - } - - public static GraphQLInterfaceType.Builder ifaceBuilder(Class iface) throws GraphQLAnnotationsException, - IllegalAccessException { - return getInstance().getIfaceBuilder(iface); - } - - private static Boolean isGraphQLField(AnnotatedElement element) { - GraphQLField annotation = element.getAnnotation(GraphQLField.class); - if (annotation == null) { - return null; - } - return annotation.value(); - } - - /** - * breadthFirst parental ascent looking for closest method declaration with explicit annotation - * - * @param method The method to match - * - * @return The closest GraphQLField annotation - */ - private boolean breadthFirstSearch(Method method) { - final List> queue = new LinkedList<>(); - final String methodName = method.getName(); - final Class[] parameterTypes = method.getParameterTypes(); - queue.add(method.getDeclaringClass()); - do { - Class cls = queue.remove(0); - - try { - method = cls.getDeclaredMethod(methodName, parameterTypes); - Boolean gqf = isGraphQLField(method); - if (gqf != null) { - return gqf; - } - } catch (NoSuchMethodException e) { - } - - Boolean gqf = isGraphQLField(cls); - if (gqf != null) { - return gqf; - } - - // add interfaces to places to search - for (Class iface : cls.getInterfaces()) { - queue.add(iface); - } - // add parent class to places to search - Class nxt = cls.getSuperclass(); - if (nxt != null) { - queue.add(nxt); - } - } while (!queue.isEmpty()); - return false; - } - - /** - * direct parental ascent looking for closest declaration with explicit annotation - * - * @param field The field to find - * - * @return The closest GraphQLField annotation - */ - private boolean parentalSearch(Field field) { - Boolean gqf = isGraphQLField(field); - if (gqf != null) { - return gqf; - } - Class cls = field.getDeclaringClass(); - - do { - gqf = isGraphQLField(cls); - if (gqf != null) { - return gqf; - } - cls = cls.getSuperclass(); - } while (cls != null); - return false; - } - - @Override - public GraphQLObjectType getObject(Class object) throws GraphQLAnnotationsException { - GraphQLOutputType type = getOutputType(object); - if (type instanceof GraphQLObjectType) { - return (GraphQLObjectType) type; - } else { - throw new IllegalArgumentException("Object resolve to a "+type.getClass().getSimpleName()); - } - } - - @Override - public GraphQLOutputType getOutputType(Class object) throws GraphQLAnnotationsException { - // because the TypeFunction can call back to this processor and - // Java classes can be circular, we need to protect against - // building the same type twice because graphql-java 3.x requires - // all type instances to be unique singletons - String typeName = getTypeName(object); - - GraphQLOutputType type = (GraphQLOutputType) typeRegistry.get(typeName); - if (type != null) { // type already exists, do not build a new new one - return type; - } - - processing.push(typeName); - if (object.getAnnotation(GraphQLUnion.class) != null) { - type = getUnionBuilder(object).build(); - } else if (object.isAnnotationPresent(GraphQLTypeResolver.class)) { - type = getIfaceBuilder(object).build(); - } else if (Enum.class.isAssignableFrom(object)) { - type = getEnumBuilder(object).build(); - } else { - type = getObjectBuilder(object).build(); - } - - typeRegistry.put(typeName, type); - processing.pop(); - - return type; - } - - public static GraphQLOutputType outputType(Class object) { - return getInstance().getOutputType(object); - } - - public GraphQLEnumType.Builder getEnumBuilder(Class aClass) { - String typeName = getTypeName(aClass); - //noinspection unchecked - Class enumClass = (Class) aClass; - GraphQLEnumType.Builder builder = newEnum(); - builder.name(typeName); - - GraphQLDescription description = aClass.getAnnotation(GraphQLDescription.class); - if (description != null) { - builder.description(description.value()); - } - - List constants = Arrays.asList(enumClass.getEnumConstants()); - - Arrays.stream(enumClass.getEnumConstants()).map(Enum::name).forEachOrdered(n -> { - try { - Field field = aClass.getField(n); - GraphQLName fieldName = field.getAnnotation(GraphQLName.class); - GraphQLDescription fieldDescription = field.getAnnotation(GraphQLDescription.class); - Enum constant = constants.stream().filter(c -> c.name().contentEquals(n)).findFirst().get(); - String name_ = fieldName == null ? n : fieldName.value(); - builder.value(name_, constant, fieldDescription == null ? name_ : fieldDescription.value()); - } catch (NoSuchFieldException ignore) { - } - }); - return builder; - } - - public static GraphQLEnumType.Builder enumBuilder(Class object) throws GraphQLAnnotationsException { - return getInstance().getEnumBuilder(object); - } - - public GraphQLOutputType getObjectOrRef(Class object) throws GraphQLAnnotationsException { - return getOutputTypeOrRef(object); - } - - @Override - public GraphQLOutputType getOutputTypeOrRef(Class object) throws GraphQLAnnotationsException { - String typeName = getTypeName(object); - if (processing.contains(typeName)) { - return new GraphQLTypeReference(typeName); - } - - return getOutputType(object); - } - public static GraphQLObjectType object(Class object) throws GraphQLAnnotationsException { - return getInstance().getObject(object); + return new GraphQLObjectHandler().getObject(object, getInstance().getContainer()); } public static class GraphQLFieldDefinitionWrapper extends GraphQLFieldDefinition { @@ -347,457 +93,18 @@ public boolean equals(Object obj) { } } - @Override - public GraphQLObjectType.Builder getObjectBuilder(Class object) throws GraphQLAnnotationsException { - GraphQLObjectType.Builder builder = newObject(); - builder.name(getTypeName(object)); - GraphQLDescription description = object.getAnnotation(GraphQLDescription.class); - if (description != null) { - builder.description(description.value()); - } - List fieldsDefined = new ArrayList<>(); - for (Method method : getOrderedMethods(object)) { - if (method.isBridge() || method.isSynthetic()) { - continue; - } - if (breadthFirstSearch(method)) { - GraphQLFieldDefinition gqlField = getField(method); - fieldsDefined.add(gqlField.getName()); - builder.field(gqlField); - } - } - - for (Field field : getAllFields(object).values()) { - if (Modifier.isStatic(field.getModifiers())) { - continue; - } - if (parentalSearch(field)) { - GraphQLFieldDefinition gqlField = getField(field); - fieldsDefined.add(gqlField.getName()); - builder.field(gqlField); - } - } - - for (Class iface : object.getInterfaces()) { - if (iface.getAnnotation(GraphQLTypeResolver.class) != null) { - String ifaceName = getTypeName(iface); - if (processing.contains(ifaceName)) { - builder.withInterface(new GraphQLTypeReference(ifaceName)); - } else { - builder.withInterface((GraphQLInterfaceType) getInterface(iface)); - } - builder.fields(getExtensionFields(iface, fieldsDefined)); - } - } - - builder.fields(getExtensionFields(object, fieldsDefined)); - - return builder; - } - - private List getExtensionFields(Class object, List fieldsDefined) { - List fields = new ArrayList<>(); - if (extensionsTypeRegistry.containsKey(object)) { - for (Class aClass : extensionsTypeRegistry.get(object)) { - for (Method method : getOrderedMethods(aClass)) { - if (method.isBridge() || method.isSynthetic()) { - continue; - } - if (breadthFirstSearch(method)) { - addExtensionField(getField(method), fields, fieldsDefined); - } - } - for (Field field : getAllFields(aClass).values()) { - if (Modifier.isStatic(field.getModifiers())) { - continue; - } - if (parentalSearch(field)) { - addExtensionField(getField(field), fields, fieldsDefined); - } - } - } - } - return fields; - } - - private void addExtensionField(GraphQLFieldDefinition gqlField, List fields, List fieldsDefined) { - if (!fieldsDefined.contains(gqlField.getName())) { - fieldsDefined.add(gqlField.getName()); - fields.add(gqlField); - } else { - throw new GraphQLAnnotationsException("Duplicate field found in extension : " + gqlField.getName(), null); - } - } - - public static GraphQLObjectType.Builder objectBuilder(Class object) throws GraphQLAnnotationsException { - return getInstance().getObjectBuilder(object); - } - - - protected List getOrderedMethods(Class c) { - return Arrays.stream(c.getMethods()) - .sorted(Comparator.comparing(Method::getName)) - .collect(Collectors.toList()); - } - - protected Map getAllFields(Class c) { - Map fields; - - if (c.getSuperclass() != null) { - fields = getAllFields(c.getSuperclass()); - } else { - fields = new TreeMap<>(); - } - - for (Field f : c.getDeclaredFields()) { - fields.put(f.getName(), f); - } - - return fields; - } - - - protected GraphQLFieldDefinition getField(Field field) throws GraphQLAnnotationsException { - GraphQLFieldDefinition.Builder builder = newFieldDefinition(); - GraphQLName name = field.getAnnotation(GraphQLName.class); - builder.name(toGraphqlName(name == null ? field.getName() : name.value())); - GraphQLType annotation = field.getAnnotation(GraphQLType.class); - - TypeFunction typeFunction = defaultTypeFunction; - - if (annotation != null) { - typeFunction = newInstance(annotation.value()); - } - - GraphQLOutputType outputType = (GraphQLOutputType) typeFunction.buildType(field.getType(), field.getAnnotatedType()); - - boolean isConnection = isConnection(field, outputType); - if (isConnection) { - outputType = getGraphQLConnection(field, outputType); - builder.argument(relay.getConnectionFieldArguments()); - } - - builder.type(outputType); - - GraphQLDescription description = field.getAnnotation(GraphQLDescription.class); - if (description != null) { - builder.description(description.value()); - } - - GraphQLDeprecate deprecate = field.getAnnotation(GraphQLDeprecate.class); - if (deprecate != null) { - builder.deprecate(deprecate.value()); - } - if (field.getAnnotation(Deprecated.class) != null) { - builder.deprecate("Deprecated"); - } - - GraphQLDataFetcher dataFetcher = field.getAnnotation(GraphQLDataFetcher.class); - DataFetcher actualDataFetcher = null; - if (nonNull(dataFetcher)) { - actualDataFetcher = constructDataFetcher(field.getName(), dataFetcher); - } - - if (actualDataFetcher == null) { - - StringBuilder fluentBuffer = new StringBuilder(field.getName()); - fluentBuffer.setCharAt(0, Character.toLowerCase(fluentBuffer.charAt(0))); - String fluentGetter = fluentBuffer.toString(); - - boolean hasFluentGetter = false; - Method fluentMethod = null; - try { - fluentMethod = field.getDeclaringClass().getMethod(fluentGetter); - hasFluentGetter = true; - } catch (NoSuchMethodException x) { - } - - // if there is getter for fields type, use propertyDataFetcher, otherwise use method directly - if (outputType == GraphQLBoolean || (outputType instanceof GraphQLNonNull && ((GraphQLNonNull) outputType).getWrappedType() == GraphQLBoolean)) { - if (checkIfPrefixGetterExists(field.getDeclaringClass(), "is", field.getName()) || - checkIfPrefixGetterExists(field.getDeclaringClass(), "get", field.getName())) { - actualDataFetcher = new ExtensionDataFetcherWrapper(field.getDeclaringClass(), new PropertyDataFetcher(field.getName())); - } - } else if (checkIfPrefixGetterExists(field.getDeclaringClass(), "get", field.getName())) { - actualDataFetcher = new ExtensionDataFetcherWrapper(field.getDeclaringClass(), new PropertyDataFetcher(field.getName())); - } else if (hasFluentGetter) { - actualDataFetcher = new MethodDataFetcher(fluentMethod, typeFunction); - } - - if (actualDataFetcher == null) { - actualDataFetcher = new ExtensionDataFetcherWrapper(field.getDeclaringClass(), new FieldDataFetcher(field.getName())); - } - } - - - if (isConnection) { - actualDataFetcher = new ConnectionDataFetcher(field.getAnnotation(GraphQLConnection.class).connection(), actualDataFetcher); - } - - builder.dataFetcher(actualDataFetcher); - - return new GraphQLFieldDefinitionWrapper(builder.build()); - } - - private DataFetcher constructDataFetcher(String fieldName, GraphQLDataFetcher annotatedDataFetcher) { - final String[] args; - if (annotatedDataFetcher.firstArgIsTargetName()) { - args = Stream.concat(Stream.of(fieldName), stream(annotatedDataFetcher.args())).toArray(String[]::new); - } else { - args = annotatedDataFetcher.args(); - } - if (args.length == 0) { - return newInstance(annotatedDataFetcher.value()); - } else { - try { - final Constructor ctr = annotatedDataFetcher.value().getDeclaredConstructor( - stream(args).map(v -> String.class).toArray(Class[]::new)); - return constructNewInstance(ctr, (Object[]) args); - } catch (final NoSuchMethodException e) { - throw new GraphQLAnnotationsException("Unable to instantiate DataFetcher via constructor for: " + fieldName, e); - } - } - } - - protected GraphQLFieldDefinition field(Field field) throws IllegalAccessException, InstantiationException { - return getInstance().getField(field); - } - - // check if there is getter for field, basic functionality taken from PropertyDataFetcher - private boolean checkIfPrefixGetterExists(Class c, String prefix, String propertyName) { - String getterName = prefix + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); - try { - Method method = c.getMethod(getterName); - } catch (NoSuchMethodException x) { - return false; - } - - return true; - } - - private GraphQLOutputType getGraphQLConnection(AccessibleObject field, GraphQLOutputType type) { - if (type instanceof GraphQLNonNull) { - GraphQLList listType = (GraphQLList) ((GraphQLNonNull) type).getWrappedType(); - return new GraphQLNonNull(internalGetGraphQLConnection(field, listType)); - } else { - return internalGetGraphQLConnection(field, (GraphQLList) type); - } - } - - private GraphQLOutputType internalGetGraphQLConnection(AccessibleObject field, GraphQLList listType) { - GraphQLOutputType wrappedType = (GraphQLOutputType) listType.getWrappedType(); - String connectionName = field.getAnnotation(GraphQLConnection.class).name(); - connectionName = connectionName.isEmpty() ? wrappedType.getName() : connectionName; - GraphQLObjectType edgeType = getActualType(relay.edgeType(connectionName, wrappedType, null, Collections.emptyList())); - return getActualType(relay.connectionType(connectionName, edgeType, Collections.emptyList())); - } - - private GraphQLObjectType getActualType(GraphQLObjectType type) { - if (typeRegistry.containsKey(type.getName())) { - type = (GraphQLObjectType) typeRegistry.get(type.getName()); - } else { - typeRegistry.put(type.getName(), type); - } - return type; - } - - private boolean isConnection(AccessibleObject obj, GraphQLOutputType type) { - if (type instanceof GraphQLNonNull) { - type = (GraphQLOutputType) ((GraphQLNonNull) type).getWrappedType(); - } - final GraphQLOutputType actualType = type; - return obj.isAnnotationPresent(GraphQLConnection.class) && - actualType instanceof GraphQLList && TYPES_FOR_CONNECTION.stream().anyMatch(aClass -> aClass.isInstance(((GraphQLList) actualType).getWrappedType())); - } - - protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotationsException { - GraphQLFieldDefinition.Builder builder = newFieldDefinition(); - - String name = method.getName().replaceFirst("^(is|get|set)(.+)", "$2"); - name = Character.toLowerCase(name.charAt(0)) + name.substring(1); - GraphQLName nameAnn = method.getAnnotation(GraphQLName.class); - builder.name(toGraphqlName(nameAnn == null ? name : nameAnn.value())); - - GraphQLType annotation = method.getAnnotation(GraphQLType.class); - TypeFunction typeFunction = defaultTypeFunction; - - if (annotation != null) { - typeFunction = newInstance(annotation.value()); - } - AnnotatedType annotatedReturnType = method.getAnnotatedReturnType(); - - TypeFunction outputTypeFunction; - if (method.getAnnotation(GraphQLBatched.class) != null) { - outputTypeFunction = new BatchedTypeFunction(typeFunction); - } else { - outputTypeFunction = typeFunction; - } - - GraphQLOutputType outputType = (GraphQLOutputType) outputTypeFunction.buildType(method.getReturnType(), annotatedReturnType); - - boolean isConnection = isConnection(method, outputType); - if (isConnection) { - outputType = getGraphQLConnection(method, outputType); - builder.argument(relay.getConnectionFieldArguments()); - } - - builder.type(outputType); - - - TypeFunction finalTypeFunction = typeFunction; - List args = Arrays.asList(method.getParameters()).stream(). - filter(p -> !DataFetchingEnvironment.class.isAssignableFrom(p.getType())). - map(parameter -> { - Class t = parameter.getType(); - graphql.schema.GraphQLInputType graphQLType = getInputObject(finalTypeFunction.buildType(t, parameter.getAnnotatedType()), DEFAULT_INPUT_PREFIX); - return getArgument(parameter, graphQLType); - }).collect(Collectors.toList()); - - GraphQLFieldDefinition relayFieldDefinition = null; - if (method.isAnnotationPresent(GraphQLRelayMutation.class)) { - if (!(outputType instanceof GraphQLObjectType || outputType instanceof GraphQLInterfaceType)) { - throw new RuntimeException("outputType should be an object or an interface"); - } - StringBuilder titleBuffer = new StringBuilder(method.getName()); - titleBuffer.setCharAt(0, Character.toUpperCase(titleBuffer.charAt(0))); - String title = titleBuffer.toString(); - List fieldDefinitions = outputType instanceof GraphQLObjectType ? - ((GraphQLObjectType) outputType).getFieldDefinitions() : - ((GraphQLInterfaceType) outputType).getFieldDefinitions(); - relayFieldDefinition = relay.mutationWithClientMutationId(title, method.getName(), - args.stream(). - map(t -> newInputObjectField().name(t.getName()).type(t.getType()).description(t.getDescription()).build()). - collect(Collectors.toList()), fieldDefinitions, new StaticDataFetcher(null)); - builder.argument(relayFieldDefinition.getArguments()); - builder.type(relayFieldDefinition.getType()); - } else { - builder.argument(args); - } - - GraphQLDescription description = method.getAnnotation(GraphQLDescription.class); - if (description != null) { - builder.description(description.value()); - } - - GraphQLDeprecate deprecate = method.getAnnotation(GraphQLDeprecate.class); - if (deprecate != null) { - builder.deprecate(deprecate.value()); - } - if (method.getAnnotation(Deprecated.class) != null) { - builder.deprecate("Deprecated"); - } - - GraphQLDataFetcher dataFetcher = method.getAnnotation(GraphQLDataFetcher.class); - DataFetcher actualDataFetcher; - if (dataFetcher == null && method.getAnnotation(GraphQLBatched.class) != null) { - actualDataFetcher = new BatchedMethodDataFetcher(method, typeFunction); - } else if (dataFetcher == null) { - actualDataFetcher = new MethodDataFetcher(method, typeFunction); - } else { - actualDataFetcher = constructDataFetcher(method.getName(), dataFetcher); - } - - if (method.isAnnotationPresent(GraphQLRelayMutation.class) && relayFieldDefinition != null) { - actualDataFetcher = new RelayMutationMethodDataFetcher(method, args, relayFieldDefinition.getArgument("input").getType(), relayFieldDefinition.getType()); - } - - if (isConnection) { - actualDataFetcher = new ConnectionDataFetcher(method.getAnnotation(GraphQLConnection.class).connection(), actualDataFetcher); - } - - builder.dataFetcher(actualDataFetcher); - - return new GraphQLFieldDefinitionWrapper(builder.build()); - } - - protected static GraphQLFieldDefinition field(Method method) throws InstantiationException, IllegalAccessException { - return getInstance().getField(method); - - } - - public GraphQLInputObjectType getInputObject(Class object) { - String typeName = DEFAULT_INPUT_PREFIX + getTypeName(object); - if (typeRegistry.containsKey(typeName)) { - return (GraphQLInputObjectType) typeRegistry.get(typeName); - } else { - graphql.schema.GraphQLType graphQLType = getObject(object); - GraphQLInputObjectType inputObject = (GraphQLInputObjectType) getInputObject(graphQLType, DEFAULT_INPUT_PREFIX); - typeRegistry.put(inputObject.getName(), inputObject); - return inputObject; - } - } - - @Override - public GraphQLInputType getInputObject(graphql.schema.GraphQLType graphQLType, String newNamePrefix) { - if (graphQLType instanceof GraphQLObjectType) { - GraphQLObjectType object = (GraphQLObjectType) graphQLType; - if (typeRegistry.containsKey(newNamePrefix + object.getName()) && typeRegistry.get(newNamePrefix + object.getName()) instanceof GraphQLInputType) { - return (GraphQLInputType) typeRegistry.get(newNamePrefix + object.getName()); - } - GraphQLInputObjectType inputObjectType = new GraphQLInputObjectType(newNamePrefix + object.getName(), object.getDescription(), - object.getFieldDefinitions().stream(). - map(field -> { - GraphQLOutputType type = field.getType(); - GraphQLInputType inputType = getInputObject(type, newNamePrefix); - return new GraphQLInputObjectField(field.getName(), field.getDescription(), inputType, null); - }). - collect(Collectors.toList())); - typeRegistry.put(inputObjectType.getName(), inputObjectType); - return inputObjectType; - } else if (graphQLType instanceof GraphQLList) { - return new GraphQLList(getInputObject(((GraphQLList)graphQLType).getWrappedType(), newNamePrefix)); - } else if (graphQLType instanceof GraphQLNonNull) { - return new GraphQLNonNull(getInputObject(((GraphQLNonNull)graphQLType).getWrappedType(), newNamePrefix)); - } else if (graphQLType instanceof GraphQLTypeReference) { - return new GraphQLTypeReference(newNamePrefix + ((GraphQLTypeReference)graphQLType).getName()); - } else if (graphQLType instanceof GraphQLInputType){ - return (GraphQLInputType) graphQLType; - } - throw new IllegalArgumentException("Cannot convert type to input : "+graphQLType); - } - - public static GraphQLInputObjectType inputObject(GraphQLObjectType graphQLType, String newNamePrefix) { - return (GraphQLInputObjectType) getInstance().getInputObject(graphQLType, newNamePrefix); - } - - protected GraphQLArgument getArgument(Parameter parameter, graphql.schema.GraphQLInputType t) throws - GraphQLAnnotationsException { - GraphQLArgument.Builder builder = newArgument().type(t); - GraphQLDescription description = parameter.getAnnotation(GraphQLDescription.class); - if (description != null) { - builder.description(description.value()); - } - GraphQLDefaultValue defaultValue = parameter.getAnnotation(GraphQLDefaultValue.class); - if (defaultValue != null) { - builder.defaultValue(newInstance(defaultValue.value()).get()); - } - GraphQLName name = parameter.getAnnotation(GraphQLName.class); - if (name != null) { - builder.name(toGraphqlName(name.value())); - } else { - builder.name(toGraphqlName(parameter.getName())); - } - return builder.build(); - } - protected TypeFunction defaultTypeFunction; - @Reference(target = "(type=default)") - public void setDefaultTypeFunction(TypeFunction function) { - defaultTypeFunction = function; - ((DefaultTypeFunction) defaultTypeFunction).setAnnotationsProcessor(this); - } - public void registerTypeExtension(Class objectClass) { GraphQLTypeExtension typeExtension = objectClass.getAnnotation(GraphQLTypeExtension.class); if (typeExtension == null) { throw new GraphQLAnnotationsException("Class is not annotated with GraphQLTypeExtension", null); } else { Class aClass = typeExtension.value(); - if (!extensionsTypeRegistry.containsKey(aClass)) { - extensionsTypeRegistry.put(aClass, new HashSet<>()); + if (!container.getExtensionsTypeRegistry().containsKey(aClass)) { + container.getExtensionsTypeRegistry().put(aClass, new HashSet<>()); } - extensionsTypeRegistry.get(aClass).add(objectClass); + container.getExtensionsTypeRegistry().get(aClass).add(objectClass); } } @@ -807,8 +114,8 @@ public void unregisterTypeExtension(Class objectClass) { throw new GraphQLAnnotationsException("Class is not annotated with GraphQLTypeExtension", null); } else { Class aClass = typeExtension.value(); - if (extensionsTypeRegistry.containsKey(aClass)) { - extensionsTypeRegistry.get(aClass).remove(objectClass); + if (container.getExtensionsTypeRegistry().containsKey(aClass)) { + container.getExtensionsTypeRegistry().get(aClass).remove(objectClass); } } } @@ -822,64 +129,11 @@ public static void register(TypeFunction typeFunction) { } public Map getTypeRegistry() { - return typeRegistry; + return container.getTypeRegistry(); } - private static class ConnectionDataFetcher implements DataFetcher { - private final Class connection; - private final DataFetcher actualDataFetcher; - private final Constructor constructor; - - public ConnectionDataFetcher(Class connection, DataFetcher actualDataFetcher) { - this.connection = connection; - Optional> constructor = - Arrays.asList(connection.getConstructors()).stream(). - filter(c -> c.getParameterCount() == 1). - map(c -> (Constructor) c). - findFirst(); - if (constructor.isPresent()) { - this.constructor = constructor.get(); - } else { - throw new IllegalArgumentException(connection + " doesn't have a single argument constructor"); - } - this.actualDataFetcher = actualDataFetcher; - } - - @Override - public Object get(DataFetchingEnvironment environment) { - // Create a list of arguments with connection specific arguments excluded - HashMap arguments = new HashMap<>(environment.getArguments()); - arguments.keySet().removeAll(Arrays.asList("first", "last", "before", "after")); - DataFetchingEnvironment env = new DataFetchingEnvironmentImpl(environment.getSource(), arguments, environment.getContext(), - environment.getRoot(), environment.getFieldDefinition(), environment.getFields(), environment.getFieldType(), environment.getParentType(), environment.getGraphQLSchema(), - environment.getFragmentsByName(), environment.getExecutionId(), environment.getSelectionSet(), environment.getFieldTypeInfo()); - Object data = actualDataFetcher.get(env); - if (data != null) { - Connection conn = constructNewInstance(constructor, data); - return conn.get(environment); - } - return null; - } + public ProcessingElementsContainer getContainer() { + return container; } - private class UnionTypeResolver implements TypeResolver { - private final Map, graphql.schema.GraphQLType> types = new HashMap<>(); - - public UnionTypeResolver(Class[] classes) { - Arrays.stream(classes). - forEach(c -> types.put(c, defaultTypeFunction.buildType(c, null))); - } - - @Override - public GraphQLObjectType getType(TypeResolutionEnvironment env) { - Object object = env.getObject(); - Optional, graphql.schema.GraphQLType>> maybeType = types.entrySet(). - stream().filter(e -> e.getKey().isAssignableFrom(object.getClass())).findFirst(); - if (maybeType.isPresent()) { - return (GraphQLObjectType) maybeType.get().getValue(); - } else { - throw new RuntimeException("Unknown type " + object.getClass()); - } - } - } } diff --git a/src/main/java/graphql/annotations/GraphQLAnnotationsProcessor.java b/src/main/java/graphql/annotations/GraphQLAnnotationsProcessor.java index 79ceab25..96ffe1e3 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotationsProcessor.java +++ b/src/main/java/graphql/annotations/GraphQLAnnotationsProcessor.java @@ -18,114 +18,114 @@ import graphql.schema.GraphQLType; public interface GraphQLAnnotationsProcessor { - /** - * @deprecated See {@link #getOutputType(Class)} - */ - graphql.schema.GraphQLType getInterface(Class iface) throws GraphQLAnnotationsException; - - /** - * This will examine the class and return a {@link GraphQLUnionType.Builder} ready for further definition - * - * @param iface interface to examine - * - * @return a {@link GraphQLUnionType.Builder} - * - * @throws GraphQLAnnotationsException if the class cannot be examined - * @throws IllegalArgumentException if iface is not an interface - */ - GraphQLUnionType.Builder getUnionBuilder(Class iface) throws GraphQLAnnotationsException, IllegalArgumentException; - - /** - * This will examine the class and return a {@link GraphQLInterfaceType.Builder} ready for further definition - * - * @param iface interface to examine - * - * @return a {@link GraphQLInterfaceType.Builder} - * - * @throws GraphQLAnnotationsException if the class cannot be examined - * @throws IllegalArgumentException if iface is not an interface - */ - GraphQLInterfaceType.Builder getIfaceBuilder(Class iface) throws GraphQLAnnotationsException, IllegalArgumentException; - - /** - * This will examine the object class and return a {@link GraphQLEnumType.Builder} ready for further definition - * - * @param object the object class to examine - * - * @return a {@link GraphQLEnumType.Builder} that represents that object class - * - * @throws GraphQLAnnotationsException if the object class cannot be examined - */ - GraphQLEnumType.Builder getEnumBuilder(Class object) throws GraphQLAnnotationsException; - - /** - * @deprecated See {@link #getOutputType(Class)} - */ - GraphQLObjectType getObject(Class object) throws GraphQLAnnotationsException; - - /** - * This will examine the object and will return a {@link GraphQLOutputType} based on the class type and annotations. - * - If its annotated with {@link GraphQLUnion} it will return a {@link GraphQLUnionType} - * - If its annotated with {@link GraphQLTypeResolver} it will return a {@link GraphQLInterfaceType} - * - It it's an Enum it will return a {@link GraphQLEnumType}, - * otherwise it will return a {@link GraphQLObjectType}. - * - * @param object the object class to examine - * - * @return a {@link GraphQLOutputType} that represents that object class - * - * @throws GraphQLAnnotationsException if the object class cannot be examined - */ - GraphQLOutputType getOutputType(Class object) throws GraphQLAnnotationsException; - - /** - * @deprecated See {@link #getOutputTypeOrRef(Class)} - */ - GraphQLOutputType getObjectOrRef(Class object) throws GraphQLAnnotationsException; - - /** - * This will examine the object class and return a {@link GraphQLOutputType} representation - * which may be a {@link GraphQLOutputType} or a {@link graphql.schema.GraphQLTypeReference} - * - * @param object the object class to examine - * - * @return a {@link GraphQLOutputType} that represents that object class - * - * @throws GraphQLAnnotationsException if the object class cannot be examined - */ - GraphQLOutputType getOutputTypeOrRef(Class object) throws GraphQLAnnotationsException; - - /** - * This will examine the object class and return a {@link GraphQLObjectType.Builder} ready for further definition - * - * @param object the object class to examine - * - * @return a {@link GraphQLObjectType.Builder} that represents that object class - * - * @throws GraphQLAnnotationsException if the object class cannot be examined - */ - GraphQLObjectType.Builder getObjectBuilder(Class object) throws GraphQLAnnotationsException; - - /** - * This will examine the object class and return a {@link GraphQLInputType} representation - * - * @param object the object class to examine - * - * @return a {@link GraphQLInputType} that represents that object class - * - * @throws GraphQLAnnotationsException if the object class cannot be examined - */ - GraphQLInputObjectType getInputObject(Class object) throws GraphQLAnnotationsException; - - /** - * This will turn a {@link GraphQLObjectType} into a corresponding {@link GraphQLInputObjectType} - * - * @param graphQLType the graphql object type - * @param newNamePrefix since graphql types MUST be unique, this prefix will be applied to the new input types - * - * @return a {@link GraphQLInputObjectType} - */ - GraphQLInputType getInputObject(GraphQLType graphQLType, String newNamePrefix); +// /** +// * @deprecated See {@link #getOutputType(Class)} +// */ +// graphql.schema.GraphQLType getInterface(Class iface) throws GraphQLAnnotationsException; +// +// /** +// * This will examine the class and return a {@link GraphQLUnionType.Builder} ready for further definition +// * +// * @param iface interface to examine +// * +// * @return a {@link GraphQLUnionType.Builder} +// * +// * @throws GraphQLAnnotationsException if the class cannot be examined +// * @throws IllegalArgumentException if iface is not an interface +// */ +// GraphQLUnionType.Builder getUnionBuilder(Class iface) throws GraphQLAnnotationsException, IllegalArgumentException; +// +// /** +// * This will examine the class and return a {@link GraphQLInterfaceType.Builder} ready for further definition +// * +// * @param iface interface to examine +// * +// * @return a {@link GraphQLInterfaceType.Builder} +// * +// * @throws GraphQLAnnotationsException if the class cannot be examined +// * @throws IllegalArgumentException if iface is not an interface +// */ +// GraphQLInterfaceType.Builder getIfaceBuilder(Class iface) throws GraphQLAnnotationsException, IllegalArgumentException; +// +// /** +// * This will examine the object class and return a {@link GraphQLEnumType.Builder} ready for further definition +// * +// * @param object the object class to examine +// * +// * @return a {@link GraphQLEnumType.Builder} that represents that object class +// * +// * @throws GraphQLAnnotationsException if the object class cannot be examined +// */ +// GraphQLEnumType.Builder getEnumBuilder(Class object) throws GraphQLAnnotationsException; +// +// /** +// * @deprecated See {@link #getOutputType(Class)} +// */ +// GraphQLObjectType getObject(Class object) throws GraphQLAnnotationsException; +// +// /** +// * This will examine the object and will return a {@link GraphQLOutputType} based on the class type and annotations. +// * - If its annotated with {@link GraphQLUnion} it will return a {@link GraphQLUnionType} +// * - If its annotated with {@link GraphQLTypeResolver} it will return a {@link GraphQLInterfaceType} +// * - It it's an Enum it will return a {@link GraphQLEnumType}, +// * otherwise it will return a {@link GraphQLObjectType}. +// * +// * @param object the object class to examine +// * +// * @return a {@link GraphQLOutputType} that represents that object class +// * +// * @throws GraphQLAnnotationsException if the object class cannot be examined +// */ +// GraphQLOutputType getOutputType(Class object) throws GraphQLAnnotationsException; +// +// /** +// * @deprecated See {@link #getOutputTypeOrRef(Class)} +// */ +// GraphQLOutputType getObjectOrRef(Class object) throws GraphQLAnnotationsException; +// +// /** +// * This will examine the object class and return a {@link GraphQLOutputType} representation +// * which may be a {@link GraphQLOutputType} or a {@link graphql.schema.GraphQLTypeReference} +// * +// * @param object the object class to examine +// * +// * @return a {@link GraphQLOutputType} that represents that object class +// * +// * @throws GraphQLAnnotationsException if the object class cannot be examined +// */ +// GraphQLOutputType getOutputTypeOrRef(Class object) throws GraphQLAnnotationsException; +// +// /** +// * This will examine the object class and return a {@link GraphQLObjectType.Builder} ready for further definition +// * +// * @param object the object class to examine +// * +// * @return a {@link GraphQLObjectType.Builder} that represents that object class +// * +// * @throws GraphQLAnnotationsException if the object class cannot be examined +// */ +// GraphQLObjectType.Builder getObjectBuilder(Class object) throws GraphQLAnnotationsException; +// +// /** +// * This will examine the object class and return a {@link GraphQLInputType} representation +// * +// * @param object the object class to examine +// * +// * @return a {@link GraphQLInputType} that represents that object class +// * +// * @throws GraphQLAnnotationsException if the object class cannot be examined +// */ +// GraphQLInputObjectType getInputObject(Class object) throws GraphQLAnnotationsException; +// +// /** +// * This will turn a {@link GraphQLObjectType} into a corresponding {@link GraphQLInputObjectType} +// * +// * @param graphQLType the graphql object type +// * @param newNamePrefix since graphql types MUST be unique, this prefix will be applied to the new input types +// * +// * @return a {@link GraphQLInputObjectType} +// */ +// GraphQLInputType getInputObject(GraphQLType graphQLType, String newNamePrefix); /** * Register a new type extension class. This extension will be used when the extended object will be created. diff --git a/src/main/java/graphql/annotations/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/GraphQLFieldRetriever.java new file mode 100644 index 00000000..7d82cfcd --- /dev/null +++ b/src/main/java/graphql/annotations/GraphQLFieldRetriever.java @@ -0,0 +1,372 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations; + + +import graphql.annotations.searchAlgorithms.BreadthFirstSearch; +import graphql.annotations.searchAlgorithms.CannotCastMemberException; +import graphql.annotations.searchAlgorithms.ParentalSearch; +import graphql.annotations.typeFunctions.BatchedTypeFunction; +import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.relay.Relay; +import graphql.schema.*; +import graphql.schema.GraphQLNonNull; + +import java.lang.reflect.*; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static graphql.Scalars.GraphQLBoolean; +import static graphql.annotations.ReflectionKit.constructNewInstance; +import static graphql.annotations.ReflectionKit.newInstance; +import static graphql.annotations.util.NamingKit.toGraphqlName; +import static graphql.annotations.util.ObjectUtil.getAllFields; +import static graphql.schema.GraphQLArgument.newArgument; +import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; +import static graphql.schema.GraphQLInputObjectField.newInputObjectField; +import static java.util.Arrays.stream; +import static java.util.Objects.nonNull; + +public class GraphQLFieldRetriever { + + private static final List TYPES_FOR_CONNECTION = Arrays.asList(GraphQLObjectType.class, GraphQLInterfaceType.class, GraphQLUnionType.class, GraphQLTypeReference.class); + private static final String DEFAULT_INPUT_PREFIX = "Input"; + + private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; + private BreadthFirstSearch breadthFirstSearch; + private ParentalSearch parentalSearch; + private GraphQLInputObjectRetriever graphQLInputObjectRetriever; + + public GraphQLFieldRetriever(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, BreadthFirstSearch breadthFirstSearch, ParentalSearch parentalSearch, GraphQLInputObjectRetriever graphQLInputObjectRetriever) { + this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; + this.breadthFirstSearch = breadthFirstSearch; + this.parentalSearch = parentalSearch; + this.graphQLInputObjectRetriever = graphQLInputObjectRetriever; + } + + public GraphQLFieldRetriever() { + this(new GraphQLObjectInfoRetriever(), new BreadthFirstSearch(new GraphQLObjectInfoRetriever()), new ParentalSearch(new GraphQLObjectInfoRetriever()), new GraphQLInputObjectRetriever() ); + } + + public List getExtensionFields(Class object, List fieldsDefined, ProcessingElementsContainer container) throws CannotCastMemberException { + List fields = new ArrayList<>(); + if (container.getExtensionsTypeRegistry().containsKey(object)) { + for (Class aClass : container.getExtensionsTypeRegistry().get(object)) { + for (Method method : graphQLObjectInfoRetriever.getOrderedMethods(aClass)) { + if (method.isBridge() || method.isSynthetic()) { + continue; + } + if (breadthFirstSearch.search(method)) { + addExtensionField(getField(method,container), fields, fieldsDefined); + } + } + for (Field field : getAllFields(aClass).values()) { + if (Modifier.isStatic(field.getModifiers())) { + continue; + } + if (parentalSearch.search(field)) { + addExtensionField(getField(field,container), fields, fieldsDefined); + } + } + } + } + return fields; + } + + public GraphQLFieldDefinition getField(Method method, ProcessingElementsContainer container) throws GraphQLAnnotationsException { + GraphQLFieldDefinition.Builder builder = newFieldDefinition(); + + buildName(method, builder); + + GraphQLType annotation = method.getAnnotation(GraphQLType.class); + TypeFunction typeFunction = container.getDefaultTypeFunction(); + + if (annotation != null) { + typeFunction = newInstance(annotation.value()); + } + AnnotatedType annotatedReturnType = method.getAnnotatedReturnType(); + + TypeFunction outputTypeFunction; + if (method.getAnnotation(GraphQLBatched.class) != null) { + outputTypeFunction = new BatchedTypeFunction(typeFunction); + } else { + outputTypeFunction = typeFunction; + } + + GraphQLOutputType outputType = (GraphQLOutputType) outputTypeFunction.buildType(method.getReturnType(), annotatedReturnType,container); + + boolean isConnection = isConnection(method, outputType); + if (isConnection) { + outputType = getGraphQLConnection(method, outputType, container.getRelay(), container.getTypeRegistry()); + builder.argument(container.getRelay().getConnectionFieldArguments()); + } + + builder.type(outputType); + + + TypeFunction finalTypeFunction = typeFunction; + List args = Arrays.asList(method.getParameters()).stream(). + filter(p -> !DataFetchingEnvironment.class.isAssignableFrom(p.getType())). + map(parameter -> { + Class t = parameter.getType(); + graphql.schema.GraphQLInputType graphQLType = graphQLInputObjectRetriever.getInputObject(finalTypeFunction.buildType(t, parameter.getAnnotatedType(),container), DEFAULT_INPUT_PREFIX,container.getTypeRegistry()); + return getArgument(parameter, graphQLType); + }).collect(Collectors.toList()); + + GraphQLFieldDefinition relayFieldDefinition = null; + if (method.isAnnotationPresent(GraphQLRelayMutation.class)) { + if (!(outputType instanceof GraphQLObjectType || outputType instanceof GraphQLInterfaceType)) { + throw new RuntimeException("outputType should be an object or an interface"); + } + StringBuilder titleBuffer = new StringBuilder(method.getName()); + titleBuffer.setCharAt(0, Character.toUpperCase(titleBuffer.charAt(0))); + String title = titleBuffer.toString(); + List fieldDefinitions = outputType instanceof GraphQLObjectType ? + ((GraphQLObjectType) outputType).getFieldDefinitions() : + ((GraphQLInterfaceType) outputType).getFieldDefinitions(); + relayFieldDefinition = container.getRelay().mutationWithClientMutationId(title, method.getName(), + args.stream(). + map(t -> newInputObjectField().name(t.getName()).type(t.getType()).description(t.getDescription()).build()). + collect(Collectors.toList()), fieldDefinitions, new StaticDataFetcher(null)); + builder.argument(relayFieldDefinition.getArguments()); + builder.type(relayFieldDefinition.getType()); + } else { + builder.argument(args); + } + + GraphQLDescription description = method.getAnnotation(GraphQLDescription.class); + if (description != null) { + builder.description(description.value()); + } + + GraphQLDeprecate deprecate = method.getAnnotation(GraphQLDeprecate.class); + if (deprecate != null) { + builder.deprecate(deprecate.value()); + } + if (method.getAnnotation(Deprecated.class) != null) { + builder.deprecate("Deprecated"); + } + + GraphQLDataFetcher dataFetcher = method.getAnnotation(GraphQLDataFetcher.class); + DataFetcher actualDataFetcher; + if (dataFetcher == null && method.getAnnotation(GraphQLBatched.class) != null) { + actualDataFetcher = new BatchedMethodDataFetcher(method,typeFunction, container); + } else if (dataFetcher == null) { + actualDataFetcher = new MethodDataFetcher(method,typeFunction, container); + } else { + actualDataFetcher = constructDataFetcher(method.getName(), dataFetcher); + } + + if (method.isAnnotationPresent(GraphQLRelayMutation.class) && relayFieldDefinition != null) { + actualDataFetcher = new RelayMutationMethodDataFetcher(method, args, relayFieldDefinition.getArgument("input").getType(), relayFieldDefinition.getType()); + } + + if (isConnection) { + actualDataFetcher = new ConnectionDataFetcher(method.getAnnotation(GraphQLConnection.class).connection(), actualDataFetcher); + } + + builder.dataFetcher(actualDataFetcher); + + return new GraphQLAnnotations.GraphQLFieldDefinitionWrapper(builder.build()); + } + + public GraphQLFieldDefinition getField(Field field,ProcessingElementsContainer container) throws GraphQLAnnotationsException { + GraphQLFieldDefinition.Builder builder = newFieldDefinition(); + GraphQLName name = field.getAnnotation(GraphQLName.class); + builder.name(toGraphqlName(name == null ? field.getName() : name.value())); + GraphQLType annotation = field.getAnnotation(GraphQLType.class); + + TypeFunction typeFunction = container.getDefaultTypeFunction(); + + if (annotation != null) { + typeFunction = newInstance(annotation.value()); + } + + GraphQLOutputType outputType = (GraphQLOutputType) typeFunction.buildType(field.getType(), field.getAnnotatedType(),container); + + boolean isConnection = isConnection(field, outputType); + if (isConnection) { + outputType = getGraphQLConnection(field, outputType,container.getRelay(),container.getTypeRegistry()); + builder.argument(container.getRelay().getConnectionFieldArguments()); + } + + builder.type(outputType); + + GraphQLDescription description = field.getAnnotation(GraphQLDescription.class); + if (description != null) { + builder.description(description.value()); + } + + GraphQLDeprecate deprecate = field.getAnnotation(GraphQLDeprecate.class); + if (deprecate != null) { + builder.deprecate(deprecate.value()); + } + if (field.getAnnotation(Deprecated.class) != null) { + builder.deprecate("Deprecated"); + } + + GraphQLDataFetcher dataFetcher = field.getAnnotation(GraphQLDataFetcher.class); + DataFetcher actualDataFetcher = null; + if (nonNull(dataFetcher)) { + actualDataFetcher = constructDataFetcher(field.getName(), dataFetcher); + } + + if (actualDataFetcher == null) { + + StringBuilder fluentBuffer = new StringBuilder(field.getName()); + fluentBuffer.setCharAt(0, Character.toLowerCase(fluentBuffer.charAt(0))); + String fluentGetter = fluentBuffer.toString(); + + boolean hasFluentGetter = false; + Method fluentMethod = null; + try { + fluentMethod = field.getDeclaringClass().getMethod(fluentGetter); + hasFluentGetter = true; + } catch (NoSuchMethodException x) { + } + + // if there is getter for fields type, use propertyDataFetcher, otherwise use method directly + if (outputType == GraphQLBoolean || (outputType instanceof GraphQLNonNull && ((GraphQLNonNull) outputType).getWrappedType() == GraphQLBoolean)) { + if (checkIfPrefixGetterExists(field.getDeclaringClass(), "is", field.getName()) || + checkIfPrefixGetterExists(field.getDeclaringClass(), "get", field.getName())) { + actualDataFetcher = new ExtensionDataFetcherWrapper(field.getDeclaringClass(), new PropertyDataFetcher(field.getName())); + } + } else if (checkIfPrefixGetterExists(field.getDeclaringClass(), "get", field.getName())) { + actualDataFetcher = new ExtensionDataFetcherWrapper(field.getDeclaringClass(), new PropertyDataFetcher(field.getName())); + } else if (hasFluentGetter) { + actualDataFetcher = new MethodDataFetcher(fluentMethod, typeFunction,container); + } + + if (actualDataFetcher == null) { + actualDataFetcher = new ExtensionDataFetcherWrapper(field.getDeclaringClass(), new FieldDataFetcher(field.getName())); + } + } + + + if (isConnection) { + actualDataFetcher = new ConnectionDataFetcher(field.getAnnotation(GraphQLConnection.class).connection(), actualDataFetcher); + } + + builder.dataFetcher(actualDataFetcher); + + return new GraphQLAnnotations.GraphQLFieldDefinitionWrapper(builder.build()); + } + + private void buildName(Method method, GraphQLFieldDefinition.Builder builder) { + String name = method.getName().replaceFirst("^(is|get|set)(.+)", "$2"); + name = Character.toLowerCase(name.charAt(0)) + name.substring(1); + GraphQLName nameAnn = method.getAnnotation(GraphQLName.class); + builder.name(toGraphqlName(nameAnn == null ? name : nameAnn.value())); + } + + private boolean isConnection(AccessibleObject obj, GraphQLOutputType type) { + if (type instanceof graphql.schema.GraphQLNonNull) { + type = (GraphQLOutputType) ((GraphQLNonNull) type).getWrappedType(); + } + final GraphQLOutputType actualType = type; + return obj.isAnnotationPresent(GraphQLConnection.class) && + actualType instanceof GraphQLList && TYPES_FOR_CONNECTION.stream().anyMatch(aClass -> aClass.isInstance(((GraphQLList) actualType).getWrappedType())); + } + + private GraphQLOutputType getGraphQLConnection(AccessibleObject field, GraphQLOutputType type, Relay relay, Map typeRegistry) { + if (type instanceof GraphQLNonNull) { + GraphQLList listType = (GraphQLList) ((GraphQLNonNull) type).getWrappedType(); + return new GraphQLNonNull(internalGetGraphQLConnection(field, listType, relay, typeRegistry)); + } else { + return internalGetGraphQLConnection(field, (GraphQLList) type, relay, typeRegistry); + } + } + + private GraphQLOutputType internalGetGraphQLConnection(AccessibleObject field, GraphQLList listType, Relay relay, Map typeRegistry) { + GraphQLOutputType wrappedType = (GraphQLOutputType) listType.getWrappedType(); + String connectionName = field.getAnnotation(GraphQLConnection.class).name(); + connectionName = connectionName.isEmpty() ? wrappedType.getName() : connectionName; + GraphQLObjectType edgeType = getActualType(relay.edgeType(connectionName, wrappedType, null, Collections.emptyList()), typeRegistry); + return getActualType(relay.connectionType(connectionName, edgeType, Collections.emptyList()), typeRegistry); + } + + private void addExtensionField(GraphQLFieldDefinition gqlField, List fields, List fieldsDefined) { + if (!fieldsDefined.contains(gqlField.getName())) { + fieldsDefined.add(gqlField.getName()); + fields.add(gqlField); + } else { + throw new GraphQLAnnotationsException("Duplicate field found in extension : " + gqlField.getName(), null); + } + } + + private GraphQLObjectType getActualType(GraphQLObjectType type, Map typeRegistry) { + if (typeRegistry.containsKey(type.getName())) { + type = (GraphQLObjectType) typeRegistry.get(type.getName()); + } else { + typeRegistry.put(type.getName(), type); + } + return type; + } + + protected GraphQLArgument getArgument(Parameter parameter, graphql.schema.GraphQLInputType t) throws + GraphQLAnnotationsException { + GraphQLArgument.Builder builder = newArgument().type(t); + GraphQLDescription description = parameter.getAnnotation(GraphQLDescription.class); + if (description != null) { + builder.description(description.value()); + } + GraphQLDefaultValue defaultValue = parameter.getAnnotation(GraphQLDefaultValue.class); + if (defaultValue != null) { + builder.defaultValue(newInstance(defaultValue.value()).get()); + } + GraphQLName name = parameter.getAnnotation(GraphQLName.class); + if (name != null) { + builder.name(toGraphqlName(name.value())); + } else { + builder.name(toGraphqlName(parameter.getName())); + } + return builder.build(); + } + + private DataFetcher constructDataFetcher(String fieldName, GraphQLDataFetcher annotatedDataFetcher) { + final String[] args; + if (annotatedDataFetcher.firstArgIsTargetName()) { + args = Stream.concat(Stream.of(fieldName), stream(annotatedDataFetcher.args())).toArray(String[]::new); + } else { + args = annotatedDataFetcher.args(); + } + if (args.length == 0) { + return newInstance(annotatedDataFetcher.value()); + } else { + try { + final Constructor ctr = annotatedDataFetcher.value().getDeclaredConstructor( + stream(args).map(v -> String.class).toArray(Class[]::new)); + return constructNewInstance(ctr, (Object[]) args); + } catch (final NoSuchMethodException e) { + throw new GraphQLAnnotationsException("Unable to instantiate DataFetcher via constructor for: " + fieldName, e); + } + } + } + + + // check if there is getter for field, basic functionality taken from PropertyDataFetcher + private boolean checkIfPrefixGetterExists(Class c, String prefix, String propertyName) { + String getterName = prefix + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); + try { + Method method = c.getMethod(getterName); + } catch (NoSuchMethodException x) { + return false; + } + + return true; + } + +} diff --git a/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java b/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java new file mode 100644 index 00000000..f0b139a5 --- /dev/null +++ b/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java @@ -0,0 +1,53 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations; + + +import graphql.schema.*; +import graphql.schema.GraphQLNonNull; + +import java.util.Map; +import java.util.stream.Collectors; + +public class GraphQLInputObjectRetriever { + + public GraphQLInputType getInputObject(graphql.schema.GraphQLType graphQLType, String newNamePrefix, Map typeRegistry) { + if (graphQLType instanceof GraphQLObjectType) { + GraphQLObjectType object = (GraphQLObjectType) graphQLType; + if (typeRegistry.containsKey(newNamePrefix + object.getName()) && typeRegistry.get(newNamePrefix + object.getName()) instanceof GraphQLInputType) { + return (GraphQLInputType) typeRegistry.get(newNamePrefix + object.getName()); + } + GraphQLInputObjectType inputObjectType = new GraphQLInputObjectType(newNamePrefix + object.getName(), object.getDescription(), + object.getFieldDefinitions().stream(). + map(field -> { + GraphQLOutputType type = field.getType(); + GraphQLInputType inputType = getInputObject(type, newNamePrefix,typeRegistry); + return new GraphQLInputObjectField(field.getName(), field.getDescription(), inputType, null); + }). + collect(Collectors.toList())); + typeRegistry.put(inputObjectType.getName(), inputObjectType); + return inputObjectType; + } else if (graphQLType instanceof GraphQLList) { + return new GraphQLList(getInputObject(((GraphQLList)graphQLType).getWrappedType(), newNamePrefix,typeRegistry)); + } else if (graphQLType instanceof graphql.schema.GraphQLNonNull) { + return new graphql.schema.GraphQLNonNull(getInputObject(((GraphQLNonNull)graphQLType).getWrappedType(), newNamePrefix,typeRegistry)); + } else if (graphQLType instanceof GraphQLTypeReference) { + return new GraphQLTypeReference(newNamePrefix + ((GraphQLTypeReference)graphQLType).getName()); + } else if (graphQLType instanceof GraphQLInputType){ + return (GraphQLInputType) graphQLType; + } + throw new IllegalArgumentException("Cannot convert type to input : "+graphQLType); + } +} diff --git a/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java b/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java new file mode 100644 index 00000000..f69eb442 --- /dev/null +++ b/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java @@ -0,0 +1,19 @@ +package graphql.annotations; + +import graphql.annotations.util.GraphQLOutputObjectRetriever; + +public class GraphQLInterfaceRetriever { + + private GraphQLOutputObjectRetriever graphQLOutputObjectRetriever; + + public GraphQLInterfaceRetriever(GraphQLOutputObjectRetriever graphQLOutputObjectRetriever){ + this.graphQLOutputObjectRetriever=graphQLOutputObjectRetriever; + } + + public GraphQLInterfaceRetriever(){ + this(new GraphQLOutputObjectRetriever()); + } + public graphql.schema.GraphQLOutputType getInterface(Class iface, ProcessingElementsContainer container) throws GraphQLAnnotationsException { + return graphQLOutputObjectRetriever.getOutputType(iface,container); + } +} diff --git a/src/main/java/graphql/annotations/GraphQLObjectHandler.java b/src/main/java/graphql/annotations/GraphQLObjectHandler.java new file mode 100644 index 00000000..17401a28 --- /dev/null +++ b/src/main/java/graphql/annotations/GraphQLObjectHandler.java @@ -0,0 +1,42 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations; + +import graphql.annotations.searchAlgorithms.CannotCastMemberException; +import graphql.annotations.util.GraphQLOutputObjectRetriever; +import graphql.schema.GraphQLObjectType; +import graphql.schema.GraphQLOutputType; + +public class GraphQLObjectHandler { + + private GraphQLOutputObjectRetriever outputObjectRetriever; + + public GraphQLObjectHandler(GraphQLOutputObjectRetriever outputObjectRetriever) { + this.outputObjectRetriever = outputObjectRetriever; + } + + public GraphQLObjectHandler() { + this(new GraphQLOutputObjectRetriever()); + } + + public GraphQLObjectType getObject(Class object, ProcessingElementsContainer container) throws GraphQLAnnotationsException, CannotCastMemberException { + GraphQLOutputType type = outputObjectRetriever.getOutputType(object, container); + if (type instanceof GraphQLObjectType) { + return (GraphQLObjectType) type; + } else { + throw new IllegalArgumentException("Object resolve to a " + type.getClass().getSimpleName()); + } + } +} diff --git a/src/main/java/graphql/annotations/GraphQLType.java b/src/main/java/graphql/annotations/GraphQLType.java index 15ce51e8..3d0f4870 100644 --- a/src/main/java/graphql/annotations/GraphQLType.java +++ b/src/main/java/graphql/annotations/GraphQLType.java @@ -14,6 +14,8 @@ */ package graphql.annotations; +import graphql.annotations.typeFunctions.DefaultTypeFunction; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/src/main/java/graphql/annotations/MethodDataFetcher.java b/src/main/java/graphql/annotations/MethodDataFetcher.java index e4808d62..0b610acc 100644 --- a/src/main/java/graphql/annotations/MethodDataFetcher.java +++ b/src/main/java/graphql/annotations/MethodDataFetcher.java @@ -18,29 +18,25 @@ import graphql.schema.GraphQLType; import java.lang.reflect.*; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.Parameter; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import static graphql.annotations.ReflectionKit.constructNewInstance; -import static graphql.annotations.ReflectionKit.constructor; import static graphql.annotations.ReflectionKit.newInstance; import static graphql.annotations.util.NamingKit.toGraphqlName; class MethodDataFetcher implements DataFetcher { private final Method method; + private final ProcessingElementsContainer container; private final TypeFunction typeFunction; - public MethodDataFetcher(Method method) { - this(method, new DefaultTypeFunction()); - } - public MethodDataFetcher(Method method, TypeFunction typeFunction) { + + public MethodDataFetcher(Method method,TypeFunction typeFunction, ProcessingElementsContainer container) { this.method = method; - this.typeFunction = typeFunction; + this.typeFunction=typeFunction; + this.container = container; } @Override @@ -60,13 +56,13 @@ public Object get(DataFetchingEnvironment environment) { return null; } } - return method.invoke(obj, invocationArgs(environment)); + return method.invoke(obj, invocationArgs(environment,container)); } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } - private Object[] invocationArgs(DataFetchingEnvironment environment) { + private Object[] invocationArgs(DataFetchingEnvironment environment,ProcessingElementsContainer container) { List result = new ArrayList<>(); Map envArgs = environment.getArguments(); for (Parameter p : method.getParameters()) { @@ -84,7 +80,7 @@ private Object[] invocationArgs(DataFetchingEnvironment environment) { continue; } - graphql.schema.GraphQLType graphQLType = typeFunction.buildType(true, paramType, p.getAnnotatedType()); + graphql.schema.GraphQLType graphQLType = typeFunction.buildType(true, paramType, p.getAnnotatedType(),container); if (envArgs.containsKey(parameterName)) { result.add(buildArg(p.getParameterizedType(), graphQLType, envArgs.get(parameterName))); } else { diff --git a/src/main/java/graphql/annotations/ProcessingElementsContainer.java b/src/main/java/graphql/annotations/ProcessingElementsContainer.java new file mode 100644 index 00000000..6103d36d --- /dev/null +++ b/src/main/java/graphql/annotations/ProcessingElementsContainer.java @@ -0,0 +1,87 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations; + + +import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.typeFunctions.DefaultTypeFunction; +import graphql.relay.Relay; +import graphql.schema.*; +import graphql.schema.GraphQLType; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.Stack; + +public class ProcessingElementsContainer { + + private TypeFunction defaultTypeFunction; + private graphql.relay.Relay relay; + private Map typeRegistry; + private Map, Set>> extensionsTypeRegistry; + private Stack processing; + + + public ProcessingElementsContainer(TypeFunction defaultTypeFunction, Relay relay, Map typeRegistry, Map, Set>> extensionsTypeRegistry, Stack processing) { + this.defaultTypeFunction = defaultTypeFunction; + this.relay = relay; + this.typeRegistry = typeRegistry; + this.extensionsTypeRegistry = extensionsTypeRegistry; + this.processing = processing; + } + + + public Relay getRelay() { + return this.relay; + } + + public void setRelay(Relay relay) { + this.relay = relay; + } + + public Map getTypeRegistry() { + return this.typeRegistry; + } + + public void setTypeRegistry(Map typeRegistry) { + this.typeRegistry = typeRegistry; + } + + public Map, Set>> getExtensionsTypeRegistry() { + return this.extensionsTypeRegistry; + } + + public void setExtensionsTypeRegistry(Map, Set>> extensionsTypeRegistry) { + this.extensionsTypeRegistry = extensionsTypeRegistry; + } + + public TypeFunction getDefaultTypeFunction() { + return defaultTypeFunction; + } + + public void setDefaultTypeFunction(TypeFunction defaultTypeFunction) { + this.defaultTypeFunction = defaultTypeFunction; + } + + public Stack getProcessing() { + return processing; + } + + public void setProcessing(Stack processing) { + this.processing = processing; + } +} diff --git a/src/main/java/graphql/annotations/ReflectionKit.java b/src/main/java/graphql/annotations/ReflectionKit.java index a86a5b0d..a4c4fcc6 100644 --- a/src/main/java/graphql/annotations/ReflectionKit.java +++ b/src/main/java/graphql/annotations/ReflectionKit.java @@ -21,8 +21,8 @@ * A package level helper in calling reflective methods and turning them into * GraphQLAnnotationsException runtime exceptions */ -class ReflectionKit { - static T newInstance(Class clazz) throws GraphQLAnnotationsException { +public class ReflectionKit { + public static T newInstance(Class clazz) throws GraphQLAnnotationsException { try { return clazz.newInstance(); } catch (InstantiationException | IllegalAccessException e) { @@ -30,7 +30,7 @@ static T newInstance(Class clazz) throws GraphQLAnnotationsException { } } - static T constructNewInstance(Constructor constructor, Object... args) throws GraphQLAnnotationsException { + public static T constructNewInstance(Constructor constructor, Object... args) throws GraphQLAnnotationsException { try { return constructor.newInstance(args); @@ -39,7 +39,7 @@ static T constructNewInstance(Constructor constructor, Object... args) th } } - static Constructor constructor(Class type, Class... parameterTypes) { + public static Constructor constructor(Class type, Class... parameterTypes) { try { return type.getConstructor(parameterTypes); } catch (NoSuchMethodException e) { @@ -47,7 +47,7 @@ static Constructor constructor(Class type, Class... parameterTypes) } } - static T newInstance(Class clazz, Object parameter) { + public static T newInstance(Class clazz, Object parameter) { if (parameter != null) { for (Constructor constructor : (Constructor[]) clazz.getConstructors()) { if (constructor.getParameterCount() == 1 && constructor.getParameters()[0].getType().isAssignableFrom(parameter.getClass())) { diff --git a/src/main/java/graphql/annotations/TypeFunction.java b/src/main/java/graphql/annotations/TypeFunction.java index 5e003f2c..30f49944 100644 --- a/src/main/java/graphql/annotations/TypeFunction.java +++ b/src/main/java/graphql/annotations/TypeFunction.java @@ -17,6 +17,7 @@ import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedType; +import java.util.Map; /** * A GraphQLType builder for java types. @@ -41,15 +42,10 @@ default String getTypeName(Class aClass, AnnotatedType annotatedType) { */ boolean canBuildType(Class aClass, AnnotatedType annotatedType); - /** - * Build a {@link GraphQLType} object from a java type. - * This is a convenience method for calling {@link #buildType(boolean, Class, AnnotatedType)} without a type name. - * @param aClass The java type to build the type name for - * @param annotatedType The {@link AnnotatedType} of the java type, which may be a {link AnnotatedParameterizedType} - * @return The built {@link GraphQLType} - */ - default GraphQLType buildType(Class aClass, AnnotatedType annotatedType) { - return buildType(false, aClass, annotatedType); + + + default GraphQLType buildType(Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + return buildType(false, aClass, annotatedType,container); } /** @@ -59,5 +55,6 @@ default GraphQLType buildType(Class aClass, AnnotatedType annotatedType) { * @param annotatedType The {@link AnnotatedType} of the java type, which may be a {link AnnotatedParameterizedType} * @return The built {@link GraphQLType} */ - GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType); + + GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container); } diff --git a/src/main/java/graphql/annotations/UnionTypeResolver.java b/src/main/java/graphql/annotations/UnionTypeResolver.java new file mode 100644 index 00000000..cc6119c9 --- /dev/null +++ b/src/main/java/graphql/annotations/UnionTypeResolver.java @@ -0,0 +1,45 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations; + +import graphql.TypeResolutionEnvironment; +import graphql.schema.*; +import graphql.schema.GraphQLType; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +public class UnionTypeResolver implements TypeResolver { + private final Map, graphql.schema.GraphQLType> types = new HashMap<>(); + + public UnionTypeResolver(Class[] classes, ProcessingElementsContainer container) { + Arrays.stream(classes). + forEach(c -> types.put(c,container.getDefaultTypeFunction().buildType(c, null, container))); + } + + @Override + public GraphQLObjectType getType(TypeResolutionEnvironment env) { + Object object = env.getObject(); + Optional, GraphQLType>> maybeType = types.entrySet(). + stream().filter(e -> e.getKey().isAssignableFrom(object.getClass())).findFirst(); + if (maybeType.isPresent()) { + return (GraphQLObjectType) maybeType.get().getValue(); + } else { + throw new RuntimeException("Unknown type " + object.getClass()); + } + } +} diff --git a/src/main/java/graphql/annotations/util/GraphQLObjectInfoRetriever.java b/src/main/java/graphql/annotations/util/GraphQLObjectInfoRetriever.java new file mode 100644 index 00000000..a3c0d95b --- /dev/null +++ b/src/main/java/graphql/annotations/util/GraphQLObjectInfoRetriever.java @@ -0,0 +1,52 @@ +/** + * Copyright 2016 Yurii Rashkovskii + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.util; + + +import graphql.annotations.GraphQLField; +import graphql.annotations.GraphQLName; + +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +import static graphql.annotations.util.NamingKit.toGraphqlName; + +public class GraphQLObjectInfoRetriever { + + public String getTypeName(Class objectClass) { + GraphQLName name = objectClass.getAnnotation(GraphQLName.class); + return toGraphqlName(name == null ? objectClass.getSimpleName() : name.value()); + } + + public List getOrderedMethods(Class c) { + return Arrays.stream(c.getMethods()) + .sorted(Comparator.comparing(Method::getName)) + .collect(Collectors.toList()); + } + + public static Boolean isGraphQLField(AnnotatedElement element) { + GraphQLField annotation = element.getAnnotation(GraphQLField.class); + if (annotation == null) { + return null; + } + return annotation.value(); + } + + +} diff --git a/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java b/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java new file mode 100644 index 00000000..0a2c958a --- /dev/null +++ b/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java @@ -0,0 +1,71 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.util; + +import graphql.annotations.*; +import graphql.annotations.builders.EnumBuilder; +import graphql.annotations.builders.InterfaceBuilder; +import graphql.annotations.builders.ObjectBuilder; +import graphql.annotations.builders.UnionBuilder; +import graphql.annotations.searchAlgorithms.BreadthFirstSearch; +import graphql.annotations.searchAlgorithms.CannotCastMemberException; +import graphql.annotations.searchAlgorithms.ParentalSearch; +import graphql.schema.GraphQLOutputType; + +public class GraphQLOutputObjectRetriever { + + private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; + private GraphQLFieldRetriever graphQLFieldRetriever; + + public GraphQLOutputObjectRetriever(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLFieldRetriever graphQLFieldRetriever) { + this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; + this.graphQLFieldRetriever = graphQLFieldRetriever; + } + + public GraphQLOutputObjectRetriever() { + this(new GraphQLObjectInfoRetriever(), new GraphQLFieldRetriever()); + } + + public GraphQLOutputType getOutputType(Class object, ProcessingElementsContainer container) throws GraphQLAnnotationsException, CannotCastMemberException { + // because the TypeFunction can call back to this processor and + // Java classes can be circular, we need to protect against + // building the same type twice because graphql-java 3.x requires + // all type instances to be unique singletons + String typeName = graphQLObjectInfoRetriever.getTypeName(object); + + GraphQLOutputType type = (GraphQLOutputType) container.getTypeRegistry().get(typeName); + if (type != null) { // type already exists, do not build a new new one + return type; + } + + container.getProcessing().push(typeName); + if (object.getAnnotation(GraphQLUnion.class) != null) { + type = new UnionBuilder(graphQLObjectInfoRetriever).getUnionBuilder(object, container).build(); + } else if (object.isAnnotationPresent(GraphQLTypeResolver.class)) { + type = new InterfaceBuilder(graphQLObjectInfoRetriever, graphQLFieldRetriever).getInterfaceBuilder(object, container).build(); + } else if (Enum.class.isAssignableFrom(object)) { + type = new EnumBuilder(graphQLObjectInfoRetriever).getEnumBuilder(object).build(); + } else { + InterfaceBuilder interfaceBuilder = new InterfaceBuilder(graphQLObjectInfoRetriever, graphQLFieldRetriever); + type = new ObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), new BreadthFirstSearch(graphQLObjectInfoRetriever), graphQLFieldRetriever, interfaceBuilder,new GraphQLInterfaceRetriever()).getObjectBuilder(object, container, this).build(); + } + + container.getTypeRegistry().put(typeName, type); + container.getProcessing().pop(); + + return type; + } + +} diff --git a/src/main/java/graphql/annotations/util/ObjectUtil.java b/src/main/java/graphql/annotations/util/ObjectUtil.java new file mode 100644 index 00000000..cd8f692b --- /dev/null +++ b/src/main/java/graphql/annotations/util/ObjectUtil.java @@ -0,0 +1,38 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations.util; + +import java.lang.reflect.Field; +import java.util.Map; +import java.util.TreeMap; + +public class ObjectUtil { + + public static Map getAllFields(Class c) { + Map fields; + + if (c.getSuperclass() != null) { + fields = getAllFields(c.getSuperclass()); + } else { + fields = new TreeMap<>(); + } + + for (Field f : c.getDeclaredFields()) { + fields.put(f.getName(), f); + } + + return fields; + } +} From 6d7258041289214483e351ef443c1d863d9e3352 Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 13:11:32 +0200 Subject: [PATCH 07/25] fix tests --- .../annotations/DefaultTypeFunctionTest.java | 305 ------------------ .../annotations/GraphQLExtensionsTest.java | 15 +- .../annotations/GraphQLFragmentTest.java | 4 +- .../graphql/annotations/GraphQLInputTest.java | 20 +- .../annotations/GraphQLInterfaceTest.java | 11 +- .../annotations/GraphQLObjectTest.java | 28 +- .../annotations/GraphQLSimpleSchemaTest.java | 6 +- .../annotations/MethodDataFetcherTest.java | 2 +- .../java/graphql/annotations/RelayTest.java | 2 +- .../typeFunctions/BooleanFunctionTests.java | 28 ++ .../DefaultTypeFunctionTest.java | 208 ++++++++++++ .../DefaultTypeFunctionTestHelper.java | 16 + .../typeFunctions/FloatFunctionTests.java | 30 ++ .../java/typeFunctions/IDFunctionTests.java | 103 ++++++ .../typeFunctions/IntegerFunctionTests.java | 28 ++ .../java/typeFunctions/LongFunctionTests.java | 26 ++ .../typeFunctions/StringFunctionTests.java | 29 ++ 17 files changed, 521 insertions(+), 340 deletions(-) delete mode 100644 src/test/java/graphql/annotations/DefaultTypeFunctionTest.java create mode 100644 src/test/java/typeFunctions/BooleanFunctionTests.java create mode 100644 src/test/java/typeFunctions/DefaultTypeFunctionTest.java create mode 100644 src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java create mode 100644 src/test/java/typeFunctions/FloatFunctionTests.java create mode 100644 src/test/java/typeFunctions/IDFunctionTests.java create mode 100644 src/test/java/typeFunctions/IntegerFunctionTests.java create mode 100644 src/test/java/typeFunctions/LongFunctionTests.java create mode 100644 src/test/java/typeFunctions/StringFunctionTests.java diff --git a/src/test/java/graphql/annotations/DefaultTypeFunctionTest.java b/src/test/java/graphql/annotations/DefaultTypeFunctionTest.java deleted file mode 100644 index 81fa2b44..00000000 --- a/src/test/java/graphql/annotations/DefaultTypeFunctionTest.java +++ /dev/null @@ -1,305 +0,0 @@ -/** - * Copyright 2016 Yurii Rashkovskii - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - */ -package graphql.annotations; - -import graphql.schema.*; -import graphql.schema.GraphQLType; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static graphql.Scalars.*; -import static graphql.Scalars.GraphQLID; -import static org.testng.Assert.*; - -public class DefaultTypeFunctionTest { - - @BeforeMethod - public void init() { - GraphQLAnnotations.getInstance().getTypeRegistry().clear(); - } - - private enum A { - @GraphQLName("someA") @GraphQLDescription("a") A, B - } - - public @GraphQLID String idStringMethod() { - return "asd"; - } - - public @GraphQLID Integer idIntegerMethod() { - return 5; - } - - public @GraphQLID int idIntMethod() { - return 5; - } - - public @GraphQLID String idStringField; - public @GraphQLID Integer idIntegerField; - public @GraphQLID int idIntField; - - @Test - public void enumeration() { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - GraphQLType enumeration = instance.buildType(A.class, null); - assertTrue(enumeration instanceof GraphQLEnumType); - List values = ((GraphQLEnumType) enumeration).getValues(); - assertEquals(values.stream(). - map(GraphQLEnumValueDefinition::getName).collect(Collectors.toList()), - Arrays.asList("someA", "B")); - assertEquals(values.stream(). - map(GraphQLEnumValueDefinition::getDescription).collect(Collectors.toList()), - Arrays.asList("a", "B")); - - } - - @Test - public void buildType_stringMethodAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchMethodException, NoSuchFieldException { - // Arrange - DefaultTypeFunction instance = testedDefaultTypeFunction(); - Method idStringMethod = DefaultTypeFunctionTest.class.getMethod("idStringMethod"); - - // Act+Assert - assertEquals(instance.buildType(idStringMethod.getReturnType(), idStringMethod.getAnnotatedReturnType()), GraphQLID); - } - - @Test - public void buildType_integerMethodAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchMethodException { - // Arrange - DefaultTypeFunction instance = testedDefaultTypeFunction(); - Method idIntegerMethod = DefaultTypeFunctionTest.class.getMethod("idIntegerMethod"); - - // Act+Assert - assertEquals(instance.buildType(idIntegerMethod.getReturnType(), idIntegerMethod.getAnnotatedReturnType()), GraphQLID); - } - - @Test - public void buildType_intMethodAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchMethodException { - // Arrange - DefaultTypeFunction instance = testedDefaultTypeFunction(); - Method idIntMethod = DefaultTypeFunctionTest.class.getMethod("idIntMethod"); - - // Act+Assert - assertEquals(instance.buildType(idIntMethod.getReturnType(), idIntMethod.getAnnotatedReturnType()), GraphQLID); - } - - @Test - public void buildType_stringFieldAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchFieldException { - // Arrange - DefaultTypeFunction instance = testedDefaultTypeFunction(); - Field idStringField = DefaultTypeFunctionTest.class.getField("idStringField"); - - // Act+Assert - assertEquals(instance.buildType(idStringField.getType(), idStringField.getAnnotatedType()), GraphQLID); - } - - @Test - public void buildType_integerFieldAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchFieldException { - // Arrange - DefaultTypeFunction instance = testedDefaultTypeFunction(); - Field idIntegerField = DefaultTypeFunctionTest.class.getField("idIntegerField"); - - // Act+Assert - assertEquals(instance.buildType(idIntegerField.getType(), idIntegerField.getAnnotatedType()), GraphQLID); - } - - @Test - public void buildType_intFieldAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchFieldException { - // Arrange - DefaultTypeFunction instance = testedDefaultTypeFunction(); - Field idIntField = DefaultTypeFunctionTest.class.getField("idIntField"); - - // Act+Assert - assertEquals(instance.buildType(idIntField.getType(), idIntField.getAnnotatedType()), GraphQLID); - } - - @Test - public void buildType_stringType_returnsGraphQLString() { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - assertEquals(instance.buildType(String.class, null), GraphQLString); - } - - @Test - public void buildType_booleanType_returnsGraphQLBoolean() { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - assertEquals(instance.buildType(boolean.class, null), GraphQLBoolean); - assertEquals(instance.buildType(Boolean.class, null), GraphQLBoolean); - } - - @Test - public void buildType_floatType_returnsGraphQLFloat() { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - assertEquals(instance.buildType(float.class, null), GraphQLFloat); - assertEquals(instance.buildType(Float.class, null), GraphQLFloat); - assertEquals(instance.buildType(Double.class, null), GraphQLFloat); - assertEquals(instance.buildType(double.class, null), GraphQLFloat); - } - - @Test - public void buildType_integerType_returnsGraphQLInt() { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - assertEquals(instance.buildType(int.class, null), GraphQLInt); - assertEquals(instance.buildType(Integer.class, null), GraphQLInt); - } - - @Test - public void buildType_longType_returnsGraphQLLong() { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - assertEquals(instance.buildType(long.class, null), GraphQLLong); - assertEquals(instance.buildType(Long.class, null), GraphQLLong); - } - - - @SuppressWarnings("unused") - public List> listMethod() { - return null; - } - - @SuppressWarnings("unused") - public Iterable> iterableMethod() { - return null; - } - - @SuppressWarnings("unused") - public Collection> collectionMethod() { - return null; - } - - - @SuppressWarnings("unused") - public Stream> streamMethod() { - return null; - } - - @SuppressWarnings("unused") - public Set> setMethod() { - return null; - } - - // GraphqlList(GraphqlList(GraphQlString) is expected here - private void assertIsGraphListOfListOfString(GraphQLType type) { - assertTrue(type instanceof GraphQLList); - GraphQLList subtype = (GraphQLList) ((GraphQLList) type).getWrappedType(); - assertTrue(subtype.getWrappedType() instanceof graphql.schema.GraphQLNonNull); - graphql.schema.GraphQLNonNull wrappedType = (graphql.schema.GraphQLNonNull) subtype.getWrappedType(); - assertEquals(wrappedType.getWrappedType(), GraphQLString); - } - - @Test - public void buildType_listType_returnsCorrectGraphQLType() throws NoSuchMethodException { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - graphql.schema.GraphQLType type = instance.buildType(getClass().getMethod("listMethod").getReturnType(), getClass().getMethod("listMethod").getAnnotatedReturnType()); - assertIsGraphListOfListOfString(type); - } - - - @Test - public void buildType_iterableType_returnsCorrectGraphQLType() throws NoSuchMethodException { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - graphql.schema.GraphQLType type = instance.buildType(getClass().getMethod("iterableMethod").getReturnType(), getClass().getMethod("iterableMethod").getAnnotatedReturnType()); - assertIsGraphListOfListOfString(type); - } - - @Test - public void buildType_collectionType_returnsCorrectGraphQLType() throws NoSuchMethodException { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - graphql.schema.GraphQLType type = instance.buildType(getClass().getMethod("collectionMethod").getReturnType(), getClass().getMethod("collectionMethod").getAnnotatedReturnType()); - assertIsGraphListOfListOfString(type); - } - - @Test - public void buildType_setType_returnsCorrectGraphQLType() throws NoSuchMethodException { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - graphql.schema.GraphQLType type = instance.buildType(getClass().getMethod("setMethod").getReturnType(), getClass().getMethod("setMethod").getAnnotatedReturnType()); - assertIsGraphListOfListOfString(type); - } - - @Test - public void buildType_streamType_returnsCorrectGraphQLType() throws NoSuchMethodException { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - graphql.schema.GraphQLType type = instance.buildType(getClass().getMethod("streamMethod").getReturnType(), getClass().getMethod("listMethod").getAnnotatedReturnType()); - assertIsGraphListOfListOfString(type); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void unparameterizedList() { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - List v = new LinkedList(); - instance.buildType(v.getClass(), null); - } - - @SuppressWarnings("unused") - public Optional> optionalMethod() { - return Optional.empty(); - } - - @Test - public void optional() throws NoSuchMethodException { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - graphql.schema.GraphQLType type = instance.buildType(getClass().getMethod("optionalMethod").getReturnType(), getClass().getMethod("listMethod").getAnnotatedReturnType()); - assertTrue(type instanceof GraphQLList); - GraphQLType subtype = ((GraphQLList) type).getWrappedType(); - assertTrue(subtype instanceof graphql.schema.GraphQLNonNull); - GraphQLType wrappedType = (((graphql.schema.GraphQLNonNull) subtype).getWrappedType()); - assertEquals(wrappedType, GraphQLString); - } - - - @Test(expectedExceptions = IllegalArgumentException.class) - public void unparametrizedOptional() { - DefaultTypeFunction instance = testedDefaultTypeFunction(); - Optional v = Optional.empty(); - instance.buildType(v.getClass(), null); - } - - public static class Class1 { - @GraphQLField - public Class2 class2; - } - - public static class Class2 { - @GraphQLField - public Class1 class1; - @GraphQLField - public Class2 class2; - } - - @Test - public void recursiveTypes() throws Exception { - GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations(); - DefaultTypeFunction instance = (DefaultTypeFunction) graphQLAnnotations.defaultTypeFunction; - GraphQLType type = instance.buildType(Class1.class, Class2.class.getField("class1").getAnnotatedType()); - GraphQLFieldDefinition class1class2 = ((GraphQLObjectType) type).getFieldDefinition("class2"); - assertNotNull(class1class2); - assertTrue(((GraphQLObjectType) class1class2.getType()).getFieldDefinition("class1").getType() instanceof GraphQLTypeReference); - assertTrue(((GraphQLObjectType) class1class2.getType()).getFieldDefinition("class2").getType() instanceof GraphQLTypeReference); - GraphQLAnnotations.instance = new GraphQLAnnotations(); - } - - private DefaultTypeFunction testedDefaultTypeFunction() { - // wire up the ability - GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations(); - DefaultTypeFunction defaultTypeFunction = new DefaultTypeFunction(); - defaultTypeFunction.setAnnotationsProcessor(graphQLAnnotations); - return defaultTypeFunction; - } -} diff --git a/src/test/java/graphql/annotations/GraphQLExtensionsTest.java b/src/test/java/graphql/annotations/GraphQLExtensionsTest.java index 7ff508bb..efa7eaf9 100644 --- a/src/test/java/graphql/annotations/GraphQLExtensionsTest.java +++ b/src/test/java/graphql/annotations/GraphQLExtensionsTest.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -95,7 +95,8 @@ public Object get(DataFetchingEnvironment environment) { public void fields() { GraphQLAnnotations instance = new GraphQLAnnotations(); instance.registerTypeExtension(TestObjectExtension.class); - GraphQLObjectType object = instance.getObject(GraphQLExtensionsTest.TestObject.class); + GraphQLObjectHandler graphQLObjectHandler = new GraphQLObjectHandler(); + GraphQLObjectType object = graphQLObjectHandler.getObject(GraphQLExtensionsTest.TestObject.class, instance.getContainer()); instance.unregisterTypeExtension(TestObjectExtension.class); List fields = object.getFieldDefinitions(); @@ -114,7 +115,8 @@ public void fields() { public void values() { GraphQLAnnotations instance = new GraphQLAnnotations(); instance.registerTypeExtension(TestObjectExtension.class); - GraphQLObjectType object = instance.getObject(GraphQLExtensionsTest.TestObject.class); + GraphQLObjectHandler graphQLObjectHandler = new GraphQLObjectHandler(); + GraphQLObjectType object = graphQLObjectHandler.getObject(GraphQLExtensionsTest.TestObject.class, instance.getContainer()); instance.unregisterTypeExtension(TestObjectExtension.class); GraphQLSchema schema = newSchema().query(object).build(); @@ -132,8 +134,9 @@ public void values() { @Test public void testDuplicateField() { GraphQLAnnotations instance = new GraphQLAnnotations(); + GraphQLObjectHandler graphQLObjectHandler = new GraphQLObjectHandler(); instance.registerTypeExtension(TestObjectExtensionInvalid.class); - GraphQLAnnotationsException e = expectThrows(GraphQLAnnotationsException.class, () -> instance.getObject(TestObject.class)); + GraphQLAnnotationsException e = expectThrows(GraphQLAnnotationsException.class, () -> graphQLObjectHandler.getObject(TestObject.class,instance.getContainer())); assertTrue(e.getMessage().startsWith("Duplicate field")); instance.unregisterTypeExtension(TestObjectExtensionInvalid.class); } diff --git a/src/test/java/graphql/annotations/GraphQLFragmentTest.java b/src/test/java/graphql/annotations/GraphQLFragmentTest.java index f993f9f4..5357925d 100644 --- a/src/test/java/graphql/annotations/GraphQLFragmentTest.java +++ b/src/test/java/graphql/annotations/GraphQLFragmentTest.java @@ -50,8 +50,8 @@ public void init() { public void testInterfaceInlineFragment() throws Exception { // Given registry = new HashMap<>(); + GraphQLInterfaceRetriever graphQLInterfaceRetriever=new GraphQLInterfaceRetriever(); - GraphQLInterfaceType iface = (GraphQLInterfaceType) GraphQLAnnotations.iface(MyInterface.class); GraphQLObjectType rootType = GraphQLAnnotations.object(RootObject.class); @@ -63,6 +63,8 @@ public void testInterfaceInlineFragment() throws Exception { registry.put("MyObject", objectType); + GraphQLInterfaceType iface = (GraphQLInterfaceType) graphQLInterfaceRetriever.getInterface(MyInterface.class,GraphQLAnnotations.getInstance().getContainer()); + GraphQLSchema schema = GraphQLSchema.newSchema() .query(rootType) .build(new HashSet<>(Arrays.asList(iface, objectType))); diff --git a/src/test/java/graphql/annotations/GraphQLInputTest.java b/src/test/java/graphql/annotations/GraphQLInputTest.java index 992cc96a..a3e65b52 100644 --- a/src/test/java/graphql/annotations/GraphQLInputTest.java +++ b/src/test/java/graphql/annotations/GraphQLInputTest.java @@ -42,7 +42,7 @@ public GraphQLObjectType getType(TypeResolutionEnvironment env) { } static class SubInputObject { - public SubInputObject(String subKey) { + public SubInputObject(@GraphQLName("subKey") String subKey) { this.subKey = subKey; } @@ -51,7 +51,7 @@ public SubInputObject(String subKey) { } static class InputObject { - public InputObject(String key, List complex) { + public InputObject(@GraphQLName("key") String key, @GraphQLName("complex") List complex) { this.key = key; this.complex = complex; } @@ -64,7 +64,7 @@ public InputObject(String key, List complex) { } static class RecursiveInputObject { - public RecursiveInputObject(HashMap map) { + public RecursiveInputObject(@GraphQLName("map") HashMap map) { key = (String) map.get("key"); if (map.containsKey("rec")) { rec = new RecursiveInputObject((HashMap) map.get("rec")); @@ -81,20 +81,20 @@ public RecursiveInputObject(HashMap map) { @GraphQLTypeResolver(Resolver.class) interface TestIface { @GraphQLField - String value(InputObject input); + String value(@GraphQLName("input") InputObject input); } static class TestObject implements TestIface { @Override - public String value(InputObject input) { + public String value(@GraphQLName("input") InputObject input) { return input.key + "a"; } } static class TestObjectList { @GraphQLField - public String value(List>> input) { + public String value(@GraphQLName("input") List>> input) { InputObject inputObject = input.get(0).get(0).get(0); return inputObject.key + "-" + inputObject.complex.get(0).subKey; } @@ -102,13 +102,13 @@ public String value(List>> input) { static class TestObjectRec { @GraphQLField - public String value(RecursiveInputObject input) { + public String value(@GraphQLName("input") RecursiveInputObject input) { return (input.rec != null ? ("rec"+input.rec.key) : input.key) + "a"; } } static class Code { - public Code(HashMap map) { + public Code(@GraphQLName("map") HashMap map) { this.firstField = (String) map.get("firstField"); this.secondField = (String) map.get("secondField"); } @@ -121,12 +121,12 @@ public Code(HashMap map) { static class QueryMultipleDefinitions { @GraphQLField - public String something(Code code) { + public String something(@GraphQLName("code") Code code) { return code.firstField + code.secondField; } @GraphQLField - public String somethingElse(Code code) { + public String somethingElse(@GraphQLName("code") Code code) { return code.firstField + code.secondField; } } diff --git a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java index 6ff391c2..24b86a32 100644 --- a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java +++ b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java @@ -52,7 +52,9 @@ interface NoResolverIface { @Test public void noResolver() { - GraphQLObjectType object = (GraphQLObjectType) GraphQLAnnotations.iface(NoResolverIface.class); + GraphQLInterfaceRetriever graphQLInterfaceRetriever=new GraphQLInterfaceRetriever(); + + GraphQLObjectType object = (GraphQLObjectType) graphQLInterfaceRetriever.getInterface(NoResolverIface.class,GraphQLAnnotations.getInstance().getContainer()); List fields = object.getFieldDefinitions(); assertEquals(fields.size(), 1); assertEquals(fields.get(0).getName(), "value"); @@ -105,7 +107,9 @@ public String value() { @Test public void test() { - GraphQLInterfaceType iface = (GraphQLInterfaceType) GraphQLAnnotations.iface(TestIface.class); + + GraphQLInterfaceRetriever graphQLInterfaceRetriever=new GraphQLInterfaceRetriever(); + GraphQLInterfaceType iface = (GraphQLInterfaceType) graphQLInterfaceRetriever.getInterface(TestIface.class,GraphQLAnnotations.getInstance().getContainer()); List fields = iface.getFieldDefinitions(); assertEquals(fields.size(), 1); assertEquals(fields.get(0).getName(), "value"); @@ -113,7 +117,8 @@ public void test() { @Test public void testUnion() { - GraphQLUnionType unionType = (GraphQLUnionType) GraphQLAnnotations.iface(TestUnion.class); + GraphQLInterfaceRetriever graphQLInterfaceRetriever=new GraphQLInterfaceRetriever(); + GraphQLUnionType unionType = (GraphQLUnionType) graphQLInterfaceRetriever.getInterface(TestUnion.class,GraphQLAnnotations.getInstance().getContainer()); assertEquals(unionType.getTypes().size(), 1); assertEquals(unionType.getTypes().get(0).getName(), "TestObject1"); } diff --git a/src/test/java/graphql/annotations/GraphQLObjectTest.java b/src/test/java/graphql/annotations/GraphQLObjectTest.java index 2c767a81..f96e84fd 100644 --- a/src/test/java/graphql/annotations/GraphQLObjectTest.java +++ b/src/test/java/graphql/annotations/GraphQLObjectTest.java @@ -75,12 +75,12 @@ String field() { } @GraphQLField - public String fieldWithArgs(@GraphQLNonNull String a, @GraphQLDefaultValue(DefaultAValue.class) @GraphQLDescription("b") String b) { + public String fieldWithArgs(@GraphQLName("a") @GraphQLNonNull String a, @GraphQLName("b") @GraphQLDefaultValue(DefaultAValue.class) @GraphQLDescription("b") String b) { return b; } @GraphQLField - public String fieldWithArgsAndEnvironment(DataFetchingEnvironment env, String a, String b) { + public String fieldWithArgsAndEnvironment(DataFetchingEnvironment env,@GraphQLName("a") String a, @GraphQLName("b") String b) { return a; } @@ -494,7 +494,7 @@ public static class Class2 { @Test public void recursiveTypes() { GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations(); - GraphQLObjectType object = graphQLAnnotations.getObject(Class1.class); + GraphQLObjectType object = new GraphQLObjectHandler().getObject(Class1.class,graphQLAnnotations.getContainer()); GraphQLSchema schema = newSchema().query(object).build(); Class1 class1 = new Class1(); @@ -553,7 +553,7 @@ private static class TestInputArgument { @GraphQLField public int b; - public TestInputArgument(String a, int b) { + public TestInputArgument(@GraphQLName("a") String a, @GraphQLName("b") int b) { this.a = a; this.b = b; } @@ -563,7 +563,7 @@ private static class TestComplexInputArgument { public Collection inputs; - public TestComplexInputArgument(Collection inputs) { + public TestComplexInputArgument(@GraphQLName("inputs") Collection inputs) { this.inputs = inputs; } @@ -578,12 +578,12 @@ public Collection getInputs() { private static class TestObjectInput { @GraphQLField - public String test(int other, TestInputArgument arg) { + public String test(@GraphQLName("other") int other, @GraphQLName("arg") TestInputArgument arg) { return arg.a; } @GraphQLField - public String test2(int other, TestComplexInputArgument arg) { + public String test2(@GraphQLName("other") int other, @GraphQLName("arg") TestComplexInputArgument arg) { return arg.inputs.iterator().next().a; } } @@ -597,7 +597,7 @@ public void inputObjectArgument() { assertEquals(argument.getName(), "arg"); GraphQLSchema schema = newSchema().query(object).build(); - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ test(arg: { a:\"ok\", b:2 }, other:0) }", new TestObjectInput()); + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ test( other:0,arg: { a:\"ok\", b:2 }) }", new TestObjectInput()); assertTrue(result.getErrors().isEmpty()); Map v = (Map) result.getData(); assertEquals(v.get("test"), "ok"); @@ -620,7 +620,8 @@ public void complexInputObjectArgument() { @Test public void inputObject() { GraphQLObjectType object = GraphQLAnnotations.object(TestObjectInput.class); - GraphQLInputObjectType inputObjectType = GraphQLAnnotations.inputObject(object, "input"); + GraphQLInputObjectRetriever graphQLInputObjectRetrieve=new GraphQLInputObjectRetriever(); + GraphQLInputObjectType inputObjectType = (GraphQLInputObjectType) graphQLInputObjectRetrieve.getInputObject(object, "input",GraphQLAnnotations.getInstance().getContainer().getTypeRegistry()); assertEquals(inputObjectType.getFields().size(), object.getFieldDefinitions().size()); } @@ -630,12 +631,16 @@ public boolean canBuildType(Class aClass, AnnotatedType annotatedType) { return aClass == UUID.class; } + @Override + public GraphQLType buildType(boolean input, Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { + return buildType(input,aClass,annotatedType); + } + @Override public String getTypeName(Class aClass, AnnotatedType annotatedType) { return "UUID"; } - @Override public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { return GraphQLString; } @@ -680,7 +685,8 @@ public void queryOptional() { @Test public void optionalInput() { GraphQLObjectType object = GraphQLAnnotations.object(OptionalTest.class); - GraphQLInputObjectType inputObject = GraphQLAnnotations.inputObject(object, "input"); + GraphQLInputObjectRetriever graphQLInputObjectRetriever=new GraphQLInputObjectRetriever(); + GraphQLInputObjectType inputObject = (GraphQLInputObjectType) graphQLInputObjectRetriever.getInputObject(object, "input",GraphQLAnnotations.getInstance().getTypeRegistry()); GraphQLObjectType mutation = GraphQLObjectType.newObject().name("mut").field(newFieldDefinition().name("test").type(object). argument(GraphQLArgument.newArgument().type(inputObject).name("input").build()).dataFetcher(environment -> { Map input = environment.getArgument("input"); diff --git a/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java b/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java index f61e82d3..b80671ad 100644 --- a/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java +++ b/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java @@ -70,7 +70,8 @@ public User defaultUser2() { @Test public void detachedCall() { GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations(); - GraphQLObjectType queryObject = graphQLAnnotations.getObject(Query.class); + GraphQLObjectHandler graphQLObjectHandler=new GraphQLObjectHandler(); + GraphQLObjectType queryObject = graphQLObjectHandler.getObject(Query.class,graphQLAnnotations.getContainer()); GraphQL graphql = GraphQL.newGraphQL(newSchema().query(queryObject).build()).build(); ExecutionResult result = graphql.execute("{ defaultUser{ name } }"); @@ -81,7 +82,8 @@ public void detachedCall() { @Test public void staticCall() { GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations(); - GraphQLObjectType queryObject = graphQLAnnotations.getObject(Query.class); + GraphQLObjectHandler graphQLObjectHandler=new GraphQLObjectHandler(); + GraphQLObjectType queryObject = graphQLObjectHandler.getObject(Query.class,graphQLAnnotations.getContainer()); GraphQL graphql = GraphQL.newGraphQL(newSchema().query(queryObject).build()).build(); ExecutionResult result = graphql.execute("{ defaultUser2{ name } }"); diff --git a/src/test/java/graphql/annotations/MethodDataFetcherTest.java b/src/test/java/graphql/annotations/MethodDataFetcherTest.java index 62916e5d..ada01b30 100644 --- a/src/test/java/graphql/annotations/MethodDataFetcherTest.java +++ b/src/test/java/graphql/annotations/MethodDataFetcherTest.java @@ -39,7 +39,7 @@ public String method() throws TestException { @Test(expectedExceptions = RuntimeException.class) public void exceptionRethrowing() { try { - MethodDataFetcher methodDataFetcher = new MethodDataFetcher(getClass().getMethod("method")); + MethodDataFetcher methodDataFetcher = new MethodDataFetcher(getClass().getMethod("method"),null,null); methodDataFetcher.get(new DataFetchingEnvironmentImpl(this, new HashMap(), null, null, null, new ArrayList<>(), null, null, null, null, null, null, null)); } catch (NoSuchMethodException e) { e.printStackTrace(); diff --git a/src/test/java/graphql/annotations/RelayTest.java b/src/test/java/graphql/annotations/RelayTest.java index dcfefa9b..2fe9d2b6 100644 --- a/src/test/java/graphql/annotations/RelayTest.java +++ b/src/test/java/graphql/annotations/RelayTest.java @@ -75,7 +75,7 @@ public Result doSomething() { return new Result(0); } @GraphQLField @GraphQLRelayMutation - public Result doSomethingElse(@GraphQLDescription("A") int a, int b) { + public Result doSomethingElse(@GraphQLName("a") @GraphQLDescription("A") int a, @GraphQLName("b") int b) { return new Result(a - b); } @GraphQLField @GraphQLRelayMutation diff --git a/src/test/java/typeFunctions/BooleanFunctionTests.java b/src/test/java/typeFunctions/BooleanFunctionTests.java new file mode 100644 index 00000000..c658f654 --- /dev/null +++ b/src/test/java/typeFunctions/BooleanFunctionTests.java @@ -0,0 +1,28 @@ +package typeFunctions; + +import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.typeFunctions.DefaultTypeFunction; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static graphql.Scalars.GraphQLBoolean; +import static org.testng.Assert.assertEquals; +import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; + +/** + * Created by Yael on 25/10/17. + */ +public class BooleanFunctionTests { + + @BeforeMethod + public void init() { + GraphQLAnnotations.getInstance().getTypeRegistry().clear(); + } + + @Test + public void buildType_booleanType_returnsGraphQLBoolean() { + DefaultTypeFunction instance = testedDefaultTypeFunction(); + assertEquals(instance.buildType(boolean.class, null,null), GraphQLBoolean); + assertEquals(instance.buildType(Boolean.class, null,null), GraphQLBoolean); + } +} diff --git a/src/test/java/typeFunctions/DefaultTypeFunctionTest.java b/src/test/java/typeFunctions/DefaultTypeFunctionTest.java new file mode 100644 index 00000000..d129b260 --- /dev/null +++ b/src/test/java/typeFunctions/DefaultTypeFunctionTest.java @@ -0,0 +1,208 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package typeFunctions; + +import graphql.annotations.*; +import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.typeFunctions.DefaultTypeFunction; +import graphql.schema.*; +import graphql.schema.GraphQLType; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static graphql.Scalars.GraphQLString; +import static org.testng.Assert.*; + +public class DefaultTypeFunctionTest { + + @BeforeMethod + public void init() { + GraphQLAnnotations.getInstance().getTypeRegistry().clear(); + } + + private enum A { + @GraphQLName("someA") @GraphQLDescription("a") A, B + } + + public @graphql.annotations.GraphQLID String idStringMethod() { + return "asd"; + } + + public @GraphQLID Integer idIntegerMethod() { + return 5; + } + + public @GraphQLID int idIntMethod() { + return 5; + } + + public @GraphQLID String idStringField; + public @GraphQLID Integer idIntegerField; + public @GraphQLID int idIntField; + + @Test + public void enumeration() { + ProcessingElementsContainer container = testedProcessingElementsContainer(); + GraphQLType enumeration = container.getDefaultTypeFunction().buildType(A.class, null,container); + assertTrue(enumeration instanceof GraphQLEnumType); + List values = ((GraphQLEnumType) enumeration).getValues(); + assertEquals(values.stream(). + map(GraphQLEnumValueDefinition::getName).collect(Collectors.toList()), + Arrays.asList("someA", "B")); + assertEquals(values.stream(). + map(GraphQLEnumValueDefinition::getDescription).collect(Collectors.toList()), + Arrays.asList("a", "B")); + + } + + + + + @SuppressWarnings("unused") + public List> listMethod() { + return null; + } + + @SuppressWarnings("unused") + public Iterable> iterableMethod() { + return null; + } + + @SuppressWarnings("unused") + public Collection> collectionMethod() { + return null; + } + + + @SuppressWarnings("unused") + public Stream> streamMethod() { + return null; + } + + @SuppressWarnings("unused") + public Set> setMethod() { + return null; + } + + // GraphqlList(GraphqlList(GraphQlString) is expected here + private void assertIsGraphListOfListOfString(GraphQLType type) { + assertTrue(type instanceof GraphQLList); + GraphQLList subtype = (GraphQLList) ((GraphQLList) type).getWrappedType(); + assertTrue(subtype.getWrappedType() instanceof graphql.schema.GraphQLNonNull); + graphql.schema.GraphQLNonNull wrappedType = (graphql.schema.GraphQLNonNull) subtype.getWrappedType(); + assertEquals(wrappedType.getWrappedType(), GraphQLString); + } + + @Test + public void buildType_listType_returnsCorrectGraphQLType() throws NoSuchMethodException { + ProcessingElementsContainer container = testedProcessingElementsContainer(); + graphql.schema.GraphQLType type = container.getDefaultTypeFunction().buildType(getClass().getMethod("listMethod").getReturnType(), getClass().getMethod("listMethod").getAnnotatedReturnType(),null); + assertIsGraphListOfListOfString(type); + } + + + @Test + public void buildType_iterableType_returnsCorrectGraphQLType() throws NoSuchMethodException { + ProcessingElementsContainer container = testedProcessingElementsContainer(); + graphql.schema.GraphQLType type = container.getDefaultTypeFunction().buildType(getClass().getMethod("iterableMethod").getReturnType(), getClass().getMethod("iterableMethod").getAnnotatedReturnType(),null); + assertIsGraphListOfListOfString(type); + } + + @Test + public void buildType_collectionType_returnsCorrectGraphQLType() throws NoSuchMethodException { + ProcessingElementsContainer container = testedProcessingElementsContainer(); + graphql.schema.GraphQLType type = container.getDefaultTypeFunction().buildType(getClass().getMethod("collectionMethod").getReturnType(), getClass().getMethod("collectionMethod").getAnnotatedReturnType(),null); + assertIsGraphListOfListOfString(type); + } + + @Test + public void buildType_setType_returnsCorrectGraphQLType() throws NoSuchMethodException { + ProcessingElementsContainer container = testedProcessingElementsContainer(); + graphql.schema.GraphQLType type = container.getDefaultTypeFunction().buildType(getClass().getMethod("setMethod").getReturnType(), getClass().getMethod("setMethod").getAnnotatedReturnType(),null); + assertIsGraphListOfListOfString(type); + } + + @Test + public void buildType_streamType_returnsCorrectGraphQLType() throws NoSuchMethodException { + ProcessingElementsContainer container = testedProcessingElementsContainer(); + graphql.schema.GraphQLType type = container.getDefaultTypeFunction().buildType(getClass().getMethod("streamMethod").getReturnType(), getClass().getMethod("listMethod").getAnnotatedReturnType(),null); + assertIsGraphListOfListOfString(type); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void unparameterizedList() { + ProcessingElementsContainer container = testedProcessingElementsContainer(); + List v = new LinkedList(); + container.getDefaultTypeFunction().buildType(v.getClass(), null,null); + } + + @SuppressWarnings("unused") + public Optional> optionalMethod() { + return Optional.empty(); + } + + @Test + public void optional() throws NoSuchMethodException { + ProcessingElementsContainer container = testedProcessingElementsContainer(); + graphql.schema.GraphQLType type = container.getDefaultTypeFunction().buildType(getClass().getMethod("optionalMethod").getReturnType(), getClass().getMethod("listMethod").getAnnotatedReturnType(),null); + assertTrue(type instanceof GraphQLList); + GraphQLType subtype = ((GraphQLList) type).getWrappedType(); + assertTrue(subtype instanceof graphql.schema.GraphQLNonNull); + GraphQLType wrappedType = (((graphql.schema.GraphQLNonNull) subtype).getWrappedType()); + assertEquals(wrappedType, GraphQLString); + } + + + @Test(expectedExceptions = IllegalArgumentException.class) + public void unparametrizedOptional() { + ProcessingElementsContainer oontainer = testedProcessingElementsContainer(); + Optional v = Optional.empty(); + oontainer.getDefaultTypeFunction().buildType(v.getClass(), null,null); + } + + public static class Class1 { + @GraphQLField + public Class2 class2; + } + + public static class Class2 { + @GraphQLField + public Class1 class1; + @GraphQLField + public Class2 class2; + } + + @Test + public void recursiveTypes() throws Exception { + ProcessingElementsContainer container = testedProcessingElementsContainer(); + GraphQLType type = container.getDefaultTypeFunction().buildType(Class1.class, Class2.class.getField("class1").getAnnotatedType(),container); + GraphQLFieldDefinition class1class2 = ((GraphQLObjectType) type).getFieldDefinition("class2"); + assertNotNull(class1class2); + assertTrue(((GraphQLObjectType) class1class2.getType()).getFieldDefinition("class1").getType() instanceof GraphQLTypeReference); + assertTrue(((GraphQLObjectType) class1class2.getType()).getFieldDefinition("class2").getType() instanceof GraphQLTypeReference); + GraphQLAnnotations.instance = new GraphQLAnnotations(); + } + + private ProcessingElementsContainer testedProcessingElementsContainer() { + // wire up the ability + GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations(); + return graphQLAnnotations.getContainer(); + } +} diff --git a/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java b/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java new file mode 100644 index 00000000..c5ba8ec3 --- /dev/null +++ b/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java @@ -0,0 +1,16 @@ +package typeFunctions; + +import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.typeFunctions.DefaultTypeFunction; + +public class DefaultTypeFunctionTestHelper { + public static DefaultTypeFunction testedDefaultTypeFunction() { + // wire up the ability + GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations(); + DefaultTypeFunction defaultTypeFunction = new DefaultTypeFunction(new GraphQLInputProcessor(),new GraphQLOutputProcessor()); + defaultTypeFunction.setAnnotationsProcessor(graphQLAnnotations); + return defaultTypeFunction; + } +} diff --git a/src/test/java/typeFunctions/FloatFunctionTests.java b/src/test/java/typeFunctions/FloatFunctionTests.java new file mode 100644 index 00000000..f5bffb7c --- /dev/null +++ b/src/test/java/typeFunctions/FloatFunctionTests.java @@ -0,0 +1,30 @@ +package typeFunctions; + +import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.typeFunctions.DefaultTypeFunction; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static graphql.Scalars.GraphQLFloat; +import static org.testng.Assert.assertEquals; +import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; + +/** + * Created by Yael on 25/10/17. + */ +public class FloatFunctionTests { + + @BeforeMethod + public void init() { + GraphQLAnnotations.getInstance().getTypeRegistry().clear(); + } + + @Test + public void buildType_floatType_returnsGraphQLFloat() { + DefaultTypeFunction instance = testedDefaultTypeFunction(); + assertEquals(instance.buildType(float.class, null,null), GraphQLFloat); + assertEquals(instance.buildType(Float.class, null,null), GraphQLFloat); + assertEquals(instance.buildType(Double.class, null,null), GraphQLFloat); + assertEquals(instance.buildType(double.class, null,null), GraphQLFloat); + } +} diff --git a/src/test/java/typeFunctions/IDFunctionTests.java b/src/test/java/typeFunctions/IDFunctionTests.java new file mode 100644 index 00000000..4a26e441 --- /dev/null +++ b/src/test/java/typeFunctions/IDFunctionTests.java @@ -0,0 +1,103 @@ +package typeFunctions; + +import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.GraphQLID; +import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.typeFunctions.DefaultTypeFunction; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import static graphql.Scalars.GraphQLID; +import static org.testng.Assert.assertEquals; +import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; + + +public class IDFunctionTests { + + @BeforeMethod + public void init() { + GraphQLAnnotations.getInstance().getTypeRegistry().clear(); + } + + public @graphql.annotations.GraphQLID String idStringMethod() { + return "asd"; + } + + public @GraphQLID Integer idIntegerMethod() { + return 5; + } + + public @GraphQLID int idIntMethod() { + return 5; + } + + public @GraphQLID String idStringField; + public @GraphQLID Integer idIntegerField; + public @GraphQLID int idIntField; + + @Test + public void buildType_stringMethodAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchMethodException, NoSuchFieldException { + // Arrange + DefaultTypeFunction instance = testedDefaultTypeFunction(); + Method idStringMethod = IDFunctionTests.class.getMethod("idStringMethod"); + + // Act+Assert + assertEquals(instance.buildType(idStringMethod.getReturnType(), idStringMethod.getAnnotatedReturnType(),null), GraphQLID); + } + + @Test + public void buildType_integerMethodAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchMethodException { + // Arrange + DefaultTypeFunction instance = testedDefaultTypeFunction(); + Method idIntegerMethod = IDFunctionTests.class.getMethod("idIntegerMethod"); + + // Act+Assert + assertEquals(instance.buildType(idIntegerMethod.getReturnType(), idIntegerMethod.getAnnotatedReturnType(),null), GraphQLID); + } + + @Test + public void buildType_intMethodAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchMethodException { + // Arrange + DefaultTypeFunction instance = testedDefaultTypeFunction(); + Method idIntMethod = IDFunctionTests.class.getMethod("idIntMethod"); + + // Act+Assert + assertEquals(instance.buildType(idIntMethod.getReturnType(), idIntMethod.getAnnotatedReturnType(),null), GraphQLID); + } + + @Test + public void buildType_stringFieldAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchFieldException { + // Arrange + DefaultTypeFunction instance = testedDefaultTypeFunction(); + Field idStringField = IDFunctionTests.class.getField("idStringField"); + + // Act+Assert + assertEquals(instance.buildType(idStringField.getType(), idStringField.getAnnotatedType(),null), GraphQLID); + } + + @Test + public void buildType_integerFieldAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchFieldException { + // Arrange + DefaultTypeFunction instance = testedDefaultTypeFunction(); + Field idIntegerField = IDFunctionTests.class.getField("idIntegerField"); + + // Act+Assert + assertEquals(instance.buildType(idIntegerField.getType(), idIntegerField.getAnnotatedType(),null), GraphQLID); + } + + @Test + public void buildType_intFieldAnnotatedWithGraphQLID_returnsGraphQLID() throws NoSuchFieldException { + // Arrange + DefaultTypeFunction instance = testedDefaultTypeFunction(); + Field idIntField = IDFunctionTests.class.getField("idIntField"); + + // Act+Assert + assertEquals(instance.buildType(idIntField.getType(), idIntField.getAnnotatedType(),null), GraphQLID); + } + + +} diff --git a/src/test/java/typeFunctions/IntegerFunctionTests.java b/src/test/java/typeFunctions/IntegerFunctionTests.java new file mode 100644 index 00000000..30b83a77 --- /dev/null +++ b/src/test/java/typeFunctions/IntegerFunctionTests.java @@ -0,0 +1,28 @@ +package typeFunctions; + +import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.typeFunctions.DefaultTypeFunction; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static graphql.Scalars.GraphQLInt; +import static org.testng.Assert.assertEquals; +import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; + +/** + * Created by Yael on 25/10/17. + */ +public class IntegerFunctionTests { + + @BeforeMethod + public void init() { + GraphQLAnnotations.getInstance().getTypeRegistry().clear(); + } + + @Test + public void buildType_integerType_returnsGraphQLInt() { + DefaultTypeFunction instance = testedDefaultTypeFunction(); + assertEquals(instance.buildType(int.class, null,null), GraphQLInt); + assertEquals(instance.buildType(Integer.class, null,null), GraphQLInt); + } +} diff --git a/src/test/java/typeFunctions/LongFunctionTests.java b/src/test/java/typeFunctions/LongFunctionTests.java new file mode 100644 index 00000000..c47071a3 --- /dev/null +++ b/src/test/java/typeFunctions/LongFunctionTests.java @@ -0,0 +1,26 @@ +package typeFunctions; + + +import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.typeFunctions.DefaultTypeFunction; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static graphql.Scalars.GraphQLLong; +import static org.testng.Assert.assertEquals; +import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; + +public class LongFunctionTests { + + @BeforeMethod + public void init() { + GraphQLAnnotations.getInstance().getTypeRegistry().clear(); + } + + @Test + public void buildType_longType_returnsGraphQLLong() { + DefaultTypeFunction instance = testedDefaultTypeFunction(); + assertEquals(instance.buildType(long.class, null,null), GraphQLLong); + assertEquals(instance.buildType(Long.class, null,null), GraphQLLong); + } +} diff --git a/src/test/java/typeFunctions/StringFunctionTests.java b/src/test/java/typeFunctions/StringFunctionTests.java new file mode 100644 index 00000000..bf07f893 --- /dev/null +++ b/src/test/java/typeFunctions/StringFunctionTests.java @@ -0,0 +1,29 @@ +package typeFunctions; + +import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.typeFunctions.DefaultTypeFunction; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static graphql.Scalars.GraphQLString; +import static org.testng.Assert.assertEquals; +import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; + +/** + * Created by Yael on 25/10/17. + */ +public class StringFunctionTests { + + @BeforeMethod + public void init() { + GraphQLAnnotations.getInstance().getTypeRegistry().clear(); + } + + @Test + public void buildType_stringType_returnsGraphQLString() { + DefaultTypeFunction instance = testedDefaultTypeFunction(); + assertEquals(instance.buildType(String.class, null,null), GraphQLString); + } + + +} From 81a48a72e5c36db19d4dc1c84da60b35eb1d0179 Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 13:38:23 +0200 Subject: [PATCH 08/25] add license --- .../annotations/GraphQLInterfaceRetriever.java | 14 ++++++++++++++ .../typeFunctions/BooleanFunctionTests.java | 17 ++++++++++++++--- .../typeFunctions/DefaultTypeFunctionTest.java | 3 --- .../DefaultTypeFunctionTestHelper.java | 14 ++++++++++++++ .../java/typeFunctions/FloatFunctionTests.java | 17 ++++++++++++++--- .../java/typeFunctions/IDFunctionTests.java | 16 ++++++++++++++-- .../typeFunctions/IntegerFunctionTests.java | 17 ++++++++++++++--- .../java/typeFunctions/LongFunctionTests.java | 14 ++++++++++++++ .../java/typeFunctions/StringFunctionTests.java | 17 ++++++++++++++--- 9 files changed, 112 insertions(+), 17 deletions(-) diff --git a/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java b/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java index f69eb442..fab50640 100644 --- a/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java +++ b/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations; import graphql.annotations.util.GraphQLOutputObjectRetriever; diff --git a/src/test/java/typeFunctions/BooleanFunctionTests.java b/src/test/java/typeFunctions/BooleanFunctionTests.java index c658f654..3f667c30 100644 --- a/src/test/java/typeFunctions/BooleanFunctionTests.java +++ b/src/test/java/typeFunctions/BooleanFunctionTests.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package typeFunctions; import graphql.annotations.GraphQLAnnotations; @@ -9,9 +23,6 @@ import static org.testng.Assert.assertEquals; import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; -/** - * Created by Yael on 25/10/17. - */ public class BooleanFunctionTests { @BeforeMethod diff --git a/src/test/java/typeFunctions/DefaultTypeFunctionTest.java b/src/test/java/typeFunctions/DefaultTypeFunctionTest.java index d129b260..3016dbf4 100644 --- a/src/test/java/typeFunctions/DefaultTypeFunctionTest.java +++ b/src/test/java/typeFunctions/DefaultTypeFunctionTest.java @@ -15,9 +15,6 @@ package typeFunctions; import graphql.annotations.*; -import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; -import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; -import graphql.annotations.typeFunctions.DefaultTypeFunction; import graphql.schema.*; import graphql.schema.GraphQLType; import org.testng.annotations.BeforeMethod; diff --git a/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java b/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java index c5ba8ec3..1a3bebd9 100644 --- a/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java +++ b/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package typeFunctions; import graphql.annotations.GraphQLAnnotations; diff --git a/src/test/java/typeFunctions/FloatFunctionTests.java b/src/test/java/typeFunctions/FloatFunctionTests.java index f5bffb7c..460374b3 100644 --- a/src/test/java/typeFunctions/FloatFunctionTests.java +++ b/src/test/java/typeFunctions/FloatFunctionTests.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package typeFunctions; import graphql.annotations.GraphQLAnnotations; @@ -9,9 +23,6 @@ import static org.testng.Assert.assertEquals; import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; -/** - * Created by Yael on 25/10/17. - */ public class FloatFunctionTests { @BeforeMethod diff --git a/src/test/java/typeFunctions/IDFunctionTests.java b/src/test/java/typeFunctions/IDFunctionTests.java index 4a26e441..18a222f3 100644 --- a/src/test/java/typeFunctions/IDFunctionTests.java +++ b/src/test/java/typeFunctions/IDFunctionTests.java @@ -1,9 +1,21 @@ +/** + * Copyright 2016 Yurii Rashkovskii + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package typeFunctions; import graphql.annotations.GraphQLAnnotations; import graphql.annotations.GraphQLID; -import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; -import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; import graphql.annotations.typeFunctions.DefaultTypeFunction; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff --git a/src/test/java/typeFunctions/IntegerFunctionTests.java b/src/test/java/typeFunctions/IntegerFunctionTests.java index 30b83a77..108425fa 100644 --- a/src/test/java/typeFunctions/IntegerFunctionTests.java +++ b/src/test/java/typeFunctions/IntegerFunctionTests.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package typeFunctions; import graphql.annotations.GraphQLAnnotations; @@ -9,9 +23,6 @@ import static org.testng.Assert.assertEquals; import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; -/** - * Created by Yael on 25/10/17. - */ public class IntegerFunctionTests { @BeforeMethod diff --git a/src/test/java/typeFunctions/LongFunctionTests.java b/src/test/java/typeFunctions/LongFunctionTests.java index c47071a3..e63f5cfd 100644 --- a/src/test/java/typeFunctions/LongFunctionTests.java +++ b/src/test/java/typeFunctions/LongFunctionTests.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package typeFunctions; diff --git a/src/test/java/typeFunctions/StringFunctionTests.java b/src/test/java/typeFunctions/StringFunctionTests.java index bf07f893..0cbf3677 100644 --- a/src/test/java/typeFunctions/StringFunctionTests.java +++ b/src/test/java/typeFunctions/StringFunctionTests.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package typeFunctions; import graphql.annotations.GraphQLAnnotations; @@ -9,9 +23,6 @@ import static org.testng.Assert.assertEquals; import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; -/** - * Created by Yael on 25/10/17. - */ public class StringFunctionTests { @BeforeMethod From a16d9f1c3d19c7cb8064cf84d7d3d1c1c3b03d6f Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 14:36:55 +0200 Subject: [PATCH 09/25] fix license --- .../graphql/annotations/GraphQLAnnotations.java | 8 ++++---- .../annotations/GraphQLInterfaceRetriever.java | 8 ++++---- .../annotations/builders/InterfaceBuilder.java | 14 ++++++++++++++ .../typeFunctions/DefaultTypeFunction.java | 8 ++++---- .../util/GraphQLObjectInfoRetriever.java | 8 ++++---- .../graphql/annotations/GraphQLExtensionsTest.java | 8 ++++---- .../java/typeFunctions/BooleanFunctionTests.java | 8 ++++---- .../DefaultTypeFunctionTestHelper.java | 8 ++++---- .../java/typeFunctions/FloatFunctionTests.java | 8 ++++---- src/test/java/typeFunctions/IDFunctionTests.java | 8 ++++---- .../java/typeFunctions/IntegerFunctionTests.java | 8 ++++---- src/test/java/typeFunctions/LongFunctionTests.java | 8 ++++---- .../java/typeFunctions/StringFunctionTests.java | 8 ++++---- 13 files changed, 62 insertions(+), 48 deletions(-) diff --git a/src/main/java/graphql/annotations/GraphQLAnnotations.java b/src/main/java/graphql/annotations/GraphQLAnnotations.java index e1e0fc52..73b54c94 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/GraphQLAnnotations.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java b/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java index fab50640..ca5e31ae 100644 --- a/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java +++ b/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/graphql/annotations/builders/InterfaceBuilder.java b/src/main/java/graphql/annotations/builders/InterfaceBuilder.java index 4dbe5f3e..b0a3aa5b 100644 --- a/src/main/java/graphql/annotations/builders/InterfaceBuilder.java +++ b/src/main/java/graphql/annotations/builders/InterfaceBuilder.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.builders; import graphql.annotations.*; diff --git a/src/main/java/graphql/annotations/typeFunctions/DefaultTypeFunction.java b/src/main/java/graphql/annotations/typeFunctions/DefaultTypeFunction.java index 6f0c4b4d..e2a9c4a1 100644 --- a/src/main/java/graphql/annotations/typeFunctions/DefaultTypeFunction.java +++ b/src/main/java/graphql/annotations/typeFunctions/DefaultTypeFunction.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/graphql/annotations/util/GraphQLObjectInfoRetriever.java b/src/main/java/graphql/annotations/util/GraphQLObjectInfoRetriever.java index a3c0d95b..53633785 100644 --- a/src/main/java/graphql/annotations/util/GraphQLObjectInfoRetriever.java +++ b/src/main/java/graphql/annotations/util/GraphQLObjectInfoRetriever.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/graphql/annotations/GraphQLExtensionsTest.java b/src/test/java/graphql/annotations/GraphQLExtensionsTest.java index efa7eaf9..19f4f6d3 100644 --- a/src/test/java/graphql/annotations/GraphQLExtensionsTest.java +++ b/src/test/java/graphql/annotations/GraphQLExtensionsTest.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/typeFunctions/BooleanFunctionTests.java b/src/test/java/typeFunctions/BooleanFunctionTests.java index 3f667c30..610d2087 100644 --- a/src/test/java/typeFunctions/BooleanFunctionTests.java +++ b/src/test/java/typeFunctions/BooleanFunctionTests.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java b/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java index 1a3bebd9..d61ac44f 100644 --- a/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java +++ b/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/typeFunctions/FloatFunctionTests.java b/src/test/java/typeFunctions/FloatFunctionTests.java index 460374b3..c91b1afe 100644 --- a/src/test/java/typeFunctions/FloatFunctionTests.java +++ b/src/test/java/typeFunctions/FloatFunctionTests.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/typeFunctions/IDFunctionTests.java b/src/test/java/typeFunctions/IDFunctionTests.java index 18a222f3..4ae8a413 100644 --- a/src/test/java/typeFunctions/IDFunctionTests.java +++ b/src/test/java/typeFunctions/IDFunctionTests.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/typeFunctions/IntegerFunctionTests.java b/src/test/java/typeFunctions/IntegerFunctionTests.java index 108425fa..cb167cde 100644 --- a/src/test/java/typeFunctions/IntegerFunctionTests.java +++ b/src/test/java/typeFunctions/IntegerFunctionTests.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/typeFunctions/LongFunctionTests.java b/src/test/java/typeFunctions/LongFunctionTests.java index e63f5cfd..c52a7aac 100644 --- a/src/test/java/typeFunctions/LongFunctionTests.java +++ b/src/test/java/typeFunctions/LongFunctionTests.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/typeFunctions/StringFunctionTests.java b/src/test/java/typeFunctions/StringFunctionTests.java index 0cbf3677..4f653ba7 100644 --- a/src/test/java/typeFunctions/StringFunctionTests.java +++ b/src/test/java/typeFunctions/StringFunctionTests.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. From de049de2a5f7ba40e6407753c47a26f02444877b Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 15:22:14 +0200 Subject: [PATCH 10/25] rename SearchAlgorithm function search to is found --- .../java/graphql/annotations/GraphQLFieldRetriever.java | 4 ++-- .../java/graphql/annotations/builders/ObjectBuilder.java | 4 ++-- .../annotations/searchAlgorithms/BreadthFirstSearch.java | 6 +++--- .../annotations/searchAlgorithms/ParentalSearch.java | 2 +- .../annotations/searchAlgorithms/SearchAlgorithm.java | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/graphql/annotations/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/GraphQLFieldRetriever.java index 7d82cfcd..1a269ddd 100644 --- a/src/main/java/graphql/annotations/GraphQLFieldRetriever.java +++ b/src/main/java/graphql/annotations/GraphQLFieldRetriever.java @@ -69,7 +69,7 @@ public List getExtensionFields(Class object, List getExtensionFields(Class object, List object, ProcessingEle if (method.isBridge() || method.isSynthetic()) { continue; } - if (breadthFirstSearch.search(method)) { + if (breadthFirstSearch.isFound(method)) { GraphQLFieldDefinition gqlField = graphQLFieldRetriever.getField(method,container); fieldsDefined.add(gqlField.getName()); builder.field(gqlField); @@ -74,7 +74,7 @@ public GraphQLObjectType.Builder getObjectBuilder(Class object, ProcessingEle if (Modifier.isStatic(field.getModifiers())) { continue; } - if (parentalSearch.search(field)) { + if (parentalSearch.isFound(field)) { GraphQLFieldDefinition gqlField = graphQLFieldRetriever.getField(field,container); fieldsDefined.add(gqlField.getName()); builder.field(gqlField); diff --git a/src/main/java/graphql/annotations/searchAlgorithms/BreadthFirstSearch.java b/src/main/java/graphql/annotations/searchAlgorithms/BreadthFirstSearch.java index 4a08a8ea..e0ab4a81 100644 --- a/src/main/java/graphql/annotations/searchAlgorithms/BreadthFirstSearch.java +++ b/src/main/java/graphql/annotations/searchAlgorithms/BreadthFirstSearch.java @@ -31,7 +31,7 @@ public BreadthFirstSearch(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever) } @Override - public boolean search(Member member) throws CannotCastMemberException { + public boolean isFound(Member member) throws CannotCastMemberException { Method method=CastToMethod(member); final List> queue = new LinkedList<>(); final String methodName = method.getName(); @@ -54,11 +54,11 @@ public boolean search(Member member) throws CannotCastMemberException { return gqf; } - // add interfaces to places to search + // add interfaces to places to isFound for (Class iface : cls.getInterfaces()) { queue.add(iface); } - // add parent class to places to search + // add parent class to places to isFound Class nxt = cls.getSuperclass(); if (nxt != null) { queue.add(nxt); diff --git a/src/main/java/graphql/annotations/searchAlgorithms/ParentalSearch.java b/src/main/java/graphql/annotations/searchAlgorithms/ParentalSearch.java index 9c4120e5..969bf2c6 100644 --- a/src/main/java/graphql/annotations/searchAlgorithms/ParentalSearch.java +++ b/src/main/java/graphql/annotations/searchAlgorithms/ParentalSearch.java @@ -28,7 +28,7 @@ public ParentalSearch(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever) { } @Override - public boolean search(Member member) throws CannotCastMemberException { + public boolean isFound(Member member) throws CannotCastMemberException { Field field=CastToField(member); Boolean gqf = graphQLObjectInfoRetriever.isGraphQLField(field); if (gqf != null) { diff --git a/src/main/java/graphql/annotations/searchAlgorithms/SearchAlgorithm.java b/src/main/java/graphql/annotations/searchAlgorithms/SearchAlgorithm.java index d57702d0..336f289c 100644 --- a/src/main/java/graphql/annotations/searchAlgorithms/SearchAlgorithm.java +++ b/src/main/java/graphql/annotations/searchAlgorithms/SearchAlgorithm.java @@ -17,5 +17,5 @@ import java.lang.reflect.Member; public interface SearchAlgorithm { - boolean search(Member member) throws CannotCastMemberException; + boolean isFound(Member member) throws CannotCastMemberException; } From 0ece9ef985fa8c45107328bcfd2a4f52658af498 Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 15:25:13 +0200 Subject: [PATCH 11/25] extract objectType to different method --- .../GraphQLInputObjectRetriever.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java b/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java index f0b139a5..19915e75 100644 --- a/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java +++ b/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java @@ -17,6 +17,7 @@ import graphql.schema.*; import graphql.schema.GraphQLNonNull; +import graphql.schema.GraphQLType; import java.util.Map; import java.util.stream.Collectors; @@ -25,29 +26,35 @@ public class GraphQLInputObjectRetriever { public GraphQLInputType getInputObject(graphql.schema.GraphQLType graphQLType, String newNamePrefix, Map typeRegistry) { if (graphQLType instanceof GraphQLObjectType) { - GraphQLObjectType object = (GraphQLObjectType) graphQLType; - if (typeRegistry.containsKey(newNamePrefix + object.getName()) && typeRegistry.get(newNamePrefix + object.getName()) instanceof GraphQLInputType) { - return (GraphQLInputType) typeRegistry.get(newNamePrefix + object.getName()); - } - GraphQLInputObjectType inputObjectType = new GraphQLInputObjectType(newNamePrefix + object.getName(), object.getDescription(), - object.getFieldDefinitions().stream(). - map(field -> { - GraphQLOutputType type = field.getType(); - GraphQLInputType inputType = getInputObject(type, newNamePrefix,typeRegistry); - return new GraphQLInputObjectField(field.getName(), field.getDescription(), inputType, null); - }). - collect(Collectors.toList())); - typeRegistry.put(inputObjectType.getName(), inputObjectType); - return inputObjectType; + return HandleGraphQLObjectType((GraphQLObjectType) graphQLType, newNamePrefix, typeRegistry); } else if (graphQLType instanceof GraphQLList) { return new GraphQLList(getInputObject(((GraphQLList)graphQLType).getWrappedType(), newNamePrefix,typeRegistry)); } else if (graphQLType instanceof graphql.schema.GraphQLNonNull) { return new graphql.schema.GraphQLNonNull(getInputObject(((GraphQLNonNull)graphQLType).getWrappedType(), newNamePrefix,typeRegistry)); } else if (graphQLType instanceof GraphQLTypeReference) { - return new GraphQLTypeReference(newNamePrefix + ((GraphQLTypeReference)graphQLType).getName()); + return new GraphQLTypeReference(newNamePrefix + (graphQLType).getName()); } else if (graphQLType instanceof GraphQLInputType){ return (GraphQLInputType) graphQLType; } throw new IllegalArgumentException("Cannot convert type to input : "+graphQLType); } + + private GraphQLInputType HandleGraphQLObjectType(GraphQLObjectType graphQLType, String newNamePrefix, Map typeRegistry) { + GraphQLObjectType object = graphQLType; + String newObjectName=newNamePrefix + object.getName(); + GraphQLType objectInTypeRegistry=typeRegistry.get(newObjectName); + if (objectInTypeRegistry !=null && objectInTypeRegistry instanceof GraphQLInputType) { + return (GraphQLInputType) objectInTypeRegistry; + } + GraphQLInputObjectType inputObjectType = new GraphQLInputObjectType(newObjectName, object.getDescription(), + object.getFieldDefinitions().stream(). + map(field -> { + GraphQLOutputType type = field.getType(); + GraphQLInputType inputType = getInputObject(type, newNamePrefix,typeRegistry); + return new GraphQLInputObjectField(field.getName(), field.getDescription(), inputType, null); + }). + collect(Collectors.toList())); + typeRegistry.put(inputObjectType.getName(), inputObjectType); + return inputObjectType; + } } From bee616fb43eaf6a0f2693e7cd5f6d4ef647a619d Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 15:27:04 +0200 Subject: [PATCH 12/25] moved type function tests to the right package --- .../annotations}/typeFunctions/BooleanFunctionTests.java | 5 ++--- .../annotations}/typeFunctions/DefaultTypeFunctionTest.java | 2 +- .../typeFunctions/DefaultTypeFunctionTestHelper.java | 3 +-- .../annotations}/typeFunctions/FloatFunctionTests.java | 5 ++--- .../annotations}/typeFunctions/IDFunctionTests.java | 5 ++--- .../annotations}/typeFunctions/IntegerFunctionTests.java | 5 ++--- .../annotations}/typeFunctions/LongFunctionTests.java | 5 ++--- .../annotations}/typeFunctions/StringFunctionTests.java | 5 ++--- 8 files changed, 14 insertions(+), 21 deletions(-) rename src/test/java/{ => graphql/annotations}/typeFunctions/BooleanFunctionTests.java (88%) rename src/test/java/{ => graphql/annotations}/typeFunctions/DefaultTypeFunctionTest.java (99%) rename src/test/java/{ => graphql/annotations}/typeFunctions/DefaultTypeFunctionTestHelper.java (93%) rename src/test/java/{ => graphql/annotations}/typeFunctions/FloatFunctionTests.java (89%) rename src/test/java/{ => graphql/annotations}/typeFunctions/IDFunctionTests.java (95%) rename src/test/java/{ => graphql/annotations}/typeFunctions/IntegerFunctionTests.java (87%) rename src/test/java/{ => graphql/annotations}/typeFunctions/LongFunctionTests.java (87%) rename src/test/java/{ => graphql/annotations}/typeFunctions/StringFunctionTests.java (87%) diff --git a/src/test/java/typeFunctions/BooleanFunctionTests.java b/src/test/java/graphql/annotations/typeFunctions/BooleanFunctionTests.java similarity index 88% rename from src/test/java/typeFunctions/BooleanFunctionTests.java rename to src/test/java/graphql/annotations/typeFunctions/BooleanFunctionTests.java index 610d2087..35356793 100644 --- a/src/test/java/typeFunctions/BooleanFunctionTests.java +++ b/src/test/java/graphql/annotations/typeFunctions/BooleanFunctionTests.java @@ -12,16 +12,15 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package typeFunctions; +package graphql.annotations.typeFunctions; import graphql.annotations.GraphQLAnnotations; -import graphql.annotations.typeFunctions.DefaultTypeFunction; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static graphql.Scalars.GraphQLBoolean; import static org.testng.Assert.assertEquals; -import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class BooleanFunctionTests { diff --git a/src/test/java/typeFunctions/DefaultTypeFunctionTest.java b/src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTest.java similarity index 99% rename from src/test/java/typeFunctions/DefaultTypeFunctionTest.java rename to src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTest.java index 3016dbf4..84666bf2 100644 --- a/src/test/java/typeFunctions/DefaultTypeFunctionTest.java +++ b/src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTest.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package typeFunctions; +package graphql.annotations.typeFunctions; import graphql.annotations.*; import graphql.schema.*; diff --git a/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java b/src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTestHelper.java similarity index 93% rename from src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java rename to src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTestHelper.java index d61ac44f..fc0f0d4b 100644 --- a/src/test/java/typeFunctions/DefaultTypeFunctionTestHelper.java +++ b/src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTestHelper.java @@ -12,12 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package typeFunctions; +package graphql.annotations.typeFunctions; import graphql.annotations.GraphQLAnnotations; import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; -import graphql.annotations.typeFunctions.DefaultTypeFunction; public class DefaultTypeFunctionTestHelper { public static DefaultTypeFunction testedDefaultTypeFunction() { diff --git a/src/test/java/typeFunctions/FloatFunctionTests.java b/src/test/java/graphql/annotations/typeFunctions/FloatFunctionTests.java similarity index 89% rename from src/test/java/typeFunctions/FloatFunctionTests.java rename to src/test/java/graphql/annotations/typeFunctions/FloatFunctionTests.java index c91b1afe..b0484686 100644 --- a/src/test/java/typeFunctions/FloatFunctionTests.java +++ b/src/test/java/graphql/annotations/typeFunctions/FloatFunctionTests.java @@ -12,16 +12,15 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package typeFunctions; +package graphql.annotations.typeFunctions; import graphql.annotations.GraphQLAnnotations; -import graphql.annotations.typeFunctions.DefaultTypeFunction; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static graphql.Scalars.GraphQLFloat; import static org.testng.Assert.assertEquals; -import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class FloatFunctionTests { diff --git a/src/test/java/typeFunctions/IDFunctionTests.java b/src/test/java/graphql/annotations/typeFunctions/IDFunctionTests.java similarity index 95% rename from src/test/java/typeFunctions/IDFunctionTests.java rename to src/test/java/graphql/annotations/typeFunctions/IDFunctionTests.java index 4ae8a413..255e3d10 100644 --- a/src/test/java/typeFunctions/IDFunctionTests.java +++ b/src/test/java/graphql/annotations/typeFunctions/IDFunctionTests.java @@ -12,11 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package typeFunctions; +package graphql.annotations.typeFunctions; import graphql.annotations.GraphQLAnnotations; import graphql.annotations.GraphQLID; -import graphql.annotations.typeFunctions.DefaultTypeFunction; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -25,7 +24,7 @@ import static graphql.Scalars.GraphQLID; import static org.testng.Assert.assertEquals; -import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class IDFunctionTests { diff --git a/src/test/java/typeFunctions/IntegerFunctionTests.java b/src/test/java/graphql/annotations/typeFunctions/IntegerFunctionTests.java similarity index 87% rename from src/test/java/typeFunctions/IntegerFunctionTests.java rename to src/test/java/graphql/annotations/typeFunctions/IntegerFunctionTests.java index cb167cde..f1b84338 100644 --- a/src/test/java/typeFunctions/IntegerFunctionTests.java +++ b/src/test/java/graphql/annotations/typeFunctions/IntegerFunctionTests.java @@ -12,16 +12,15 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package typeFunctions; +package graphql.annotations.typeFunctions; import graphql.annotations.GraphQLAnnotations; -import graphql.annotations.typeFunctions.DefaultTypeFunction; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static graphql.Scalars.GraphQLInt; import static org.testng.Assert.assertEquals; -import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class IntegerFunctionTests { diff --git a/src/test/java/typeFunctions/LongFunctionTests.java b/src/test/java/graphql/annotations/typeFunctions/LongFunctionTests.java similarity index 87% rename from src/test/java/typeFunctions/LongFunctionTests.java rename to src/test/java/graphql/annotations/typeFunctions/LongFunctionTests.java index c52a7aac..0da0be9c 100644 --- a/src/test/java/typeFunctions/LongFunctionTests.java +++ b/src/test/java/graphql/annotations/typeFunctions/LongFunctionTests.java @@ -12,17 +12,16 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package typeFunctions; +package graphql.annotations.typeFunctions; import graphql.annotations.GraphQLAnnotations; -import graphql.annotations.typeFunctions.DefaultTypeFunction; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static graphql.Scalars.GraphQLLong; import static org.testng.Assert.assertEquals; -import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class LongFunctionTests { diff --git a/src/test/java/typeFunctions/StringFunctionTests.java b/src/test/java/graphql/annotations/typeFunctions/StringFunctionTests.java similarity index 87% rename from src/test/java/typeFunctions/StringFunctionTests.java rename to src/test/java/graphql/annotations/typeFunctions/StringFunctionTests.java index 4f653ba7..1f2c3820 100644 --- a/src/test/java/typeFunctions/StringFunctionTests.java +++ b/src/test/java/graphql/annotations/typeFunctions/StringFunctionTests.java @@ -12,16 +12,15 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package typeFunctions; +package graphql.annotations.typeFunctions; import graphql.annotations.GraphQLAnnotations; -import graphql.annotations.typeFunctions.DefaultTypeFunction; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static graphql.Scalars.GraphQLString; import static org.testng.Assert.assertEquals; -import static typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class StringFunctionTests { From d924cdb1d1ae2edd2a25d1252c90ff626a0e0a29 Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 16:06:18 +0200 Subject: [PATCH 13/25] remove notes from graphQLAnnotationProcessor to other classes --- .../GraphQLAnnotationsProcessor.java | 112 ------------------ .../GraphQLInputObjectRetriever.java | 34 ++++-- .../GraphQLInterfaceRetriever.java | 28 +++-- .../annotations/builders/EnumBuilder.java | 15 ++- .../annotations/builders/ObjectBuilder.java | 15 ++- .../annotations/builders/UnionBuilder.java | 18 ++- .../GraphQLInputProcessor.java | 34 ++++-- .../GraphQLOutputProcessor.java | 20 +++- .../util/GraphQLOutputObjectRetriever.java | 26 ++-- 9 files changed, 133 insertions(+), 169 deletions(-) diff --git a/src/main/java/graphql/annotations/GraphQLAnnotationsProcessor.java b/src/main/java/graphql/annotations/GraphQLAnnotationsProcessor.java index 96ffe1e3..0e43f7fe 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotationsProcessor.java +++ b/src/main/java/graphql/annotations/GraphQLAnnotationsProcessor.java @@ -14,119 +14,7 @@ */ package graphql.annotations; -import graphql.schema.*; -import graphql.schema.GraphQLType; - public interface GraphQLAnnotationsProcessor { -// /** -// * @deprecated See {@link #getOutputType(Class)} -// */ -// graphql.schema.GraphQLType getInterface(Class iface) throws GraphQLAnnotationsException; -// -// /** -// * This will examine the class and return a {@link GraphQLUnionType.Builder} ready for further definition -// * -// * @param iface interface to examine -// * -// * @return a {@link GraphQLUnionType.Builder} -// * -// * @throws GraphQLAnnotationsException if the class cannot be examined -// * @throws IllegalArgumentException if iface is not an interface -// */ -// GraphQLUnionType.Builder getUnionBuilder(Class iface) throws GraphQLAnnotationsException, IllegalArgumentException; -// -// /** -// * This will examine the class and return a {@link GraphQLInterfaceType.Builder} ready for further definition -// * -// * @param iface interface to examine -// * -// * @return a {@link GraphQLInterfaceType.Builder} -// * -// * @throws GraphQLAnnotationsException if the class cannot be examined -// * @throws IllegalArgumentException if iface is not an interface -// */ -// GraphQLInterfaceType.Builder getIfaceBuilder(Class iface) throws GraphQLAnnotationsException, IllegalArgumentException; -// -// /** -// * This will examine the object class and return a {@link GraphQLEnumType.Builder} ready for further definition -// * -// * @param object the object class to examine -// * -// * @return a {@link GraphQLEnumType.Builder} that represents that object class -// * -// * @throws GraphQLAnnotationsException if the object class cannot be examined -// */ -// GraphQLEnumType.Builder getEnumBuilder(Class object) throws GraphQLAnnotationsException; -// -// /** -// * @deprecated See {@link #getOutputType(Class)} -// */ -// GraphQLObjectType getObject(Class object) throws GraphQLAnnotationsException; -// -// /** -// * This will examine the object and will return a {@link GraphQLOutputType} based on the class type and annotations. -// * - If its annotated with {@link GraphQLUnion} it will return a {@link GraphQLUnionType} -// * - If its annotated with {@link GraphQLTypeResolver} it will return a {@link GraphQLInterfaceType} -// * - It it's an Enum it will return a {@link GraphQLEnumType}, -// * otherwise it will return a {@link GraphQLObjectType}. -// * -// * @param object the object class to examine -// * -// * @return a {@link GraphQLOutputType} that represents that object class -// * -// * @throws GraphQLAnnotationsException if the object class cannot be examined -// */ -// GraphQLOutputType getOutputType(Class object) throws GraphQLAnnotationsException; -// -// /** -// * @deprecated See {@link #getOutputTypeOrRef(Class)} -// */ -// GraphQLOutputType getObjectOrRef(Class object) throws GraphQLAnnotationsException; -// -// /** -// * This will examine the object class and return a {@link GraphQLOutputType} representation -// * which may be a {@link GraphQLOutputType} or a {@link graphql.schema.GraphQLTypeReference} -// * -// * @param object the object class to examine -// * -// * @return a {@link GraphQLOutputType} that represents that object class -// * -// * @throws GraphQLAnnotationsException if the object class cannot be examined -// */ -// GraphQLOutputType getOutputTypeOrRef(Class object) throws GraphQLAnnotationsException; -// -// /** -// * This will examine the object class and return a {@link GraphQLObjectType.Builder} ready for further definition -// * -// * @param object the object class to examine -// * -// * @return a {@link GraphQLObjectType.Builder} that represents that object class -// * -// * @throws GraphQLAnnotationsException if the object class cannot be examined -// */ -// GraphQLObjectType.Builder getObjectBuilder(Class object) throws GraphQLAnnotationsException; -// -// /** -// * This will examine the object class and return a {@link GraphQLInputType} representation -// * -// * @param object the object class to examine -// * -// * @return a {@link GraphQLInputType} that represents that object class -// * -// * @throws GraphQLAnnotationsException if the object class cannot be examined -// */ -// GraphQLInputObjectType getInputObject(Class object) throws GraphQLAnnotationsException; -// -// /** -// * This will turn a {@link GraphQLObjectType} into a corresponding {@link GraphQLInputObjectType} -// * -// * @param graphQLType the graphql object type -// * @param newNamePrefix since graphql types MUST be unique, this prefix will be applied to the new input types -// * -// * @return a {@link GraphQLInputObjectType} -// */ -// GraphQLInputType getInputObject(GraphQLType graphQLType, String newNamePrefix); - /** * Register a new type extension class. This extension will be used when the extended object will be created. * The class must have a {@link GraphQLTypeExtension} annotation. diff --git a/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java b/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java index 19915e75..aa92b044 100644 --- a/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java +++ b/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,33 +24,43 @@ public class GraphQLInputObjectRetriever { + + /** + * This will turn a {@link GraphQLObjectType} into a corresponding {@link GraphQLInputObjectType} + * + * @param graphQLType the graphql object type + * @param newNamePrefix since graphql types MUST be unique, this prefix will be applied to the new input types + * @param typeRegistry object thata saves all the types + * @return a {@link GraphQLInputObjectType} + */ + public GraphQLInputType getInputObject(graphql.schema.GraphQLType graphQLType, String newNamePrefix, Map typeRegistry) { if (graphQLType instanceof GraphQLObjectType) { return HandleGraphQLObjectType((GraphQLObjectType) graphQLType, newNamePrefix, typeRegistry); } else if (graphQLType instanceof GraphQLList) { - return new GraphQLList(getInputObject(((GraphQLList)graphQLType).getWrappedType(), newNamePrefix,typeRegistry)); + return new GraphQLList(getInputObject(((GraphQLList) graphQLType).getWrappedType(), newNamePrefix, typeRegistry)); } else if (graphQLType instanceof graphql.schema.GraphQLNonNull) { - return new graphql.schema.GraphQLNonNull(getInputObject(((GraphQLNonNull)graphQLType).getWrappedType(), newNamePrefix,typeRegistry)); + return new graphql.schema.GraphQLNonNull(getInputObject(((GraphQLNonNull) graphQLType).getWrappedType(), newNamePrefix, typeRegistry)); } else if (graphQLType instanceof GraphQLTypeReference) { return new GraphQLTypeReference(newNamePrefix + (graphQLType).getName()); - } else if (graphQLType instanceof GraphQLInputType){ + } else if (graphQLType instanceof GraphQLInputType) { return (GraphQLInputType) graphQLType; } - throw new IllegalArgumentException("Cannot convert type to input : "+graphQLType); + throw new IllegalArgumentException("Cannot convert type to input : " + graphQLType); } private GraphQLInputType HandleGraphQLObjectType(GraphQLObjectType graphQLType, String newNamePrefix, Map typeRegistry) { GraphQLObjectType object = graphQLType; - String newObjectName=newNamePrefix + object.getName(); - GraphQLType objectInTypeRegistry=typeRegistry.get(newObjectName); - if (objectInTypeRegistry !=null && objectInTypeRegistry instanceof GraphQLInputType) { + String newObjectName = newNamePrefix + object.getName(); + GraphQLType objectInTypeRegistry = typeRegistry.get(newObjectName); + if (objectInTypeRegistry != null && objectInTypeRegistry instanceof GraphQLInputType) { return (GraphQLInputType) objectInTypeRegistry; } GraphQLInputObjectType inputObjectType = new GraphQLInputObjectType(newObjectName, object.getDescription(), object.getFieldDefinitions().stream(). map(field -> { GraphQLOutputType type = field.getType(); - GraphQLInputType inputType = getInputObject(type, newNamePrefix,typeRegistry); + GraphQLInputType inputType = getInputObject(type, newNamePrefix, typeRegistry); return new GraphQLInputObjectField(field.getName(), field.getDescription(), inputType, null); }). collect(Collectors.toList())); diff --git a/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java b/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java index ca5e31ae..7f54ad19 100644 --- a/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java +++ b/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,19 +15,29 @@ package graphql.annotations; import graphql.annotations.util.GraphQLOutputObjectRetriever; +import graphql.schema.GraphQLUnionType; public class GraphQLInterfaceRetriever { - private GraphQLOutputObjectRetriever graphQLOutputObjectRetriever; + private GraphQLOutputObjectRetriever graphQLOutputObjectRetriever; - public GraphQLInterfaceRetriever(GraphQLOutputObjectRetriever graphQLOutputObjectRetriever){ - this.graphQLOutputObjectRetriever=graphQLOutputObjectRetriever; + public GraphQLInterfaceRetriever(GraphQLOutputObjectRetriever graphQLOutputObjectRetriever) { + this.graphQLOutputObjectRetriever = graphQLOutputObjectRetriever; } - public GraphQLInterfaceRetriever(){ + public GraphQLInterfaceRetriever() { this(new GraphQLOutputObjectRetriever()); } + + /** + * This will examine the class and return a {@link graphql.schema.GraphQLOutputType} ready for further definition + * + * @param iface interface to examine + * @param container a class that hold several members that are required in order to build schema + * @return a {@link graphql.schema.GraphQLOutputType} + * @throws GraphQLAnnotationsException if the class cannot be examined + */ public graphql.schema.GraphQLOutputType getInterface(Class iface, ProcessingElementsContainer container) throws GraphQLAnnotationsException { - return graphQLOutputObjectRetriever.getOutputType(iface,container); + return graphQLOutputObjectRetriever.getOutputType(iface, container); } } diff --git a/src/main/java/graphql/annotations/builders/EnumBuilder.java b/src/main/java/graphql/annotations/builders/EnumBuilder.java index 89073de5..86dd768a 100644 --- a/src/main/java/graphql/annotations/builders/EnumBuilder.java +++ b/src/main/java/graphql/annotations/builders/EnumBuilder.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -33,6 +33,13 @@ public EnumBuilder(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever) { this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; } + /** + * This will examine the object class and return a {@link GraphQLEnumType.Builder} ready for further definition + * + * @param aClass the object class to examine + * @return a {@link GraphQLEnumType.Builder} that represents that object class + */ + public GraphQLEnumType.Builder getEnumBuilder(Class aClass) { String typeName = graphQLObjectInfoRetriever.getTypeName(aClass); //noinspection unchecked diff --git a/src/main/java/graphql/annotations/builders/ObjectBuilder.java b/src/main/java/graphql/annotations/builders/ObjectBuilder.java index cacbebd4..455d5eb1 100644 --- a/src/main/java/graphql/annotations/builders/ObjectBuilder.java +++ b/src/main/java/graphql/annotations/builders/ObjectBuilder.java @@ -39,19 +39,26 @@ public class ObjectBuilder { private BreadthFirstSearch breadthFirstSearch; private ParentalSearch parentalSearch; private GraphQLFieldRetriever graphQLFieldRetriever; - private InterfaceBuilder interfaceBuilder; private GraphQLInterfaceRetriever graphQLInterfaceRetriever; - public ObjectBuilder(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, ParentalSearch parentalSearch, BreadthFirstSearch breadthFirstSearch,GraphQLFieldRetriever graphQLFieldRetriever,InterfaceBuilder interfaceBuilder,GraphQLInterfaceRetriever graphQLInterfaceRetriever) { + public ObjectBuilder(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, ParentalSearch parentalSearch, BreadthFirstSearch breadthFirstSearch,GraphQLFieldRetriever graphQLFieldRetriever,GraphQLInterfaceRetriever graphQLInterfaceRetriever) { this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; this.breadthFirstSearch=breadthFirstSearch; this.parentalSearch=parentalSearch; this.graphQLFieldRetriever=graphQLFieldRetriever; - this.interfaceBuilder=interfaceBuilder; this.graphQLInterfaceRetriever=graphQLInterfaceRetriever; } - public GraphQLObjectType.Builder getObjectBuilder(Class object, ProcessingElementsContainer container, GraphQLOutputObjectRetriever outputObjectRetriever) throws GraphQLAnnotationsException { + /** + * This will examine the object class and return a {@link GraphQLObjectType.Builder} ready for further definition + * + * @param object the object class to examine + * @param container a class that hold several members that are required in order to build schema + * @return a {@link GraphQLObjectType.Builder} that represents that object class + * @throws GraphQLAnnotationsException if the object class cannot be examined + */ + + public GraphQLObjectType.Builder getObjectBuilder(Class object, ProcessingElementsContainer container) throws GraphQLAnnotationsException { GraphQLObjectType.Builder builder = newObject(); builder.name(graphQLObjectInfoRetriever.getTypeName(object)); GraphQLDescription description = object.getAnnotation(GraphQLDescription.class); diff --git a/src/main/java/graphql/annotations/builders/UnionBuilder.java b/src/main/java/graphql/annotations/builders/UnionBuilder.java index dd36e57f..64e7b915 100644 --- a/src/main/java/graphql/annotations/builders/UnionBuilder.java +++ b/src/main/java/graphql/annotations/builders/UnionBuilder.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -33,6 +33,14 @@ public UnionBuilder(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever) { this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; } + /** + * This will examine the class and return a {@link GraphQLUnionType.Builder} ready for further definition + * @param container a class that hold several members that are required in order to build schema + * @param iface interface to examine + * @return a {@link GraphQLUnionType.Builder} + * @throws GraphQLAnnotationsException if the class cannot be examined + */ + public GraphQLUnionType.Builder getUnionBuilder(Class iface, ProcessingElementsContainer container) throws GraphQLAnnotationsException, IllegalArgumentException { if (!iface.isInterface()) { throw new IllegalArgumentException(iface + " is not an interface"); @@ -58,7 +66,7 @@ public GraphQLUnionType.Builder getUnionBuilder(Class iface, ProcessingElemen .map(new Function, graphql.schema.GraphQLType>() { @Override public graphql.schema.GraphQLType apply(Class aClass) { - return finalTypeFunction.buildType(aClass, null,container); + return finalTypeFunction.buildType(aClass, null, container); } }) .map(v -> (GraphQLObjectType) v) diff --git a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java index 7f989b63..0166efeb 100644 --- a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java +++ b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,6 +20,7 @@ import graphql.annotations.ProcessingElementsContainer; import graphql.annotations.util.GraphQLObjectInfoRetriever; import graphql.schema.GraphQLInputObjectType; +import graphql.schema.GraphQLInputType; import graphql.schema.GraphQLType; import java.util.Map; @@ -32,15 +33,24 @@ public class GraphQLInputProcessor { private GraphQLObjectHandler graphQLObjectHandler; private GraphQLInputObjectRetriever graphQLInputObjectRetriever; - public GraphQLInputProcessor(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever,GraphQLObjectHandler graphQLObjectHandler,GraphQLInputObjectRetriever graphQLInputObjectRetriever){ - this.graphQLObjectInfoRetriever=graphQLObjectInfoRetriever; - this.graphQLObjectHandler=graphQLObjectHandler; - this.graphQLInputObjectRetriever=graphQLInputObjectRetriever; + public GraphQLInputProcessor(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLObjectHandler graphQLObjectHandler, GraphQLInputObjectRetriever graphQLInputObjectRetriever) { + this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; + this.graphQLObjectHandler = graphQLObjectHandler; + this.graphQLInputObjectRetriever = graphQLInputObjectRetriever; } - public GraphQLInputProcessor(){ - this(new GraphQLObjectInfoRetriever(), new GraphQLObjectHandler(),new GraphQLInputObjectRetriever()); + public GraphQLInputProcessor() { + this(new GraphQLObjectInfoRetriever(), new GraphQLObjectHandler(), new GraphQLInputObjectRetriever()); } + + /** + * This will examine the object class and return a {@link GraphQLInputType} representation + * + * @param object the object class to examine + * @param container a class that hold several members that are required in order to build schema + * @return a {@link GraphQLInputType} that represents that object class + */ + public GraphQLInputObjectType getInputObject(Class object, ProcessingElementsContainer container) { String typeName = DEFAULT_INPUT_PREFIX + graphQLObjectInfoRetriever.getTypeName(object); Map typeRegistry = container.getTypeRegistry(); @@ -48,8 +58,8 @@ public GraphQLInputObjectType getInputObject(Class object, ProcessingElements if (typeRegistry.containsKey(typeName)) { return (GraphQLInputObjectType) container.getTypeRegistry().get(typeName); } else { - graphql.schema.GraphQLType graphQLType = graphQLObjectHandler.getObject(object,container); - GraphQLInputObjectType inputObject = (GraphQLInputObjectType) graphQLInputObjectRetriever.getInputObject(graphQLType, DEFAULT_INPUT_PREFIX,typeRegistry); + graphql.schema.GraphQLType graphQLType = graphQLObjectHandler.getObject(object, container); + GraphQLInputObjectType inputObject = (GraphQLInputObjectType) graphQLInputObjectRetriever.getInputObject(graphQLType, DEFAULT_INPUT_PREFIX, typeRegistry); typeRegistry.put(inputObject.getName(), inputObject); return inputObject; } diff --git a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java index 98efb7d5..2e84322e 100644 --- a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java +++ b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -37,6 +37,18 @@ public GraphQLOutputProcessor() { this(new GraphQLObjectInfoRetriever(), new GraphQLOutputObjectRetriever()); } + /** + * This will examine the object class and return a {@link GraphQLOutputType} representation + * which may be a {@link GraphQLOutputType} or a {@link graphql.schema.GraphQLTypeReference} + * + * @param object the object class to examine + * @param container a class that hold several members that are required in order to build schema + + * @return a {@link GraphQLOutputType} that represents that object class + * + * @throws GraphQLAnnotationsException if the object class cannot be examined + */ + public GraphQLOutputType getOutputTypeOrRef(Class object, ProcessingElementsContainer container) throws GraphQLAnnotationsException { String typeName = graphQLObjectInfoRetriever.getTypeName(object); if (container.getProcessing().contains(typeName)) { diff --git a/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java b/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java index 0a2c958a..2f6db247 100644 --- a/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java +++ b/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,7 +22,7 @@ import graphql.annotations.searchAlgorithms.BreadthFirstSearch; import graphql.annotations.searchAlgorithms.CannotCastMemberException; import graphql.annotations.searchAlgorithms.ParentalSearch; -import graphql.schema.GraphQLOutputType; +import graphql.schema.*; public class GraphQLOutputObjectRetriever { @@ -38,6 +38,19 @@ public GraphQLOutputObjectRetriever() { this(new GraphQLObjectInfoRetriever(), new GraphQLFieldRetriever()); } + /** + * This will examine the object and will return a {@link GraphQLOutputType} based on the class type and annotations. + * - If its annotated with {@link GraphQLUnion} it will return a {@link GraphQLUnionType} + * - If its annotated with {@link GraphQLTypeResolver} it will return a {@link GraphQLInterfaceType} + * - It it's an Enum it will return a {@link GraphQLEnumType}, + * otherwise it will return a {@link GraphQLObjectType}. + * + * @param object the object class to examine* + * @param container a class that hold several members that are required in order to build schema + * @return a {@link GraphQLOutputType} that represents that object class + * @throws GraphQLAnnotationsException if the object class cannot be examined + * @throws CannotCastMemberException if the object class cannot be examined + */ public GraphQLOutputType getOutputType(Class object, ProcessingElementsContainer container) throws GraphQLAnnotationsException, CannotCastMemberException { // because the TypeFunction can call back to this processor and // Java classes can be circular, we need to protect against @@ -58,8 +71,7 @@ public GraphQLOutputType getOutputType(Class object, ProcessingElementsContai } else if (Enum.class.isAssignableFrom(object)) { type = new EnumBuilder(graphQLObjectInfoRetriever).getEnumBuilder(object).build(); } else { - InterfaceBuilder interfaceBuilder = new InterfaceBuilder(graphQLObjectInfoRetriever, graphQLFieldRetriever); - type = new ObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), new BreadthFirstSearch(graphQLObjectInfoRetriever), graphQLFieldRetriever, interfaceBuilder,new GraphQLInterfaceRetriever()).getObjectBuilder(object, container, this).build(); + type = new ObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), new BreadthFirstSearch(graphQLObjectInfoRetriever), graphQLFieldRetriever, new GraphQLInterfaceRetriever()).getObjectBuilder(object, container).build(); } container.getTypeRegistry().put(typeName, type); From 156d8add327953630a5416a55c598bbca2ce6fed Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 16:13:02 +0200 Subject: [PATCH 14/25] fix license --- .../graphql/annotations/GraphQLInputObjectRetriever.java | 8 ++++---- .../graphql/annotations/GraphQLInterfaceRetriever.java | 8 ++++---- .../java/graphql/annotations/builders/EnumBuilder.java | 8 ++++---- .../java/graphql/annotations/builders/UnionBuilder.java | 8 ++++---- .../graphQLProcessors/GraphQLInputProcessor.java | 8 ++++---- .../graphQLProcessors/GraphQLOutputProcessor.java | 8 ++++---- .../annotations/util/GraphQLOutputObjectRetriever.java | 8 ++++---- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java b/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java index aa92b044..a299bb41 100644 --- a/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java +++ b/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java b/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java index 7f54ad19..bf842b53 100644 --- a/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java +++ b/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/graphql/annotations/builders/EnumBuilder.java b/src/main/java/graphql/annotations/builders/EnumBuilder.java index 86dd768a..52a3ee0f 100644 --- a/src/main/java/graphql/annotations/builders/EnumBuilder.java +++ b/src/main/java/graphql/annotations/builders/EnumBuilder.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/graphql/annotations/builders/UnionBuilder.java b/src/main/java/graphql/annotations/builders/UnionBuilder.java index 64e7b915..83998b47 100644 --- a/src/main/java/graphql/annotations/builders/UnionBuilder.java +++ b/src/main/java/graphql/annotations/builders/UnionBuilder.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java index 0166efeb..af9b0a28 100644 --- a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java +++ b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java index 2e84322e..443c845e 100644 --- a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java +++ b/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java b/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java index 2f6db247..984a4898 100644 --- a/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java +++ b/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. From 8811adf327807e001e7640509529d340c05a2e58 Mon Sep 17 00:00:00 2001 From: yarinvak Date: Wed, 1 Nov 2017 16:15:19 +0200 Subject: [PATCH 15/25] organize classes in directories --- .../{ => annotations}/GraphQLBatched.java | 2 +- .../{ => annotations}/GraphQLConnection.java | 5 ++- .../{ => annotations}/GraphQLDataFetcher.java | 2 +- .../GraphQLDefaultValue.java | 2 +- .../{ => annotations}/GraphQLDeprecate.java | 2 +- .../{ => annotations}/GraphQLDescription.java | 2 +- .../{ => annotations}/GraphQLField.java | 2 +- .../{ => annotations}/GraphQLID.java | 2 +- .../GraphQLInvokeDetached.java | 2 +- .../{ => annotations}/GraphQLMutation.java | 2 +- .../{ => annotations}/GraphQLName.java | 2 +- .../{ => annotations}/GraphQLNonNull.java | 2 +- .../GraphQLRelayMutation.java | 2 +- .../{ => annotations}/GraphQLType.java | 5 +-- .../GraphQLTypeExtension.java | 2 +- .../GraphQLTypeResolver.java | 2 +- .../{ => annotations}/GraphQLUnion.java | 2 +- .../BatchedMethodDataFetcher.java | 6 ++-- .../ExtensionDataFetcherWrapper.java | 4 +-- .../{ => dataFetchers}/MethodDataFetcher.java | 14 +++++--- .../RelayMutationMethodDataFetcher.java | 2 +- .../connection}/Connection.java | 2 +- .../connection}/ConnectionDataFetcher.java | 6 ++-- .../connection}/DispatchingConnection.java | 2 +- .../connection}/ListConnection.java | 2 +- .../connection}/StreamConnection.java | 6 ++-- .../{ => processor}/GraphQLAnnotations.java | 20 +++++++---- .../ProcessingElementsContainer.java | 9 ++--- .../GraphQLAnnotationsException.java | 2 +- .../GraphQLAnnotationsProcessor.java | 5 ++- .../GraphQLInputProcessor.java | 10 +++--- .../GraphQLOutputProcessor.java | 10 +++--- .../retrievers}/GraphQLFieldRetriever.java | 34 ++++++++++++------- .../GraphQLInputObjectRetriever.java | 2 +- .../GraphQLInterfaceRetriever.java | 5 +-- .../retrievers}/GraphQLObjectHandler.java | 7 ++-- .../GraphQLObjectInfoRetriever.java | 8 ++--- .../GraphQLOutputObjectRetriever.java | 21 +++++++----- .../searchAlgorithms/BreadthFirstSearch.java | 4 +-- .../CannotCastMemberException.java | 2 +- .../searchAlgorithms/ParentalSearch.java | 4 +-- .../searchAlgorithms/SearchAlgorithm.java | 2 +- .../typeBuilders}/EnumBuilder.java | 8 ++--- .../typeBuilders}/InterfaceBuilder.java | 15 +++++--- .../typeBuilders}/ObjectBuilder.java | 19 +++++++---- .../typeBuilders}/UnionBuilder.java | 15 +++++--- .../typeFunctions/BatchedTypeFunction.java | 5 ++- .../typeFunctions/BooleanFunction.java | 5 ++- .../typeFunctions/DefaultTypeFunction.java | 15 ++++---- .../typeFunctions/FloatFunction.java | 5 ++- .../typeFunctions/IDFunction.java | 7 ++-- .../typeFunctions/IntegerFunction.java | 5 ++- .../typeFunctions/IterableFunction.java | 5 ++- .../typeFunctions/LongFunction.java | 5 ++- .../typeFunctions/ObjectFunction.java | 13 ++++--- .../typeFunctions/OptionalFunction.java | 5 ++- .../typeFunctions/StreamFunction.java | 5 ++- .../typeFunctions/StringFunction.java | 5 ++- .../typeFunctions}/TypeFunction.java | 4 +-- .../{ => processor}/util/Base64.java | 2 +- .../{ => processor}/util/NamingKit.java | 2 +- .../{ => processor}/util/ObjectUtil.java | 2 +- .../{ => processor/util}/ReflectionKit.java | 4 ++- .../{ => processor}/util/RelayKit.java | 2 +- .../EnhancedExecutionStrategy.java | 2 +- .../UnionTypeResolver.java | 3 +- .../annotations/GraphQLBatchedTest.java | 4 ++- .../annotations/GraphQLConnectionTest.java | 11 ++++-- .../annotations/GraphQLDataFetcherTest.java | 4 +++ .../graphql/annotations/GraphQLEnumTest.java | 9 ++--- .../annotations/GraphQLExtensionsTest.java | 7 ++-- .../annotations/GraphQLFragmentTest.java | 4 +++ .../graphql/annotations/GraphQLInputTest.java | 5 +++ .../annotations/GraphQLInterfaceTest.java | 7 ++++ .../annotations/GraphQLObjectTest.java | 9 ++++- .../annotations/GraphQLSimpleSchemaTest.java | 4 +++ .../annotations/MethodDataFetcherTest.java | 2 ++ .../java/graphql/annotations/RelayTest.java | 3 ++ .../typeFunctions/BooleanFunctionTests.java | 6 ++-- .../DefaultTypeFunctionTest.java | 25 ++++++++------ .../DefaultTypeFunctionTestHelper.java | 8 ++--- .../typeFunctions/FloatFunctionTests.java | 6 ++-- .../typeFunctions/IDFunctionTests.java | 10 +++--- .../typeFunctions/IntegerFunctionTests.java | 6 ++-- .../typeFunctions/LongFunctionTests.java | 6 ++-- .../typeFunctions/StringFunctionTests.java | 6 ++-- .../{ => processor}/util/CustomRelay.java | 2 +- .../{ => processor}/util/NamingKitTest.java | 2 +- 88 files changed, 306 insertions(+), 227 deletions(-) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLBatched.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLConnection.java (90%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLDataFetcher.java (96%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLDefaultValue.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLDeprecate.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLDescription.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLField.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLID.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLInvokeDetached.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLMutation.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLName.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLNonNull.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLRelayMutation.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLType.java (84%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLTypeExtension.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLTypeResolver.java (95%) rename src/main/java/graphql/annotations/{ => annotations}/GraphQLUnion.java (95%) rename src/main/java/graphql/annotations/{ => dataFetchers}/BatchedMethodDataFetcher.java (79%) rename src/main/java/graphql/annotations/{ => dataFetchers}/ExtensionDataFetcherWrapper.java (94%) rename src/main/java/graphql/annotations/{ => dataFetchers}/MethodDataFetcher.java (89%) rename src/main/java/graphql/annotations/{ => dataFetchers}/RelayMutationMethodDataFetcher.java (98%) rename src/main/java/graphql/annotations/{ => dataFetchers/connection}/Connection.java (92%) rename src/main/java/graphql/annotations/{ => dataFetchers/connection}/ConnectionDataFetcher.java (93%) rename src/main/java/graphql/annotations/{ => dataFetchers/connection}/DispatchingConnection.java (96%) rename src/main/java/graphql/annotations/{ => dataFetchers/connection}/ListConnection.java (93%) rename src/main/java/graphql/annotations/{ => dataFetchers/connection}/StreamConnection.java (95%) rename src/main/java/graphql/annotations/{ => processor}/GraphQLAnnotations.java (86%) rename src/main/java/graphql/annotations/{ => processor}/ProcessingElementsContainer.java (88%) rename src/main/java/graphql/annotations/{ => processor/exceptions}/GraphQLAnnotationsException.java (94%) rename src/main/java/graphql/annotations/{ => processor/graphQLProcessors}/GraphQLAnnotationsProcessor.java (98%) rename src/main/java/graphql/annotations/{ => processor}/graphQLProcessors/GraphQLInputProcessor.java (87%) rename src/main/java/graphql/annotations/{ => processor}/graphQLProcessors/GraphQLOutputProcessor.java (82%) rename src/main/java/graphql/annotations/{ => processor/retrievers}/GraphQLFieldRetriever.java (92%) rename src/main/java/graphql/annotations/{ => processor/retrievers}/GraphQLInputObjectRetriever.java (98%) rename src/main/java/graphql/annotations/{ => processor/retrievers}/GraphQLInterfaceRetriever.java (86%) rename src/main/java/graphql/annotations/{ => processor/retrievers}/GraphQLObjectHandler.java (84%) rename src/main/java/graphql/annotations/{util => processor/retrievers}/GraphQLObjectInfoRetriever.java (86%) rename src/main/java/graphql/annotations/{util => processor/retrievers}/GraphQLOutputObjectRetriever.java (79%) rename src/main/java/graphql/annotations/{ => processor}/searchAlgorithms/BreadthFirstSearch.java (95%) rename src/main/java/graphql/annotations/{ => processor}/searchAlgorithms/CannotCastMemberException.java (94%) rename src/main/java/graphql/annotations/{ => processor}/searchAlgorithms/ParentalSearch.java (93%) rename src/main/java/graphql/annotations/{ => processor}/searchAlgorithms/SearchAlgorithm.java (92%) rename src/main/java/graphql/annotations/{builders => processor/typeBuilders}/EnumBuilder.java (90%) rename src/main/java/graphql/annotations/{builders => processor/typeBuilders}/InterfaceBuilder.java (83%) rename src/main/java/graphql/annotations/{builders => processor/typeBuilders}/ObjectBuilder.java (83%) rename src/main/java/graphql/annotations/{builders => processor/typeBuilders}/UnionBuilder.java (78%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/BatchedTypeFunction.java (94%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/BooleanFunction.java (90%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/DefaultTypeFunction.java (90%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/FloatFunction.java (91%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/IDFunction.java (89%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/IntegerFunction.java (90%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/IterableFunction.java (93%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/LongFunction.java (90%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/ObjectFunction.java (81%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/OptionalFunction.java (94%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/StreamFunction.java (93%) rename src/main/java/graphql/annotations/{ => processor}/typeFunctions/StringFunction.java (90%) rename src/main/java/graphql/annotations/{ => processor/typeFunctions}/TypeFunction.java (95%) rename src/main/java/graphql/annotations/{ => processor}/util/Base64.java (96%) rename src/main/java/graphql/annotations/{ => processor}/util/NamingKit.java (98%) rename src/main/java/graphql/annotations/{ => processor}/util/ObjectUtil.java (96%) rename src/main/java/graphql/annotations/{ => processor/util}/ReflectionKit.java (95%) rename src/main/java/graphql/annotations/{ => processor}/util/RelayKit.java (96%) rename src/main/java/graphql/annotations/{ => strategies}/EnhancedExecutionStrategy.java (99%) rename src/main/java/graphql/annotations/{ => typeResolvers}/UnionTypeResolver.java (93%) rename src/test/java/graphql/annotations/{ => processor}/typeFunctions/BooleanFunctionTests.java (84%) rename src/test/java/graphql/annotations/{ => processor}/typeFunctions/DefaultTypeFunctionTest.java (88%) rename src/test/java/graphql/annotations/{ => processor}/typeFunctions/DefaultTypeFunctionTestHelper.java (79%) rename src/test/java/graphql/annotations/{ => processor}/typeFunctions/FloatFunctionTests.java (85%) rename src/test/java/graphql/annotations/{ => processor}/typeFunctions/IDFunctionTests.java (91%) rename src/test/java/graphql/annotations/{ => processor}/typeFunctions/IntegerFunctionTests.java (84%) rename src/test/java/graphql/annotations/{ => processor}/typeFunctions/LongFunctionTests.java (84%) rename src/test/java/graphql/annotations/{ => processor}/typeFunctions/StringFunctionTests.java (83%) rename src/test/java/graphql/annotations/{ => processor}/util/CustomRelay.java (98%) rename src/test/java/graphql/annotations/{ => processor}/util/NamingKitTest.java (97%) diff --git a/src/main/java/graphql/annotations/GraphQLBatched.java b/src/main/java/graphql/annotations/annotations/GraphQLBatched.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLBatched.java rename to src/main/java/graphql/annotations/annotations/GraphQLBatched.java index 89b32598..a04684e8 100644 --- a/src/main/java/graphql/annotations/GraphQLBatched.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLBatched.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLConnection.java b/src/main/java/graphql/annotations/annotations/GraphQLConnection.java similarity index 90% rename from src/main/java/graphql/annotations/GraphQLConnection.java rename to src/main/java/graphql/annotations/annotations/GraphQLConnection.java index ec4969d1..b5af444b 100644 --- a/src/main/java/graphql/annotations/GraphQLConnection.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLConnection.java @@ -12,7 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; + +import graphql.annotations.dataFetchers.connection.Connection; +import graphql.annotations.dataFetchers.connection.DispatchingConnection; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLDataFetcher.java b/src/main/java/graphql/annotations/annotations/GraphQLDataFetcher.java similarity index 96% rename from src/main/java/graphql/annotations/GraphQLDataFetcher.java rename to src/main/java/graphql/annotations/annotations/GraphQLDataFetcher.java index 3b95fc12..98830d7d 100644 --- a/src/main/java/graphql/annotations/GraphQLDataFetcher.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLDataFetcher.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import graphql.schema.DataFetcher; diff --git a/src/main/java/graphql/annotations/GraphQLDefaultValue.java b/src/main/java/graphql/annotations/annotations/GraphQLDefaultValue.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLDefaultValue.java rename to src/main/java/graphql/annotations/annotations/GraphQLDefaultValue.java index a3d9d13f..a16c03b5 100644 --- a/src/main/java/graphql/annotations/GraphQLDefaultValue.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLDefaultValue.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLDeprecate.java b/src/main/java/graphql/annotations/annotations/GraphQLDeprecate.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLDeprecate.java rename to src/main/java/graphql/annotations/annotations/GraphQLDeprecate.java index 7c04e7c3..e79a0e69 100644 --- a/src/main/java/graphql/annotations/GraphQLDeprecate.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLDeprecate.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLDescription.java b/src/main/java/graphql/annotations/annotations/GraphQLDescription.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLDescription.java rename to src/main/java/graphql/annotations/annotations/GraphQLDescription.java index c0b29181..1e70ef29 100644 --- a/src/main/java/graphql/annotations/GraphQLDescription.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLDescription.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLField.java b/src/main/java/graphql/annotations/annotations/GraphQLField.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLField.java rename to src/main/java/graphql/annotations/annotations/GraphQLField.java index 1ab03058..bf751f16 100644 --- a/src/main/java/graphql/annotations/GraphQLField.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLField.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLID.java b/src/main/java/graphql/annotations/annotations/GraphQLID.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLID.java rename to src/main/java/graphql/annotations/annotations/GraphQLID.java index ad9be20d..9c5cab92 100644 --- a/src/main/java/graphql/annotations/GraphQLID.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLID.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLInvokeDetached.java b/src/main/java/graphql/annotations/annotations/GraphQLInvokeDetached.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLInvokeDetached.java rename to src/main/java/graphql/annotations/annotations/GraphQLInvokeDetached.java index 6388f827..cdbaa6aa 100644 --- a/src/main/java/graphql/annotations/GraphQLInvokeDetached.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLInvokeDetached.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLMutation.java b/src/main/java/graphql/annotations/annotations/GraphQLMutation.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLMutation.java rename to src/main/java/graphql/annotations/annotations/GraphQLMutation.java index 1e077a63..02b6f779 100644 --- a/src/main/java/graphql/annotations/GraphQLMutation.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLMutation.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLName.java b/src/main/java/graphql/annotations/annotations/GraphQLName.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLName.java rename to src/main/java/graphql/annotations/annotations/GraphQLName.java index 9b02c04d..b8defb08 100644 --- a/src/main/java/graphql/annotations/GraphQLName.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLName.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLNonNull.java b/src/main/java/graphql/annotations/annotations/GraphQLNonNull.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLNonNull.java rename to src/main/java/graphql/annotations/annotations/GraphQLNonNull.java index 5459cf1a..92f67679 100644 --- a/src/main/java/graphql/annotations/GraphQLNonNull.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLNonNull.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLRelayMutation.java b/src/main/java/graphql/annotations/annotations/GraphQLRelayMutation.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLRelayMutation.java rename to src/main/java/graphql/annotations/annotations/GraphQLRelayMutation.java index db42d632..375afeca 100644 --- a/src/main/java/graphql/annotations/GraphQLRelayMutation.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLRelayMutation.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLType.java b/src/main/java/graphql/annotations/annotations/GraphQLType.java similarity index 84% rename from src/main/java/graphql/annotations/GraphQLType.java rename to src/main/java/graphql/annotations/annotations/GraphQLType.java index 3d0f4870..94dff3a4 100644 --- a/src/main/java/graphql/annotations/GraphQLType.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLType.java @@ -12,9 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; -import graphql.annotations.typeFunctions.DefaultTypeFunction; +import graphql.annotations.processor.typeFunctions.TypeFunction; +import graphql.annotations.processor.typeFunctions.DefaultTypeFunction; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLTypeExtension.java b/src/main/java/graphql/annotations/annotations/GraphQLTypeExtension.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLTypeExtension.java rename to src/main/java/graphql/annotations/annotations/GraphQLTypeExtension.java index b9d39df9..5004d5d8 100644 --- a/src/main/java/graphql/annotations/GraphQLTypeExtension.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLTypeExtension.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/GraphQLTypeResolver.java b/src/main/java/graphql/annotations/annotations/GraphQLTypeResolver.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLTypeResolver.java rename to src/main/java/graphql/annotations/annotations/GraphQLTypeResolver.java index da22e656..572ee563 100644 --- a/src/main/java/graphql/annotations/GraphQLTypeResolver.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLTypeResolver.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import graphql.schema.TypeResolver; diff --git a/src/main/java/graphql/annotations/GraphQLUnion.java b/src/main/java/graphql/annotations/annotations/GraphQLUnion.java similarity index 95% rename from src/main/java/graphql/annotations/GraphQLUnion.java rename to src/main/java/graphql/annotations/annotations/GraphQLUnion.java index 0c7de2f9..6e61f7f6 100644 --- a/src/main/java/graphql/annotations/GraphQLUnion.java +++ b/src/main/java/graphql/annotations/annotations/GraphQLUnion.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/BatchedMethodDataFetcher.java b/src/main/java/graphql/annotations/dataFetchers/BatchedMethodDataFetcher.java similarity index 79% rename from src/main/java/graphql/annotations/BatchedMethodDataFetcher.java rename to src/main/java/graphql/annotations/dataFetchers/BatchedMethodDataFetcher.java index 821a372f..5f4c3a89 100644 --- a/src/main/java/graphql/annotations/BatchedMethodDataFetcher.java +++ b/src/main/java/graphql/annotations/dataFetchers/BatchedMethodDataFetcher.java @@ -12,8 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.dataFetchers; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.typeFunctions.TypeFunction; import graphql.execution.batched.Batched; import graphql.schema.DataFetchingEnvironment; @@ -23,7 +25,7 @@ public class BatchedMethodDataFetcher extends MethodDataFetcher { - public BatchedMethodDataFetcher(Method method,TypeFunction typeFunction, ProcessingElementsContainer container) { + public BatchedMethodDataFetcher(Method method, TypeFunction typeFunction, ProcessingElementsContainer container) { super(method,typeFunction, container); if (!Modifier.isStatic(method.getModifiers())) { throw new IllegalArgumentException("Batched method should be static"); diff --git a/src/main/java/graphql/annotations/ExtensionDataFetcherWrapper.java b/src/main/java/graphql/annotations/dataFetchers/ExtensionDataFetcherWrapper.java similarity index 94% rename from src/main/java/graphql/annotations/ExtensionDataFetcherWrapper.java rename to src/main/java/graphql/annotations/dataFetchers/ExtensionDataFetcherWrapper.java index e7a7b228..28867009 100644 --- a/src/main/java/graphql/annotations/ExtensionDataFetcherWrapper.java +++ b/src/main/java/graphql/annotations/dataFetchers/ExtensionDataFetcherWrapper.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.dataFetchers; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; @@ -20,7 +20,7 @@ import java.util.Map; -import static graphql.annotations.ReflectionKit.newInstance; +import static graphql.annotations.processor.util.ReflectionKit.newInstance; public class ExtensionDataFetcherWrapper implements DataFetcher{ diff --git a/src/main/java/graphql/annotations/MethodDataFetcher.java b/src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java similarity index 89% rename from src/main/java/graphql/annotations/MethodDataFetcher.java rename to src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java index 0b610acc..fc6b2458 100644 --- a/src/main/java/graphql/annotations/MethodDataFetcher.java +++ b/src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java @@ -12,8 +12,12 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.dataFetchers; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.annotations.GraphQLInvokeDetached; +import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.processor.typeFunctions.TypeFunction; import graphql.schema.*; import graphql.schema.GraphQLType; @@ -22,11 +26,11 @@ import java.util.List; import java.util.Map; -import static graphql.annotations.ReflectionKit.constructNewInstance; -import static graphql.annotations.ReflectionKit.newInstance; -import static graphql.annotations.util.NamingKit.toGraphqlName; +import static graphql.annotations.processor.util.ReflectionKit.constructNewInstance; +import static graphql.annotations.processor.util.ReflectionKit.newInstance; +import static graphql.annotations.processor.util.NamingKit.toGraphqlName; -class MethodDataFetcher implements DataFetcher { +public class MethodDataFetcher implements DataFetcher { private final Method method; private final ProcessingElementsContainer container; private final TypeFunction typeFunction; diff --git a/src/main/java/graphql/annotations/RelayMutationMethodDataFetcher.java b/src/main/java/graphql/annotations/dataFetchers/RelayMutationMethodDataFetcher.java similarity index 98% rename from src/main/java/graphql/annotations/RelayMutationMethodDataFetcher.java rename to src/main/java/graphql/annotations/dataFetchers/RelayMutationMethodDataFetcher.java index 22e35e9c..fb8562e6 100644 --- a/src/main/java/graphql/annotations/RelayMutationMethodDataFetcher.java +++ b/src/main/java/graphql/annotations/dataFetchers/RelayMutationMethodDataFetcher.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.dataFetchers; import graphql.schema.*; diff --git a/src/main/java/graphql/annotations/Connection.java b/src/main/java/graphql/annotations/dataFetchers/connection/Connection.java similarity index 92% rename from src/main/java/graphql/annotations/Connection.java rename to src/main/java/graphql/annotations/dataFetchers/connection/Connection.java index 14527576..6eed7f79 100644 --- a/src/main/java/graphql/annotations/Connection.java +++ b/src/main/java/graphql/annotations/dataFetchers/connection/Connection.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.dataFetchers.connection; import graphql.schema.DataFetcher; diff --git a/src/main/java/graphql/annotations/ConnectionDataFetcher.java b/src/main/java/graphql/annotations/dataFetchers/connection/ConnectionDataFetcher.java similarity index 93% rename from src/main/java/graphql/annotations/ConnectionDataFetcher.java rename to src/main/java/graphql/annotations/dataFetchers/connection/ConnectionDataFetcher.java index 8e95bc9c..ff9c1b17 100644 --- a/src/main/java/graphql/annotations/ConnectionDataFetcher.java +++ b/src/main/java/graphql/annotations/dataFetchers/connection/ConnectionDataFetcher.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.dataFetchers.connection; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; @@ -23,9 +23,9 @@ import java.util.HashMap; import java.util.Optional; -import static graphql.annotations.ReflectionKit.constructNewInstance; +import static graphql.annotations.processor.util.ReflectionKit.constructNewInstance; - class ConnectionDataFetcher implements DataFetcher { + public class ConnectionDataFetcher implements DataFetcher { private final Class connection; private final DataFetcher actualDataFetcher; private final Constructor constructor; diff --git a/src/main/java/graphql/annotations/DispatchingConnection.java b/src/main/java/graphql/annotations/dataFetchers/connection/DispatchingConnection.java similarity index 96% rename from src/main/java/graphql/annotations/DispatchingConnection.java rename to src/main/java/graphql/annotations/dataFetchers/connection/DispatchingConnection.java index dfe820c7..fc1c8729 100644 --- a/src/main/java/graphql/annotations/DispatchingConnection.java +++ b/src/main/java/graphql/annotations/dataFetchers/connection/DispatchingConnection.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.dataFetchers.connection; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; diff --git a/src/main/java/graphql/annotations/ListConnection.java b/src/main/java/graphql/annotations/dataFetchers/connection/ListConnection.java similarity index 93% rename from src/main/java/graphql/annotations/ListConnection.java rename to src/main/java/graphql/annotations/dataFetchers/connection/ListConnection.java index 609149f2..6f0145e3 100644 --- a/src/main/java/graphql/annotations/ListConnection.java +++ b/src/main/java/graphql/annotations/dataFetchers/connection/ListConnection.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.dataFetchers.connection; import graphql.relay.SimpleListConnection; diff --git a/src/main/java/graphql/annotations/StreamConnection.java b/src/main/java/graphql/annotations/dataFetchers/connection/StreamConnection.java similarity index 95% rename from src/main/java/graphql/annotations/StreamConnection.java rename to src/main/java/graphql/annotations/dataFetchers/connection/StreamConnection.java index d34ec764..2cda05ee 100644 --- a/src/main/java/graphql/annotations/StreamConnection.java +++ b/src/main/java/graphql/annotations/dataFetchers/connection/StreamConnection.java @@ -12,9 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.dataFetchers.connection; -import graphql.annotations.util.Base64; +import graphql.annotations.processor.util.Base64; import graphql.relay.ConnectionCursor; import graphql.relay.DefaultConnection; import graphql.relay.DefaultConnectionCursor; @@ -30,7 +30,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static graphql.annotations.util.RelayKit.EMPTY_CONNECTION; +import static graphql.annotations.processor.util.RelayKit.EMPTY_CONNECTION; public class StreamConnection implements DataFetcher, Connection { diff --git a/src/main/java/graphql/annotations/GraphQLAnnotations.java b/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java similarity index 86% rename from src/main/java/graphql/annotations/GraphQLAnnotations.java rename to src/main/java/graphql/annotations/processor/GraphQLAnnotations.java index 73b54c94..0fd625a6 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java @@ -12,12 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; - -import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; -import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; -import graphql.annotations.typeFunctions.DefaultTypeFunction; -import graphql.annotations.util.GraphQLObjectInfoRetriever; +package graphql.annotations.processor; + +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.retrievers.GraphQLObjectHandler; +import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.annotations.GraphQLTypeExtension; +import graphql.annotations.processor.graphQLProcessors.GraphQLAnnotationsProcessor; +import graphql.annotations.processor.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.processor.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.processor.typeFunctions.DefaultTypeFunction; +import graphql.annotations.processor.typeFunctions.TypeFunction; +import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; import graphql.relay.Relay; import graphql.schema.GraphQLFieldDefinition; import graphql.schema.GraphQLObjectType; @@ -25,7 +31,7 @@ import java.util.*; -import static graphql.annotations.util.NamingKit.toGraphqlName; +import static graphql.annotations.processor.util.NamingKit.toGraphqlName; /** * A utility class for extracting GraphQL data structures from annotated diff --git a/src/main/java/graphql/annotations/ProcessingElementsContainer.java b/src/main/java/graphql/annotations/processor/ProcessingElementsContainer.java similarity index 88% rename from src/main/java/graphql/annotations/ProcessingElementsContainer.java rename to src/main/java/graphql/annotations/processor/ProcessingElementsContainer.java index 6103d36d..7a04ac3a 100644 --- a/src/main/java/graphql/annotations/ProcessingElementsContainer.java +++ b/src/main/java/graphql/annotations/processor/ProcessingElementsContainer.java @@ -12,17 +12,12 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.processor; -import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; -import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; -import graphql.annotations.typeFunctions.DefaultTypeFunction; +import graphql.annotations.processor.typeFunctions.TypeFunction; import graphql.relay.Relay; -import graphql.schema.*; -import graphql.schema.GraphQLType; -import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.Stack; diff --git a/src/main/java/graphql/annotations/GraphQLAnnotationsException.java b/src/main/java/graphql/annotations/processor/exceptions/GraphQLAnnotationsException.java similarity index 94% rename from src/main/java/graphql/annotations/GraphQLAnnotationsException.java rename to src/main/java/graphql/annotations/processor/exceptions/GraphQLAnnotationsException.java index 9c7ae98f..f4002a5f 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotationsException.java +++ b/src/main/java/graphql/annotations/processor/exceptions/GraphQLAnnotationsException.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.processor.exceptions; /** * A base class for runtime exceptions that can happen during annotation introspection diff --git a/src/main/java/graphql/annotations/GraphQLAnnotationsProcessor.java b/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java similarity index 98% rename from src/main/java/graphql/annotations/GraphQLAnnotationsProcessor.java rename to src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java index 96ffe1e3..9a514c93 100644 --- a/src/main/java/graphql/annotations/GraphQLAnnotationsProcessor.java +++ b/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java @@ -12,10 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.processor.graphQLProcessors; -import graphql.schema.*; -import graphql.schema.GraphQLType; +import graphql.annotations.annotations.GraphQLTypeExtension; public interface GraphQLAnnotationsProcessor { // /** diff --git a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java b/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLInputProcessor.java similarity index 87% rename from src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java rename to src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLInputProcessor.java index 7f989b63..0f8d7f4d 100644 --- a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLInputProcessor.java +++ b/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLInputProcessor.java @@ -12,13 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.graphQLProcessors; +package graphql.annotations.processor.graphQLProcessors; -import graphql.annotations.GraphQLInputObjectRetriever; -import graphql.annotations.GraphQLObjectHandler; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.annotations.processor.retrievers.GraphQLInputObjectRetriever; +import graphql.annotations.processor.retrievers.GraphQLObjectHandler; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; import graphql.schema.GraphQLInputObjectType; import graphql.schema.GraphQLType; diff --git a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java b/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLOutputProcessor.java similarity index 82% rename from src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java rename to src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLOutputProcessor.java index 98efb7d5..2f16f3ca 100644 --- a/src/main/java/graphql/annotations/graphQLProcessors/GraphQLOutputProcessor.java +++ b/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLOutputProcessor.java @@ -12,13 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.graphQLProcessors; +package graphql.annotations.processor.graphQLProcessors; -import graphql.annotations.GraphQLAnnotationsException; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.util.GraphQLObjectInfoRetriever; -import graphql.annotations.util.GraphQLOutputObjectRetriever; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; +import graphql.annotations.processor.retrievers.GraphQLOutputObjectRetriever; import graphql.schema.GraphQLOutputType; import graphql.schema.GraphQLTypeReference; diff --git a/src/main/java/graphql/annotations/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java similarity index 92% rename from src/main/java/graphql/annotations/GraphQLFieldRetriever.java rename to src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java index 1a269ddd..0d9a8afe 100644 --- a/src/main/java/graphql/annotations/GraphQLFieldRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java @@ -12,14 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; - - -import graphql.annotations.searchAlgorithms.BreadthFirstSearch; -import graphql.annotations.searchAlgorithms.CannotCastMemberException; -import graphql.annotations.searchAlgorithms.ParentalSearch; -import graphql.annotations.typeFunctions.BatchedTypeFunction; -import graphql.annotations.util.GraphQLObjectInfoRetriever; +package graphql.annotations.processor.retrievers; + + +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.dataFetchers.RelayMutationMethodDataFetcher; +import graphql.annotations.annotations.*; +import graphql.annotations.annotations.GraphQLType; +import graphql.annotations.dataFetchers.BatchedMethodDataFetcher; +import graphql.annotations.dataFetchers.MethodDataFetcher; +import graphql.annotations.dataFetchers.connection.ConnectionDataFetcher; +import graphql.annotations.dataFetchers.ExtensionDataFetcherWrapper; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; +import graphql.annotations.processor.searchAlgorithms.CannotCastMemberException; +import graphql.annotations.processor.searchAlgorithms.ParentalSearch; +import graphql.annotations.processor.typeFunctions.BatchedTypeFunction; +import graphql.annotations.processor.typeFunctions.TypeFunction; import graphql.relay.Relay; import graphql.schema.*; import graphql.schema.GraphQLNonNull; @@ -30,10 +40,10 @@ import java.util.stream.Stream; import static graphql.Scalars.GraphQLBoolean; -import static graphql.annotations.ReflectionKit.constructNewInstance; -import static graphql.annotations.ReflectionKit.newInstance; -import static graphql.annotations.util.NamingKit.toGraphqlName; -import static graphql.annotations.util.ObjectUtil.getAllFields; +import static graphql.annotations.processor.util.ReflectionKit.constructNewInstance; +import static graphql.annotations.processor.util.ReflectionKit.newInstance; +import static graphql.annotations.processor.util.NamingKit.toGraphqlName; +import static graphql.annotations.processor.util.ObjectUtil.getAllFields; import static graphql.schema.GraphQLArgument.newArgument; import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; import static graphql.schema.GraphQLInputObjectField.newInputObjectField; diff --git a/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLInputObjectRetriever.java similarity index 98% rename from src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java rename to src/main/java/graphql/annotations/processor/retrievers/GraphQLInputObjectRetriever.java index 19915e75..5d6c0d8f 100644 --- a/src/main/java/graphql/annotations/GraphQLInputObjectRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLInputObjectRetriever.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.processor.retrievers; import graphql.schema.*; diff --git a/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLInterfaceRetriever.java similarity index 86% rename from src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java rename to src/main/java/graphql/annotations/processor/retrievers/GraphQLInterfaceRetriever.java index ca5e31ae..70633073 100644 --- a/src/main/java/graphql/annotations/GraphQLInterfaceRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLInterfaceRetriever.java @@ -12,9 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.processor.retrievers; -import graphql.annotations.util.GraphQLOutputObjectRetriever; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.ProcessingElementsContainer; public class GraphQLInterfaceRetriever { diff --git a/src/main/java/graphql/annotations/GraphQLObjectHandler.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectHandler.java similarity index 84% rename from src/main/java/graphql/annotations/GraphQLObjectHandler.java rename to src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectHandler.java index 17401a28..405c2287 100644 --- a/src/main/java/graphql/annotations/GraphQLObjectHandler.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectHandler.java @@ -12,10 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.processor.retrievers; -import graphql.annotations.searchAlgorithms.CannotCastMemberException; -import graphql.annotations.util.GraphQLOutputObjectRetriever; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.searchAlgorithms.CannotCastMemberException; import graphql.schema.GraphQLObjectType; import graphql.schema.GraphQLOutputType; diff --git a/src/main/java/graphql/annotations/util/GraphQLObjectInfoRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectInfoRetriever.java similarity index 86% rename from src/main/java/graphql/annotations/util/GraphQLObjectInfoRetriever.java rename to src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectInfoRetriever.java index 53633785..912c5789 100644 --- a/src/main/java/graphql/annotations/util/GraphQLObjectInfoRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectInfoRetriever.java @@ -12,11 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.util; +package graphql.annotations.processor.retrievers; -import graphql.annotations.GraphQLField; -import graphql.annotations.GraphQLName; +import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.annotations.GraphQLName; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; @@ -25,7 +25,7 @@ import java.util.List; import java.util.stream.Collectors; -import static graphql.annotations.util.NamingKit.toGraphqlName; +import static graphql.annotations.processor.util.NamingKit.toGraphqlName; public class GraphQLObjectInfoRetriever { diff --git a/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java similarity index 79% rename from src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java rename to src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java index 0a2c958a..ade9e1b8 100644 --- a/src/main/java/graphql/annotations/util/GraphQLOutputObjectRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java @@ -12,16 +12,19 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.util; +package graphql.annotations.processor.retrievers; -import graphql.annotations.*; -import graphql.annotations.builders.EnumBuilder; -import graphql.annotations.builders.InterfaceBuilder; -import graphql.annotations.builders.ObjectBuilder; -import graphql.annotations.builders.UnionBuilder; -import graphql.annotations.searchAlgorithms.BreadthFirstSearch; -import graphql.annotations.searchAlgorithms.CannotCastMemberException; -import graphql.annotations.searchAlgorithms.ParentalSearch; +import graphql.annotations.annotations.GraphQLTypeResolver; +import graphql.annotations.annotations.GraphQLUnion; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.typeBuilders.EnumBuilder; +import graphql.annotations.processor.typeBuilders.InterfaceBuilder; +import graphql.annotations.processor.typeBuilders.ObjectBuilder; +import graphql.annotations.processor.typeBuilders.UnionBuilder; +import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; +import graphql.annotations.processor.searchAlgorithms.CannotCastMemberException; +import graphql.annotations.processor.searchAlgorithms.ParentalSearch; import graphql.schema.GraphQLOutputType; public class GraphQLOutputObjectRetriever { diff --git a/src/main/java/graphql/annotations/searchAlgorithms/BreadthFirstSearch.java b/src/main/java/graphql/annotations/processor/searchAlgorithms/BreadthFirstSearch.java similarity index 95% rename from src/main/java/graphql/annotations/searchAlgorithms/BreadthFirstSearch.java rename to src/main/java/graphql/annotations/processor/searchAlgorithms/BreadthFirstSearch.java index e0ab4a81..0f56cf21 100644 --- a/src/main/java/graphql/annotations/searchAlgorithms/BreadthFirstSearch.java +++ b/src/main/java/graphql/annotations/processor/searchAlgorithms/BreadthFirstSearch.java @@ -12,9 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.searchAlgorithms; +package graphql.annotations.processor.searchAlgorithms; -import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; import java.lang.reflect.Member; import java.lang.reflect.Method; diff --git a/src/main/java/graphql/annotations/searchAlgorithms/CannotCastMemberException.java b/src/main/java/graphql/annotations/processor/searchAlgorithms/CannotCastMemberException.java similarity index 94% rename from src/main/java/graphql/annotations/searchAlgorithms/CannotCastMemberException.java rename to src/main/java/graphql/annotations/processor/searchAlgorithms/CannotCastMemberException.java index 23c88acc..3c0ebb97 100644 --- a/src/main/java/graphql/annotations/searchAlgorithms/CannotCastMemberException.java +++ b/src/main/java/graphql/annotations/processor/searchAlgorithms/CannotCastMemberException.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.searchAlgorithms; +package graphql.annotations.processor.searchAlgorithms; public class CannotCastMemberException extends RuntimeException { diff --git a/src/main/java/graphql/annotations/searchAlgorithms/ParentalSearch.java b/src/main/java/graphql/annotations/processor/searchAlgorithms/ParentalSearch.java similarity index 93% rename from src/main/java/graphql/annotations/searchAlgorithms/ParentalSearch.java rename to src/main/java/graphql/annotations/processor/searchAlgorithms/ParentalSearch.java index 969bf2c6..c56952fd 100644 --- a/src/main/java/graphql/annotations/searchAlgorithms/ParentalSearch.java +++ b/src/main/java/graphql/annotations/processor/searchAlgorithms/ParentalSearch.java @@ -12,9 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.searchAlgorithms; +package graphql.annotations.processor.searchAlgorithms; -import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; import java.lang.reflect.Field; import java.lang.reflect.Member; diff --git a/src/main/java/graphql/annotations/searchAlgorithms/SearchAlgorithm.java b/src/main/java/graphql/annotations/processor/searchAlgorithms/SearchAlgorithm.java similarity index 92% rename from src/main/java/graphql/annotations/searchAlgorithms/SearchAlgorithm.java rename to src/main/java/graphql/annotations/processor/searchAlgorithms/SearchAlgorithm.java index 336f289c..c4e3448e 100644 --- a/src/main/java/graphql/annotations/searchAlgorithms/SearchAlgorithm.java +++ b/src/main/java/graphql/annotations/processor/searchAlgorithms/SearchAlgorithm.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.searchAlgorithms; +package graphql.annotations.processor.searchAlgorithms; import java.lang.reflect.Member; diff --git a/src/main/java/graphql/annotations/builders/EnumBuilder.java b/src/main/java/graphql/annotations/processor/typeBuilders/EnumBuilder.java similarity index 90% rename from src/main/java/graphql/annotations/builders/EnumBuilder.java rename to src/main/java/graphql/annotations/processor/typeBuilders/EnumBuilder.java index 89073de5..93955a18 100644 --- a/src/main/java/graphql/annotations/builders/EnumBuilder.java +++ b/src/main/java/graphql/annotations/processor/typeBuilders/EnumBuilder.java @@ -12,11 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.builders; +package graphql.annotations.processor.typeBuilders; -import graphql.annotations.GraphQLDescription; -import graphql.annotations.GraphQLName; -import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.annotations.annotations.GraphQLDescription; +import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; import graphql.schema.GraphQLEnumType; import java.lang.reflect.Field; diff --git a/src/main/java/graphql/annotations/builders/InterfaceBuilder.java b/src/main/java/graphql/annotations/processor/typeBuilders/InterfaceBuilder.java similarity index 83% rename from src/main/java/graphql/annotations/builders/InterfaceBuilder.java rename to src/main/java/graphql/annotations/processor/typeBuilders/InterfaceBuilder.java index b0a3aa5b..99e9607e 100644 --- a/src/main/java/graphql/annotations/builders/InterfaceBuilder.java +++ b/src/main/java/graphql/annotations/processor/typeBuilders/InterfaceBuilder.java @@ -12,11 +12,16 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.builders; +package graphql.annotations.processor.typeBuilders; -import graphql.annotations.*; -import graphql.annotations.searchAlgorithms.CannotCastMemberException; -import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.annotations.annotations.GraphQLDescription; +import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.annotations.GraphQLTypeResolver; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.retrievers.GraphQLFieldRetriever; +import graphql.annotations.processor.searchAlgorithms.CannotCastMemberException; +import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; import graphql.schema.GraphQLFieldDefinition; import graphql.schema.GraphQLInterfaceType; @@ -25,7 +30,7 @@ import java.util.ArrayList; import java.util.List; -import static graphql.annotations.ReflectionKit.newInstance; +import static graphql.annotations.processor.util.ReflectionKit.newInstance; import static graphql.schema.GraphQLInterfaceType.newInterface; /** * Copyright 2016 Yurii Rashkovskii diff --git a/src/main/java/graphql/annotations/builders/ObjectBuilder.java b/src/main/java/graphql/annotations/processor/typeBuilders/ObjectBuilder.java similarity index 83% rename from src/main/java/graphql/annotations/builders/ObjectBuilder.java rename to src/main/java/graphql/annotations/processor/typeBuilders/ObjectBuilder.java index cacbebd4..30ef86fb 100644 --- a/src/main/java/graphql/annotations/builders/ObjectBuilder.java +++ b/src/main/java/graphql/annotations/processor/typeBuilders/ObjectBuilder.java @@ -12,13 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.builders; +package graphql.annotations.processor.typeBuilders; -import graphql.annotations.*; -import graphql.annotations.searchAlgorithms.BreadthFirstSearch; -import graphql.annotations.searchAlgorithms.ParentalSearch; -import graphql.annotations.util.GraphQLObjectInfoRetriever; -import graphql.annotations.util.GraphQLOutputObjectRetriever; +import graphql.annotations.annotations.GraphQLDescription; +import graphql.annotations.annotations.GraphQLTypeResolver; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.retrievers.GraphQLFieldRetriever; +import graphql.annotations.processor.retrievers.GraphQLInterfaceRetriever; +import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; +import graphql.annotations.processor.searchAlgorithms.ParentalSearch; +import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; +import graphql.annotations.processor.retrievers.GraphQLOutputObjectRetriever; import graphql.schema.GraphQLFieldDefinition; import graphql.schema.GraphQLInterfaceType; import graphql.schema.GraphQLObjectType; @@ -30,7 +35,7 @@ import java.util.ArrayList; import java.util.List; -import static graphql.annotations.util.ObjectUtil.getAllFields; +import static graphql.annotations.processor.util.ObjectUtil.getAllFields; import static graphql.schema.GraphQLObjectType.newObject; diff --git a/src/main/java/graphql/annotations/builders/UnionBuilder.java b/src/main/java/graphql/annotations/processor/typeBuilders/UnionBuilder.java similarity index 78% rename from src/main/java/graphql/annotations/builders/UnionBuilder.java rename to src/main/java/graphql/annotations/processor/typeBuilders/UnionBuilder.java index dd36e57f..83f8dde3 100644 --- a/src/main/java/graphql/annotations/builders/UnionBuilder.java +++ b/src/main/java/graphql/annotations/processor/typeBuilders/UnionBuilder.java @@ -12,11 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.builders; +package graphql.annotations.processor.typeBuilders; -import graphql.annotations.*; -import graphql.annotations.util.GraphQLObjectInfoRetriever; +import graphql.annotations.annotations.GraphQLDescription; +import graphql.annotations.annotations.GraphQLType; +import graphql.annotations.annotations.GraphQLUnion; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.util.ReflectionKit; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.typeFunctions.TypeFunction; +import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; +import graphql.annotations.typeResolvers.UnionTypeResolver; import graphql.schema.GraphQLObjectType; import graphql.schema.GraphQLUnionType; @@ -45,7 +52,7 @@ public GraphQLUnionType.Builder getUnionBuilder(Class iface, ProcessingElemen if (description != null) { builder.description(description.value()); } - graphql.annotations.GraphQLType typeAnnotation = iface.getAnnotation(graphql.annotations.GraphQLType.class); + GraphQLType typeAnnotation = iface.getAnnotation(GraphQLType.class); TypeFunction typeFunction = container.getDefaultTypeFunction(); diff --git a/src/main/java/graphql/annotations/typeFunctions/BatchedTypeFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/BatchedTypeFunction.java similarity index 94% rename from src/main/java/graphql/annotations/typeFunctions/BatchedTypeFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/BatchedTypeFunction.java index 46d46640..2733de72 100644 --- a/src/main/java/graphql/annotations/typeFunctions/BatchedTypeFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/BatchedTypeFunction.java @@ -12,10 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedParameterizedType; diff --git a/src/main/java/graphql/annotations/typeFunctions/BooleanFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/BooleanFunction.java similarity index 90% rename from src/main/java/graphql/annotations/typeFunctions/BooleanFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/BooleanFunction.java index 57d6e4d0..1c45ed89 100644 --- a/src/main/java/graphql/annotations/typeFunctions/BooleanFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/BooleanFunction.java @@ -12,11 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; import graphql.Scalars; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedType; diff --git a/src/main/java/graphql/annotations/typeFunctions/DefaultTypeFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunction.java similarity index 90% rename from src/main/java/graphql/annotations/typeFunctions/DefaultTypeFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunction.java index e2a9c4a1..95565d16 100644 --- a/src/main/java/graphql/annotations/typeFunctions/DefaultTypeFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunction.java @@ -12,14 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; - -import graphql.annotations.GraphQLAnnotationsProcessor; -import graphql.annotations.GraphQLNonNull; -import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; -import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +package graphql.annotations.processor.typeFunctions; + +import graphql.annotations.processor.graphQLProcessors.GraphQLAnnotationsProcessor; +import graphql.annotations.annotations.GraphQLNonNull; +import graphql.annotations.processor.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.processor.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; import org.osgi.service.component.annotations.*; diff --git a/src/main/java/graphql/annotations/typeFunctions/FloatFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/FloatFunction.java similarity index 91% rename from src/main/java/graphql/annotations/typeFunctions/FloatFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/FloatFunction.java index 4131470f..7847ba2e 100644 --- a/src/main/java/graphql/annotations/typeFunctions/FloatFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/FloatFunction.java @@ -12,11 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; import graphql.Scalars; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedType; diff --git a/src/main/java/graphql/annotations/typeFunctions/IDFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/IDFunction.java similarity index 89% rename from src/main/java/graphql/annotations/typeFunctions/IDFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/IDFunction.java index cce8dd80..ee1f4395 100644 --- a/src/main/java/graphql/annotations/typeFunctions/IDFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/IDFunction.java @@ -12,12 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; import graphql.Scalars; -import graphql.annotations.GraphQLID; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +import graphql.annotations.annotations.GraphQLID; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedType; diff --git a/src/main/java/graphql/annotations/typeFunctions/IntegerFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/IntegerFunction.java similarity index 90% rename from src/main/java/graphql/annotations/typeFunctions/IntegerFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/IntegerFunction.java index 9888f81f..758d49b6 100644 --- a/src/main/java/graphql/annotations/typeFunctions/IntegerFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/IntegerFunction.java @@ -12,11 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; import graphql.Scalars; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedType; diff --git a/src/main/java/graphql/annotations/typeFunctions/IterableFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/IterableFunction.java similarity index 93% rename from src/main/java/graphql/annotations/typeFunctions/IterableFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/IterableFunction.java index 7f4af80c..0e0a6060 100644 --- a/src/main/java/graphql/annotations/typeFunctions/IterableFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/IterableFunction.java @@ -12,10 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLList; import graphql.schema.GraphQLType; diff --git a/src/main/java/graphql/annotations/typeFunctions/LongFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/LongFunction.java similarity index 90% rename from src/main/java/graphql/annotations/typeFunctions/LongFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/LongFunction.java index 7851d395..06618c46 100644 --- a/src/main/java/graphql/annotations/typeFunctions/LongFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/LongFunction.java @@ -12,11 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; import graphql.Scalars; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedType; diff --git a/src/main/java/graphql/annotations/typeFunctions/ObjectFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/ObjectFunction.java similarity index 81% rename from src/main/java/graphql/annotations/typeFunctions/ObjectFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/ObjectFunction.java index edbd28a1..e6edefe0 100644 --- a/src/main/java/graphql/annotations/typeFunctions/ObjectFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/ObjectFunction.java @@ -12,18 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.GraphQLName; -import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; -import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.processor.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.processor.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedType; -import static graphql.annotations.util.NamingKit.toGraphqlName; +import static graphql.annotations.processor.util.NamingKit.toGraphqlName; class ObjectFunction implements TypeFunction { diff --git a/src/main/java/graphql/annotations/typeFunctions/OptionalFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/OptionalFunction.java similarity index 94% rename from src/main/java/graphql/annotations/typeFunctions/OptionalFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/OptionalFunction.java index 922b9a6c..6aab92a9 100644 --- a/src/main/java/graphql/annotations/typeFunctions/OptionalFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/OptionalFunction.java @@ -12,10 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedParameterizedType; diff --git a/src/main/java/graphql/annotations/typeFunctions/StreamFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/StreamFunction.java similarity index 93% rename from src/main/java/graphql/annotations/typeFunctions/StreamFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/StreamFunction.java index 171df56f..f9948bf9 100644 --- a/src/main/java/graphql/annotations/typeFunctions/StreamFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/StreamFunction.java @@ -12,10 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLList; import graphql.schema.GraphQLType; diff --git a/src/main/java/graphql/annotations/typeFunctions/StringFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/StringFunction.java similarity index 90% rename from src/main/java/graphql/annotations/typeFunctions/StringFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/StringFunction.java index b8d5fe06..571c4538 100644 --- a/src/main/java/graphql/annotations/typeFunctions/StringFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/StringFunction.java @@ -12,11 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; import graphql.Scalars; -import graphql.annotations.ProcessingElementsContainer; -import graphql.annotations.TypeFunction; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedType; diff --git a/src/main/java/graphql/annotations/TypeFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/TypeFunction.java similarity index 95% rename from src/main/java/graphql/annotations/TypeFunction.java rename to src/main/java/graphql/annotations/processor/typeFunctions/TypeFunction.java index 30f49944..f3b06727 100644 --- a/src/main/java/graphql/annotations/TypeFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/TypeFunction.java @@ -12,12 +12,12 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.processor.typeFunctions; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; import java.lang.reflect.AnnotatedType; -import java.util.Map; /** * A GraphQLType builder for java types. diff --git a/src/main/java/graphql/annotations/util/Base64.java b/src/main/java/graphql/annotations/processor/util/Base64.java similarity index 96% rename from src/main/java/graphql/annotations/util/Base64.java rename to src/main/java/graphql/annotations/processor/util/Base64.java index 19d611df..c5a0d803 100644 --- a/src/main/java/graphql/annotations/util/Base64.java +++ b/src/main/java/graphql/annotations/processor/util/Base64.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.util; +package graphql.annotations.processor.util; import javax.xml.bind.DatatypeConverter; import java.io.UnsupportedEncodingException; diff --git a/src/main/java/graphql/annotations/util/NamingKit.java b/src/main/java/graphql/annotations/processor/util/NamingKit.java similarity index 98% rename from src/main/java/graphql/annotations/util/NamingKit.java rename to src/main/java/graphql/annotations/processor/util/NamingKit.java index a889ad71..9c96861a 100644 --- a/src/main/java/graphql/annotations/util/NamingKit.java +++ b/src/main/java/graphql/annotations/processor/util/NamingKit.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.util; +package graphql.annotations.processor.util; import java.util.regex.Pattern; diff --git a/src/main/java/graphql/annotations/util/ObjectUtil.java b/src/main/java/graphql/annotations/processor/util/ObjectUtil.java similarity index 96% rename from src/main/java/graphql/annotations/util/ObjectUtil.java rename to src/main/java/graphql/annotations/processor/util/ObjectUtil.java index cd8f692b..f4c23ffa 100644 --- a/src/main/java/graphql/annotations/util/ObjectUtil.java +++ b/src/main/java/graphql/annotations/processor/util/ObjectUtil.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.util; +package graphql.annotations.processor.util; import java.lang.reflect.Field; import java.util.Map; diff --git a/src/main/java/graphql/annotations/ReflectionKit.java b/src/main/java/graphql/annotations/processor/util/ReflectionKit.java similarity index 95% rename from src/main/java/graphql/annotations/ReflectionKit.java rename to src/main/java/graphql/annotations/processor/util/ReflectionKit.java index a4c4fcc6..3b71fa15 100644 --- a/src/main/java/graphql/annotations/ReflectionKit.java +++ b/src/main/java/graphql/annotations/processor/util/ReflectionKit.java @@ -12,7 +12,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.processor.util; + +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; diff --git a/src/main/java/graphql/annotations/util/RelayKit.java b/src/main/java/graphql/annotations/processor/util/RelayKit.java similarity index 96% rename from src/main/java/graphql/annotations/util/RelayKit.java rename to src/main/java/graphql/annotations/processor/util/RelayKit.java index 0b39e787..e77eec40 100644 --- a/src/main/java/graphql/annotations/util/RelayKit.java +++ b/src/main/java/graphql/annotations/processor/util/RelayKit.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.util; +package graphql.annotations.processor.util; import graphql.relay.DefaultConnection; import graphql.relay.DefaultPageInfo; diff --git a/src/main/java/graphql/annotations/EnhancedExecutionStrategy.java b/src/main/java/graphql/annotations/strategies/EnhancedExecutionStrategy.java similarity index 99% rename from src/main/java/graphql/annotations/EnhancedExecutionStrategy.java rename to src/main/java/graphql/annotations/strategies/EnhancedExecutionStrategy.java index 46761683..7bec1845 100644 --- a/src/main/java/graphql/annotations/EnhancedExecutionStrategy.java +++ b/src/main/java/graphql/annotations/strategies/EnhancedExecutionStrategy.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.strategies; import graphql.ExecutionResult; import graphql.execution.*; diff --git a/src/main/java/graphql/annotations/UnionTypeResolver.java b/src/main/java/graphql/annotations/typeResolvers/UnionTypeResolver.java similarity index 93% rename from src/main/java/graphql/annotations/UnionTypeResolver.java rename to src/main/java/graphql/annotations/typeResolvers/UnionTypeResolver.java index cc6119c9..dfcdb57c 100644 --- a/src/main/java/graphql/annotations/UnionTypeResolver.java +++ b/src/main/java/graphql/annotations/typeResolvers/UnionTypeResolver.java @@ -12,9 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.typeResolvers; import graphql.TypeResolutionEnvironment; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.*; import graphql.schema.GraphQLType; diff --git a/src/test/java/graphql/annotations/GraphQLBatchedTest.java b/src/test/java/graphql/annotations/GraphQLBatchedTest.java index 6f4ce6e5..4f1adbd3 100644 --- a/src/test/java/graphql/annotations/GraphQLBatchedTest.java +++ b/src/test/java/graphql/annotations/GraphQLBatchedTest.java @@ -17,11 +17,13 @@ import graphql.ExceptionWhileDataFetching; import graphql.ExecutionResult; import graphql.GraphQL; +import graphql.annotations.annotations.GraphQLBatched; +import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.processor.GraphQLAnnotations; import graphql.execution.batched.BatchedExecutionStrategy; import graphql.schema.GraphQLObjectType; import graphql.schema.GraphQLSchema; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.util.Arrays; diff --git a/src/test/java/graphql/annotations/GraphQLConnectionTest.java b/src/test/java/graphql/annotations/GraphQLConnectionTest.java index 26c61d58..7290b630 100644 --- a/src/test/java/graphql/annotations/GraphQLConnectionTest.java +++ b/src/test/java/graphql/annotations/GraphQLConnectionTest.java @@ -16,7 +16,14 @@ import graphql.ExecutionResult; import graphql.GraphQL; -import graphql.annotations.util.CustomRelay; +import graphql.annotations.annotations.GraphQLConnection; +import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.annotations.GraphQLNonNull; +import graphql.annotations.dataFetchers.connection.Connection; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.util.CustomRelay; import graphql.relay.Relay; import graphql.schema.DataFetchingEnvironment; import graphql.schema.GraphQLList; @@ -30,7 +37,7 @@ import java.util.Map; import java.util.stream.Stream; -import static graphql.annotations.util.RelayKit.EMPTY_CONNECTION; +import static graphql.annotations.processor.util.RelayKit.EMPTY_CONNECTION; import static graphql.schema.GraphQLSchema.newSchema; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; diff --git a/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java b/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java index 189405c7..1e468912 100644 --- a/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java +++ b/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java @@ -16,6 +16,10 @@ import graphql.ExecutionResult; import graphql.GraphQL; +import graphql.annotations.annotations.GraphQLDataFetcher; +import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.processor.GraphQLAnnotations; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; import graphql.schema.GraphQLObjectType; diff --git a/src/test/java/graphql/annotations/GraphQLEnumTest.java b/src/test/java/graphql/annotations/GraphQLEnumTest.java index 881532de..3bbc813e 100644 --- a/src/test/java/graphql/annotations/GraphQLEnumTest.java +++ b/src/test/java/graphql/annotations/GraphQLEnumTest.java @@ -16,17 +16,12 @@ import graphql.ExecutionResult; import graphql.GraphQL; +import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.processor.GraphQLAnnotations; import graphql.schema.*; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import java.lang.reflect.AnnotatedType; -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -import static graphql.schema.GraphQLEnumType.newEnum; import static graphql.schema.GraphQLSchema.newSchema; import static org.testng.Assert.assertEquals; diff --git a/src/test/java/graphql/annotations/GraphQLExtensionsTest.java b/src/test/java/graphql/annotations/GraphQLExtensionsTest.java index 19f4f6d3..9b47f6cc 100644 --- a/src/test/java/graphql/annotations/GraphQLExtensionsTest.java +++ b/src/test/java/graphql/annotations/GraphQLExtensionsTest.java @@ -16,10 +16,11 @@ import graphql.ExecutionResult; import graphql.GraphQL; +import graphql.annotations.annotations.*; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.retrievers.GraphQLObjectHandler; import graphql.schema.*; -import org.testng.Assert; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.util.List; diff --git a/src/test/java/graphql/annotations/GraphQLFragmentTest.java b/src/test/java/graphql/annotations/GraphQLFragmentTest.java index 5357925d..391f8e82 100644 --- a/src/test/java/graphql/annotations/GraphQLFragmentTest.java +++ b/src/test/java/graphql/annotations/GraphQLFragmentTest.java @@ -17,6 +17,10 @@ import graphql.ExecutionResult; import graphql.GraphQL; import graphql.TypeResolutionEnvironment; +import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.annotations.GraphQLTypeResolver; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.retrievers.GraphQLInterfaceRetriever; import graphql.schema.GraphQLInterfaceType; import graphql.schema.GraphQLObjectType; import graphql.schema.GraphQLSchema; diff --git a/src/test/java/graphql/annotations/GraphQLInputTest.java b/src/test/java/graphql/annotations/GraphQLInputTest.java index a3e65b52..cf54bc0e 100644 --- a/src/test/java/graphql/annotations/GraphQLInputTest.java +++ b/src/test/java/graphql/annotations/GraphQLInputTest.java @@ -17,6 +17,11 @@ import graphql.ExecutionResult; import graphql.GraphQL; import graphql.TypeResolutionEnvironment; +import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.annotations.GraphQLTypeResolver; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.schema.*; import org.testng.annotations.Test; diff --git a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java index 24b86a32..4ea60594 100644 --- a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java +++ b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java @@ -17,6 +17,13 @@ import graphql.ExecutionResult; import graphql.GraphQL; import graphql.TypeResolutionEnvironment; +import graphql.annotations.annotations.GraphQLDataFetcher; +import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.annotations.GraphQLTypeResolver; +import graphql.annotations.annotations.GraphQLUnion; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.retrievers.GraphQLInterfaceRetriever; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; import graphql.schema.GraphQLFieldDefinition; diff --git a/src/test/java/graphql/annotations/GraphQLObjectTest.java b/src/test/java/graphql/annotations/GraphQLObjectTest.java index f96e84fd..f963bc66 100644 --- a/src/test/java/graphql/annotations/GraphQLObjectTest.java +++ b/src/test/java/graphql/annotations/GraphQLObjectTest.java @@ -17,6 +17,13 @@ import graphql.ExecutionResult; import graphql.GraphQL; import graphql.Scalars; +import graphql.annotations.annotations.*; +import graphql.annotations.dataFetchers.ExtensionDataFetcherWrapper; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.retrievers.GraphQLInputObjectRetriever; +import graphql.annotations.processor.retrievers.GraphQLObjectHandler; +import graphql.annotations.processor.typeFunctions.TypeFunction; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; @@ -535,7 +542,7 @@ public void customType() { private static class TestCustomTypeFunction { @GraphQLField - @graphql.annotations.GraphQLType(UUIDTypeFunction.class) + @graphql.annotations.annotations.GraphQLType(UUIDTypeFunction.class) public UUID id() { return UUID.randomUUID(); } diff --git a/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java b/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java index b80671ad..a5e186f6 100644 --- a/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java +++ b/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java @@ -16,6 +16,10 @@ import graphql.ExecutionResult; import graphql.GraphQL; +import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.annotations.GraphQLInvokeDetached; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.retrievers.GraphQLObjectHandler; import graphql.schema.GraphQLObjectType; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff --git a/src/test/java/graphql/annotations/MethodDataFetcherTest.java b/src/test/java/graphql/annotations/MethodDataFetcherTest.java index ada01b30..a619ede2 100644 --- a/src/test/java/graphql/annotations/MethodDataFetcherTest.java +++ b/src/test/java/graphql/annotations/MethodDataFetcherTest.java @@ -14,6 +14,8 @@ */ package graphql.annotations; +import graphql.annotations.dataFetchers.MethodDataFetcher; +import graphql.annotations.processor.GraphQLAnnotations; import graphql.schema.DataFetchingEnvironmentImpl; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff --git a/src/test/java/graphql/annotations/RelayTest.java b/src/test/java/graphql/annotations/RelayTest.java index 2fe9d2b6..a9bbe558 100644 --- a/src/test/java/graphql/annotations/RelayTest.java +++ b/src/test/java/graphql/annotations/RelayTest.java @@ -17,6 +17,9 @@ import graphql.ExecutionResult; import graphql.GraphQL; import graphql.TypeResolutionEnvironment; +import graphql.annotations.annotations.*; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.strategies.EnhancedExecutionStrategy; import graphql.schema.*; import graphql.schema.GraphQLNonNull; import graphql.schema.GraphQLType; diff --git a/src/test/java/graphql/annotations/typeFunctions/BooleanFunctionTests.java b/src/test/java/graphql/annotations/processor/typeFunctions/BooleanFunctionTests.java similarity index 84% rename from src/test/java/graphql/annotations/typeFunctions/BooleanFunctionTests.java rename to src/test/java/graphql/annotations/processor/typeFunctions/BooleanFunctionTests.java index 35356793..23aa76f7 100644 --- a/src/test/java/graphql/annotations/typeFunctions/BooleanFunctionTests.java +++ b/src/test/java/graphql/annotations/processor/typeFunctions/BooleanFunctionTests.java @@ -12,15 +12,15 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.processor.GraphQLAnnotations; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static graphql.Scalars.GraphQLBoolean; import static org.testng.Assert.assertEquals; -import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.processor.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class BooleanFunctionTests { diff --git a/src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTest.java b/src/test/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunctionTest.java similarity index 88% rename from src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTest.java rename to src/test/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunctionTest.java index 84666bf2..58ea6773 100644 --- a/src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTest.java +++ b/src/test/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunctionTest.java @@ -12,9 +12,14 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; - -import graphql.annotations.*; +package graphql.annotations.processor.typeFunctions; + +import graphql.annotations.annotations.GraphQLDescription; +import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.annotations.GraphQLID; +import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.*; import graphql.schema.GraphQLType; import org.testng.annotations.BeforeMethod; @@ -38,7 +43,7 @@ private enum A { @GraphQLName("someA") @GraphQLDescription("a") A, B } - public @graphql.annotations.GraphQLID String idStringMethod() { + public @GraphQLID String idStringMethod() { return "asd"; } @@ -73,28 +78,28 @@ public void enumeration() { @SuppressWarnings("unused") - public List> listMethod() { + public List> listMethod() { return null; } @SuppressWarnings("unused") - public Iterable> iterableMethod() { + public Iterable> iterableMethod() { return null; } @SuppressWarnings("unused") - public Collection> collectionMethod() { + public Collection> collectionMethod() { return null; } @SuppressWarnings("unused") - public Stream> streamMethod() { + public Stream> streamMethod() { return null; } @SuppressWarnings("unused") - public Set> setMethod() { + public Set> setMethod() { return null; } @@ -151,7 +156,7 @@ public void unparameterizedList() { } @SuppressWarnings("unused") - public Optional> optionalMethod() { + public Optional> optionalMethod() { return Optional.empty(); } diff --git a/src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTestHelper.java b/src/test/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunctionTestHelper.java similarity index 79% rename from src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTestHelper.java rename to src/test/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunctionTestHelper.java index fc0f0d4b..061814ce 100644 --- a/src/test/java/graphql/annotations/typeFunctions/DefaultTypeFunctionTestHelper.java +++ b/src/test/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunctionTestHelper.java @@ -12,11 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.GraphQLAnnotations; -import graphql.annotations.graphQLProcessors.GraphQLInputProcessor; -import graphql.annotations.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.processor.graphQLProcessors.GraphQLOutputProcessor; public class DefaultTypeFunctionTestHelper { public static DefaultTypeFunction testedDefaultTypeFunction() { diff --git a/src/test/java/graphql/annotations/typeFunctions/FloatFunctionTests.java b/src/test/java/graphql/annotations/processor/typeFunctions/FloatFunctionTests.java similarity index 85% rename from src/test/java/graphql/annotations/typeFunctions/FloatFunctionTests.java rename to src/test/java/graphql/annotations/processor/typeFunctions/FloatFunctionTests.java index b0484686..68b6f87e 100644 --- a/src/test/java/graphql/annotations/typeFunctions/FloatFunctionTests.java +++ b/src/test/java/graphql/annotations/processor/typeFunctions/FloatFunctionTests.java @@ -12,15 +12,15 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.processor.GraphQLAnnotations; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static graphql.Scalars.GraphQLFloat; import static org.testng.Assert.assertEquals; -import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.processor.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class FloatFunctionTests { diff --git a/src/test/java/graphql/annotations/typeFunctions/IDFunctionTests.java b/src/test/java/graphql/annotations/processor/typeFunctions/IDFunctionTests.java similarity index 91% rename from src/test/java/graphql/annotations/typeFunctions/IDFunctionTests.java rename to src/test/java/graphql/annotations/processor/typeFunctions/IDFunctionTests.java index 255e3d10..c7086c18 100644 --- a/src/test/java/graphql/annotations/typeFunctions/IDFunctionTests.java +++ b/src/test/java/graphql/annotations/processor/typeFunctions/IDFunctionTests.java @@ -12,10 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.GraphQLAnnotations; -import graphql.annotations.GraphQLID; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.annotations.GraphQLID; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -24,7 +24,7 @@ import static graphql.Scalars.GraphQLID; import static org.testng.Assert.assertEquals; -import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.processor.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class IDFunctionTests { @@ -34,7 +34,7 @@ public void init() { GraphQLAnnotations.getInstance().getTypeRegistry().clear(); } - public @graphql.annotations.GraphQLID String idStringMethod() { + public @graphql.annotations.annotations.GraphQLID String idStringMethod() { return "asd"; } diff --git a/src/test/java/graphql/annotations/typeFunctions/IntegerFunctionTests.java b/src/test/java/graphql/annotations/processor/typeFunctions/IntegerFunctionTests.java similarity index 84% rename from src/test/java/graphql/annotations/typeFunctions/IntegerFunctionTests.java rename to src/test/java/graphql/annotations/processor/typeFunctions/IntegerFunctionTests.java index f1b84338..50cfeb04 100644 --- a/src/test/java/graphql/annotations/typeFunctions/IntegerFunctionTests.java +++ b/src/test/java/graphql/annotations/processor/typeFunctions/IntegerFunctionTests.java @@ -12,15 +12,15 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.processor.GraphQLAnnotations; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static graphql.Scalars.GraphQLInt; import static org.testng.Assert.assertEquals; -import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.processor.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class IntegerFunctionTests { diff --git a/src/test/java/graphql/annotations/typeFunctions/LongFunctionTests.java b/src/test/java/graphql/annotations/processor/typeFunctions/LongFunctionTests.java similarity index 84% rename from src/test/java/graphql/annotations/typeFunctions/LongFunctionTests.java rename to src/test/java/graphql/annotations/processor/typeFunctions/LongFunctionTests.java index 0da0be9c..9468a93b 100644 --- a/src/test/java/graphql/annotations/typeFunctions/LongFunctionTests.java +++ b/src/test/java/graphql/annotations/processor/typeFunctions/LongFunctionTests.java @@ -12,16 +12,16 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.processor.GraphQLAnnotations; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static graphql.Scalars.GraphQLLong; import static org.testng.Assert.assertEquals; -import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.processor.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class LongFunctionTests { diff --git a/src/test/java/graphql/annotations/typeFunctions/StringFunctionTests.java b/src/test/java/graphql/annotations/processor/typeFunctions/StringFunctionTests.java similarity index 83% rename from src/test/java/graphql/annotations/typeFunctions/StringFunctionTests.java rename to src/test/java/graphql/annotations/processor/typeFunctions/StringFunctionTests.java index 1f2c3820..76b4ca2b 100644 --- a/src/test/java/graphql/annotations/typeFunctions/StringFunctionTests.java +++ b/src/test/java/graphql/annotations/processor/typeFunctions/StringFunctionTests.java @@ -12,15 +12,15 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.typeFunctions; +package graphql.annotations.processor.typeFunctions; -import graphql.annotations.GraphQLAnnotations; +import graphql.annotations.processor.GraphQLAnnotations; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static graphql.Scalars.GraphQLString; import static org.testng.Assert.assertEquals; -import static graphql.annotations.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; +import static graphql.annotations.processor.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction; public class StringFunctionTests { diff --git a/src/test/java/graphql/annotations/util/CustomRelay.java b/src/test/java/graphql/annotations/processor/util/CustomRelay.java similarity index 98% rename from src/test/java/graphql/annotations/util/CustomRelay.java rename to src/test/java/graphql/annotations/processor/util/CustomRelay.java index 96d84ff9..a285dd37 100644 --- a/src/test/java/graphql/annotations/util/CustomRelay.java +++ b/src/test/java/graphql/annotations/processor/util/CustomRelay.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.util; +package graphql.annotations.processor.util; import graphql.relay.Relay; import graphql.schema.*; diff --git a/src/test/java/graphql/annotations/util/NamingKitTest.java b/src/test/java/graphql/annotations/processor/util/NamingKitTest.java similarity index 97% rename from src/test/java/graphql/annotations/util/NamingKitTest.java rename to src/test/java/graphql/annotations/processor/util/NamingKitTest.java index 1b6157b2..4dca6a90 100644 --- a/src/test/java/graphql/annotations/util/NamingKitTest.java +++ b/src/test/java/graphql/annotations/processor/util/NamingKitTest.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.util; +package graphql.annotations.processor.util; import org.testng.annotations.Test; From f05ca9fa599e5268fd15dca9958bb4bfa29f1a29 Mon Sep 17 00:00:00 2001 From: yarinvak Date: Wed, 1 Nov 2017 16:21:02 +0200 Subject: [PATCH 16/25] organize & remove unused class --- .../GraphQLObjectBackedByClass.java | 19 ------------------- .../CannotCastMemberException.java | 2 +- .../retrievers/GraphQLFieldRetriever.java | 2 +- .../retrievers/GraphQLObjectHandler.java | 2 +- .../GraphQLOutputObjectRetriever.java | 2 +- .../searchAlgorithms/BreadthFirstSearch.java | 1 + .../searchAlgorithms/ParentalSearch.java | 1 + .../searchAlgorithms/SearchAlgorithm.java | 2 ++ .../typeBuilders/InterfaceBuilder.java | 2 +- 9 files changed, 9 insertions(+), 24 deletions(-) delete mode 100644 src/main/java/graphql/annotations/GraphQLObjectBackedByClass.java rename src/main/java/graphql/annotations/processor/{searchAlgorithms => exceptions}/CannotCastMemberException.java (94%) diff --git a/src/main/java/graphql/annotations/GraphQLObjectBackedByClass.java b/src/main/java/graphql/annotations/GraphQLObjectBackedByClass.java deleted file mode 100644 index cc9fc047..00000000 --- a/src/main/java/graphql/annotations/GraphQLObjectBackedByClass.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright 2016 Yurii Rashkovskii - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - */ -package graphql.annotations; - -public interface GraphQLObjectBackedByClass { - Class getObjectClass(); -} diff --git a/src/main/java/graphql/annotations/processor/searchAlgorithms/CannotCastMemberException.java b/src/main/java/graphql/annotations/processor/exceptions/CannotCastMemberException.java similarity index 94% rename from src/main/java/graphql/annotations/processor/searchAlgorithms/CannotCastMemberException.java rename to src/main/java/graphql/annotations/processor/exceptions/CannotCastMemberException.java index 3c0ebb97..ee448e77 100644 --- a/src/main/java/graphql/annotations/processor/searchAlgorithms/CannotCastMemberException.java +++ b/src/main/java/graphql/annotations/processor/exceptions/CannotCastMemberException.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.processor.searchAlgorithms; +package graphql.annotations.processor.exceptions; public class CannotCastMemberException extends RuntimeException { diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java index 0d9a8afe..5454eb71 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java @@ -26,7 +26,7 @@ import graphql.annotations.dataFetchers.ExtensionDataFetcherWrapper; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; -import graphql.annotations.processor.searchAlgorithms.CannotCastMemberException; +import graphql.annotations.processor.exceptions.CannotCastMemberException; import graphql.annotations.processor.searchAlgorithms.ParentalSearch; import graphql.annotations.processor.typeFunctions.BatchedTypeFunction; import graphql.annotations.processor.typeFunctions.TypeFunction; diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectHandler.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectHandler.java index 405c2287..02218339 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectHandler.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectHandler.java @@ -16,7 +16,7 @@ import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.ProcessingElementsContainer; -import graphql.annotations.processor.searchAlgorithms.CannotCastMemberException; +import graphql.annotations.processor.exceptions.CannotCastMemberException; import graphql.schema.GraphQLObjectType; import graphql.schema.GraphQLOutputType; diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java index ade9e1b8..67e50e02 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java @@ -23,7 +23,7 @@ import graphql.annotations.processor.typeBuilders.ObjectBuilder; import graphql.annotations.processor.typeBuilders.UnionBuilder; import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; -import graphql.annotations.processor.searchAlgorithms.CannotCastMemberException; +import graphql.annotations.processor.exceptions.CannotCastMemberException; import graphql.annotations.processor.searchAlgorithms.ParentalSearch; import graphql.schema.GraphQLOutputType; diff --git a/src/main/java/graphql/annotations/processor/searchAlgorithms/BreadthFirstSearch.java b/src/main/java/graphql/annotations/processor/searchAlgorithms/BreadthFirstSearch.java index 0f56cf21..71dc67d5 100644 --- a/src/main/java/graphql/annotations/processor/searchAlgorithms/BreadthFirstSearch.java +++ b/src/main/java/graphql/annotations/processor/searchAlgorithms/BreadthFirstSearch.java @@ -14,6 +14,7 @@ */ package graphql.annotations.processor.searchAlgorithms; +import graphql.annotations.processor.exceptions.CannotCastMemberException; import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; import java.lang.reflect.Member; diff --git a/src/main/java/graphql/annotations/processor/searchAlgorithms/ParentalSearch.java b/src/main/java/graphql/annotations/processor/searchAlgorithms/ParentalSearch.java index c56952fd..c4286268 100644 --- a/src/main/java/graphql/annotations/processor/searchAlgorithms/ParentalSearch.java +++ b/src/main/java/graphql/annotations/processor/searchAlgorithms/ParentalSearch.java @@ -14,6 +14,7 @@ */ package graphql.annotations.processor.searchAlgorithms; +import graphql.annotations.processor.exceptions.CannotCastMemberException; import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; import java.lang.reflect.Field; diff --git a/src/main/java/graphql/annotations/processor/searchAlgorithms/SearchAlgorithm.java b/src/main/java/graphql/annotations/processor/searchAlgorithms/SearchAlgorithm.java index c4e3448e..6f00206b 100644 --- a/src/main/java/graphql/annotations/processor/searchAlgorithms/SearchAlgorithm.java +++ b/src/main/java/graphql/annotations/processor/searchAlgorithms/SearchAlgorithm.java @@ -14,6 +14,8 @@ */ package graphql.annotations.processor.searchAlgorithms; +import graphql.annotations.processor.exceptions.CannotCastMemberException; + import java.lang.reflect.Member; public interface SearchAlgorithm { diff --git a/src/main/java/graphql/annotations/processor/typeBuilders/InterfaceBuilder.java b/src/main/java/graphql/annotations/processor/typeBuilders/InterfaceBuilder.java index 99e9607e..c36a3f56 100644 --- a/src/main/java/graphql/annotations/processor/typeBuilders/InterfaceBuilder.java +++ b/src/main/java/graphql/annotations/processor/typeBuilders/InterfaceBuilder.java @@ -20,7 +20,7 @@ import graphql.annotations.processor.ProcessingElementsContainer; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.retrievers.GraphQLFieldRetriever; -import graphql.annotations.processor.searchAlgorithms.CannotCastMemberException; +import graphql.annotations.processor.exceptions.CannotCastMemberException; import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; import graphql.schema.GraphQLFieldDefinition; import graphql.schema.GraphQLInterfaceType; From ee968e154cc60a0dfa06ab4824f34c421f33358e Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 1 Nov 2017 16:22:36 +0200 Subject: [PATCH 17/25] add java doc --- .../annotations/MethodDataFetcher.java | 23 +++++++++---------- .../graphql/annotations/TypeFunction.java | 18 ++++++++++----- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/graphql/annotations/MethodDataFetcher.java b/src/main/java/graphql/annotations/MethodDataFetcher.java index 0b610acc..a90d3e12 100644 --- a/src/main/java/graphql/annotations/MethodDataFetcher.java +++ b/src/main/java/graphql/annotations/MethodDataFetcher.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -32,10 +32,9 @@ class MethodDataFetcher implements DataFetcher { private final TypeFunction typeFunction; - - public MethodDataFetcher(Method method,TypeFunction typeFunction, ProcessingElementsContainer container) { + public MethodDataFetcher(Method method, TypeFunction typeFunction, ProcessingElementsContainer container) { this.method = method; - this.typeFunction=typeFunction; + this.typeFunction = typeFunction; this.container = container; } @@ -56,15 +55,15 @@ public Object get(DataFetchingEnvironment environment) { return null; } } - return method.invoke(obj, invocationArgs(environment,container)); + return method.invoke(obj, invocationArgs(environment, container)); } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } - private Object[] invocationArgs(DataFetchingEnvironment environment,ProcessingElementsContainer container) { + private Object[] invocationArgs(DataFetchingEnvironment environment, ProcessingElementsContainer container) { List result = new ArrayList<>(); - Map envArgs = environment.getArguments(); + Map envArgs = environment.getArguments(); for (Parameter p : method.getParameters()) { String parameterName; GraphQLName name = p.getAnnotation(GraphQLName.class); @@ -80,7 +79,7 @@ private Object[] invocationArgs(DataFetchingEnvironment environment,ProcessingEl continue; } - graphql.schema.GraphQLType graphQLType = typeFunction.buildType(true, paramType, p.getAnnotatedType(),container); + graphql.schema.GraphQLType graphQLType = typeFunction.buildType(true, paramType, p.getAnnotatedType(), container); if (envArgs.containsKey(parameterName)) { result.add(buildArg(p.getParameterizedType(), graphQLType, envArgs.get(parameterName))); } else { @@ -108,7 +107,7 @@ private Object buildArg(Type p, GraphQLType graphQLType, Object arg) { Map map = (Map) arg; for (Parameter parameter : parameters) { String name = toGraphqlName(parameter.getAnnotation(GraphQLName.class) != null ? parameter.getAnnotation(GraphQLName.class).value() : parameter.getName()); - objects.add(buildArg(parameter.getParameterizedType(), ((GraphQLInputObjectType)graphQLType).getField(name).getType(),map.get(name))); + objects.add(buildArg(parameter.getParameterizedType(), ((GraphQLInputObjectType) graphQLType).getField(name).getType(), map.get(name))); } return constructNewInstance(constructor, objects.toArray(new Object[objects.size()])); } @@ -116,7 +115,7 @@ private Object buildArg(Type p, GraphQLType graphQLType, Object arg) { return null; } else if (p instanceof ParameterizedType && graphQLType instanceof GraphQLList) { List list = new ArrayList<>(); - Type subType = ((ParameterizedType)p).getActualTypeArguments()[0]; + Type subType = ((ParameterizedType) p).getActualTypeArguments()[0]; GraphQLType wrappedType = ((GraphQLList) graphQLType).getWrappedType(); for (Object item : ((List) arg)) { diff --git a/src/main/java/graphql/annotations/TypeFunction.java b/src/main/java/graphql/annotations/TypeFunction.java index 30f49944..8fd7b921 100644 --- a/src/main/java/graphql/annotations/TypeFunction.java +++ b/src/main/java/graphql/annotations/TypeFunction.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -42,10 +42,16 @@ default String getTypeName(Class aClass, AnnotatedType annotatedType) { */ boolean canBuildType(Class aClass, AnnotatedType annotatedType); - + /** + * + * @param aClass The java type to build the type name for + * @param annotatedType The {@link AnnotatedType} of the java type, which may be a {link AnnotatedParameterizedType} + * @param container a class that hold several members that are required in order to build schema + * @return The built + */ default GraphQLType buildType(Class aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) { - return buildType(false, aClass, annotatedType,container); + return buildType(false, aClass, annotatedType, container); } /** From 8007db35586a7039c7d598ab19c089fbdb5ae753 Mon Sep 17 00:00:00 2001 From: Yarin Date: Wed, 1 Nov 2017 21:52:50 +0200 Subject: [PATCH 18/25] fix build --- .../GraphQLBatched.java | 2 +- .../GraphQLConnection.java | 2 +- .../GraphQLDataFetcher.java | 2 +- .../GraphQLDefaultValue.java | 2 +- .../GraphQLDeprecate.java | 2 +- .../GraphQLDescription.java | 2 +- .../GraphQLField.java | 2 +- .../GraphQLID.java | 2 +- .../GraphQLInvokeDetached.java | 2 +- .../GraphQLMutation.java | 2 +- .../GraphQLName.java | 2 +- .../GraphQLNonNull.java | 2 +- .../GraphQLRelayMutation.java | 2 +- .../GraphQLType.java | 2 +- .../GraphQLTypeExtension.java | 2 +- .../GraphQLTypeResolver.java | 2 +- .../GraphQLUnion.java | 2 +- .../dataFetchers/MethodDataFetcher.java | 4 +-- .../processor/GraphQLAnnotations.java | 4 +-- .../GraphQLAnnotationsProcessor.java | 4 +-- .../retrievers/GraphQLFieldRetriever.java | 4 +-- .../retrievers/GraphQLInterfaceRetriever.java | 7 +++-- .../GraphQLObjectInfoRetriever.java | 4 +-- .../GraphQLOutputObjectRetriever.java | 31 ++++++++++--------- .../processor/typeBuilders/EnumBuilder.java | 4 +-- .../typeBuilders/InterfaceBuilder.java | 6 ++-- .../processor/typeBuilders/ObjectBuilder.java | 5 ++- .../processor/typeBuilders/UnionBuilder.java | 6 ++-- .../typeFunctions/DefaultTypeFunction.java | 2 +- .../processor/typeFunctions/IDFunction.java | 2 +- .../typeFunctions/ObjectFunction.java | 2 +- .../annotations/GraphQLBatchedTest.java | 4 +-- .../annotations/GraphQLConnectionTest.java | 8 ++--- .../annotations/GraphQLDataFetcherTest.java | 6 ++-- .../graphql/annotations/GraphQLEnumTest.java | 2 +- .../annotations/GraphQLExtensionsTest.java | 2 +- .../annotations/GraphQLFragmentTest.java | 4 +-- .../graphql/annotations/GraphQLInputTest.java | 6 ++-- .../annotations/GraphQLInterfaceTest.java | 8 ++--- .../annotations/GraphQLObjectTest.java | 4 +-- .../annotations/GraphQLSimpleSchemaTest.java | 4 +-- .../java/graphql/annotations/RelayTest.java | 2 +- .../DefaultTypeFunctionTest.java | 20 ++++++------ .../typeFunctions/IDFunctionTests.java | 4 +-- 44 files changed, 98 insertions(+), 95 deletions(-) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLBatched.java (94%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLConnection.java (97%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLDataFetcher.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLDefaultValue.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLDeprecate.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLDescription.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLField.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLID.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLInvokeDetached.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLMutation.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLName.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLNonNull.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLRelayMutation.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLType.java (96%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLTypeExtension.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLTypeResolver.java (95%) rename src/main/java/graphql/annotations/{annotations => annotationTypes}/GraphQLUnion.java (95%) diff --git a/src/main/java/graphql/annotations/annotations/GraphQLBatched.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLBatched.java similarity index 94% rename from src/main/java/graphql/annotations/annotations/GraphQLBatched.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLBatched.java index a04684e8..e3c20fdf 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLBatched.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLBatched.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLConnection.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLConnection.java similarity index 97% rename from src/main/java/graphql/annotations/annotations/GraphQLConnection.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLConnection.java index b5af444b..fe5c99db 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLConnection.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLConnection.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import graphql.annotations.dataFetchers.connection.Connection; import graphql.annotations.dataFetchers.connection.DispatchingConnection; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLDataFetcher.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLDataFetcher.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLDataFetcher.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLDataFetcher.java index 98830d7d..d32b6b74 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLDataFetcher.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLDataFetcher.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import graphql.schema.DataFetcher; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLDefaultValue.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLDefaultValue.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLDefaultValue.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLDefaultValue.java index a16c03b5..591d2b6b 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLDefaultValue.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLDefaultValue.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLDeprecate.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLDeprecate.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLDeprecate.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLDeprecate.java index e79a0e69..fbbb91c6 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLDeprecate.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLDeprecate.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLDescription.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLDescription.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLDescription.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLDescription.java index 1e70ef29..bbedc01d 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLDescription.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLDescription.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLField.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLField.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLField.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLField.java index bf751f16..9102836d 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLField.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLField.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLID.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLID.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLID.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLID.java index 9c5cab92..99f3d3cc 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLID.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLID.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLInvokeDetached.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLInvokeDetached.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLInvokeDetached.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLInvokeDetached.java index cdbaa6aa..817f540a 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLInvokeDetached.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLInvokeDetached.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLMutation.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLMutation.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLMutation.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLMutation.java index 02b6f779..fd14aefb 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLMutation.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLMutation.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLName.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLName.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLName.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLName.java index b8defb08..8c4c2f1b 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLName.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLName.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLNonNull.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLNonNull.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLNonNull.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLNonNull.java index 92f67679..d9fbbbe8 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLNonNull.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLNonNull.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLRelayMutation.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLRelayMutation.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLRelayMutation.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLRelayMutation.java index 375afeca..fc0bde56 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLRelayMutation.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLRelayMutation.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLType.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLType.java similarity index 96% rename from src/main/java/graphql/annotations/annotations/GraphQLType.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLType.java index 94dff3a4..3e788f12 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLType.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLType.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import graphql.annotations.processor.typeFunctions.TypeFunction; import graphql.annotations.processor.typeFunctions.DefaultTypeFunction; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLTypeExtension.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLTypeExtension.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLTypeExtension.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLTypeExtension.java index 5004d5d8..b292eede 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLTypeExtension.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLTypeExtension.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLTypeResolver.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLTypeResolver.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLTypeResolver.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLTypeResolver.java index 572ee563..54235a24 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLTypeResolver.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLTypeResolver.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import graphql.schema.TypeResolver; diff --git a/src/main/java/graphql/annotations/annotations/GraphQLUnion.java b/src/main/java/graphql/annotations/annotationTypes/GraphQLUnion.java similarity index 95% rename from src/main/java/graphql/annotations/annotations/GraphQLUnion.java rename to src/main/java/graphql/annotations/annotationTypes/GraphQLUnion.java index 6e61f7f6..8d7d5147 100644 --- a/src/main/java/graphql/annotations/annotations/GraphQLUnion.java +++ b/src/main/java/graphql/annotations/annotationTypes/GraphQLUnion.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.annotations; +package graphql.annotations.annotationTypes; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java b/src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java index 507c1014..59f54661 100644 --- a/src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java +++ b/src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java @@ -15,8 +15,8 @@ package graphql.annotations.dataFetchers; import graphql.annotations.processor.ProcessingElementsContainer; -import graphql.annotations.annotations.GraphQLInvokeDetached; -import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLInvokeDetached; +import graphql.annotations.annotationTypes.GraphQLName; import graphql.annotations.processor.typeFunctions.TypeFunction; import graphql.schema.*; import graphql.schema.GraphQLType; diff --git a/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java b/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java index 0fd625a6..be3d8ba6 100644 --- a/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java @@ -16,8 +16,8 @@ import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.retrievers.GraphQLObjectHandler; -import graphql.annotations.annotations.GraphQLName; -import graphql.annotations.annotations.GraphQLTypeExtension; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLTypeExtension; import graphql.annotations.processor.graphQLProcessors.GraphQLAnnotationsProcessor; import graphql.annotations.processor.graphQLProcessors.GraphQLInputProcessor; import graphql.annotations.processor.graphQLProcessors.GraphQLOutputProcessor; diff --git a/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java b/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java index 0e43f7fe..aea5763a 100644 --- a/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java +++ b/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java @@ -12,12 +12,12 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.processor.graphQLProcessors; public interface GraphQLAnnotationsProcessor { /** * Register a new type extension class. This extension will be used when the extended object will be created. - * The class must have a {@link GraphQLTypeExtension} annotation. + * The class must have a {@link graphql.annotations.annotationTypes.GraphQLTypeExtension} annotation. * * @param objectClass The extension class to register */ diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java index 5454eb71..0cae89ee 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java @@ -18,8 +18,8 @@ import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.ProcessingElementsContainer; import graphql.annotations.dataFetchers.RelayMutationMethodDataFetcher; -import graphql.annotations.annotations.*; -import graphql.annotations.annotations.GraphQLType; +import graphql.annotations.annotationTypes.*; +import graphql.annotations.annotationTypes.GraphQLType; import graphql.annotations.dataFetchers.BatchedMethodDataFetcher; import graphql.annotations.dataFetchers.MethodDataFetcher; import graphql.annotations.dataFetchers.connection.ConnectionDataFetcher; diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLInterfaceRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLInterfaceRetriever.java index bf842b53..c97e11cb 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLInterfaceRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLInterfaceRetriever.java @@ -12,10 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations; +package graphql.annotations.processor.retrievers; -import graphql.annotations.util.GraphQLOutputObjectRetriever; -import graphql.schema.GraphQLUnionType; + +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; public class GraphQLInterfaceRetriever { diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectInfoRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectInfoRetriever.java index 912c5789..2f7bc6a7 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectInfoRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLObjectInfoRetriever.java @@ -15,8 +15,8 @@ package graphql.annotations.processor.retrievers; -import graphql.annotations.annotations.GraphQLField; -import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java index 984a4898..431e3748 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java @@ -12,16 +12,19 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and */ -package graphql.annotations.util; +package graphql.annotations.processor.retrievers; -import graphql.annotations.*; -import graphql.annotations.builders.EnumBuilder; -import graphql.annotations.builders.InterfaceBuilder; -import graphql.annotations.builders.ObjectBuilder; -import graphql.annotations.builders.UnionBuilder; -import graphql.annotations.searchAlgorithms.BreadthFirstSearch; -import graphql.annotations.searchAlgorithms.CannotCastMemberException; -import graphql.annotations.searchAlgorithms.ParentalSearch; +import graphql.annotations.annotationTypes.GraphQLTypeResolver; +import graphql.annotations.annotationTypes.GraphQLUnion; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.exceptions.CannotCastMemberException; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; +import graphql.annotations.processor.searchAlgorithms.ParentalSearch; +import graphql.annotations.processor.typeBuilders.EnumBuilder; +import graphql.annotations.processor.typeBuilders.InterfaceBuilder; +import graphql.annotations.processor.typeBuilders.ObjectBuilder; +import graphql.annotations.processor.typeBuilders.UnionBuilder; import graphql.schema.*; public class GraphQLOutputObjectRetriever { @@ -39,17 +42,17 @@ public GraphQLOutputObjectRetriever() { } /** - * This will examine the object and will return a {@link GraphQLOutputType} based on the class type and annotations. - * - If its annotated with {@link GraphQLUnion} it will return a {@link GraphQLUnionType} - * - If its annotated with {@link GraphQLTypeResolver} it will return a {@link GraphQLInterfaceType} + * This will examine the object and will return a {@link GraphQLOutputType} based on the class type and annotationTypes. + * - If its annotated with {@link graphql.annotations.annotationTypes.GraphQLUnion} it will return a {@link GraphQLUnionType} + * - If its annotated with {@link graphql.annotations.annotationTypes.GraphQLTypeResolver} it will return a {@link GraphQLInterfaceType} * - It it's an Enum it will return a {@link GraphQLEnumType}, * otherwise it will return a {@link GraphQLObjectType}. * * @param object the object class to examine* * @param container a class that hold several members that are required in order to build schema * @return a {@link GraphQLOutputType} that represents that object class - * @throws GraphQLAnnotationsException if the object class cannot be examined - * @throws CannotCastMemberException if the object class cannot be examined + * @throws graphql.annotations.processor.exceptions.GraphQLAnnotationsException if the object class cannot be examined + * @throws graphql.annotations.processor.exceptions.CannotCastMemberException if the object class cannot be examined */ public GraphQLOutputType getOutputType(Class object, ProcessingElementsContainer container) throws GraphQLAnnotationsException, CannotCastMemberException { // because the TypeFunction can call back to this processor and diff --git a/src/main/java/graphql/annotations/processor/typeBuilders/EnumBuilder.java b/src/main/java/graphql/annotations/processor/typeBuilders/EnumBuilder.java index 7fee086c..f5592541 100644 --- a/src/main/java/graphql/annotations/processor/typeBuilders/EnumBuilder.java +++ b/src/main/java/graphql/annotations/processor/typeBuilders/EnumBuilder.java @@ -14,8 +14,8 @@ */ package graphql.annotations.processor.typeBuilders; -import graphql.annotations.annotations.GraphQLDescription; -import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLDescription; +import graphql.annotations.annotationTypes.GraphQLName; import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; import graphql.schema.GraphQLEnumType; diff --git a/src/main/java/graphql/annotations/processor/typeBuilders/InterfaceBuilder.java b/src/main/java/graphql/annotations/processor/typeBuilders/InterfaceBuilder.java index c36a3f56..97702272 100644 --- a/src/main/java/graphql/annotations/processor/typeBuilders/InterfaceBuilder.java +++ b/src/main/java/graphql/annotations/processor/typeBuilders/InterfaceBuilder.java @@ -14,9 +14,9 @@ */ package graphql.annotations.processor.typeBuilders; -import graphql.annotations.annotations.GraphQLDescription; -import graphql.annotations.annotations.GraphQLField; -import graphql.annotations.annotations.GraphQLTypeResolver; +import graphql.annotations.annotationTypes.GraphQLDescription; +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLTypeResolver; import graphql.annotations.processor.ProcessingElementsContainer; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.retrievers.GraphQLFieldRetriever; diff --git a/src/main/java/graphql/annotations/processor/typeBuilders/ObjectBuilder.java b/src/main/java/graphql/annotations/processor/typeBuilders/ObjectBuilder.java index 615aa143..4db5214e 100644 --- a/src/main/java/graphql/annotations/processor/typeBuilders/ObjectBuilder.java +++ b/src/main/java/graphql/annotations/processor/typeBuilders/ObjectBuilder.java @@ -14,8 +14,8 @@ */ package graphql.annotations.processor.typeBuilders; -import graphql.annotations.annotations.GraphQLDescription; -import graphql.annotations.annotations.GraphQLTypeResolver; +import graphql.annotations.annotationTypes.GraphQLDescription; +import graphql.annotations.annotationTypes.GraphQLTypeResolver; import graphql.annotations.processor.ProcessingElementsContainer; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.retrievers.GraphQLFieldRetriever; @@ -23,7 +23,6 @@ import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; import graphql.annotations.processor.searchAlgorithms.ParentalSearch; import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; -import graphql.annotations.processor.retrievers.GraphQLOutputObjectRetriever; import graphql.schema.GraphQLFieldDefinition; import graphql.schema.GraphQLInterfaceType; import graphql.schema.GraphQLObjectType; diff --git a/src/main/java/graphql/annotations/processor/typeBuilders/UnionBuilder.java b/src/main/java/graphql/annotations/processor/typeBuilders/UnionBuilder.java index 29e982ca..b7f18b3b 100644 --- a/src/main/java/graphql/annotations/processor/typeBuilders/UnionBuilder.java +++ b/src/main/java/graphql/annotations/processor/typeBuilders/UnionBuilder.java @@ -15,9 +15,9 @@ package graphql.annotations.processor.typeBuilders; -import graphql.annotations.annotations.GraphQLDescription; -import graphql.annotations.annotations.GraphQLType; -import graphql.annotations.annotations.GraphQLUnion; +import graphql.annotations.annotationTypes.GraphQLDescription; +import graphql.annotations.annotationTypes.GraphQLType; +import graphql.annotations.annotationTypes.GraphQLUnion; import graphql.annotations.processor.ProcessingElementsContainer; import graphql.annotations.processor.util.ReflectionKit; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; diff --git a/src/main/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunction.java index 95565d16..8c5e28f2 100644 --- a/src/main/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunction.java @@ -15,7 +15,7 @@ package graphql.annotations.processor.typeFunctions; import graphql.annotations.processor.graphQLProcessors.GraphQLAnnotationsProcessor; -import graphql.annotations.annotations.GraphQLNonNull; +import graphql.annotations.annotationTypes.GraphQLNonNull; import graphql.annotations.processor.graphQLProcessors.GraphQLInputProcessor; import graphql.annotations.processor.graphQLProcessors.GraphQLOutputProcessor; import graphql.annotations.processor.ProcessingElementsContainer; diff --git a/src/main/java/graphql/annotations/processor/typeFunctions/IDFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/IDFunction.java index ee1f4395..aa5165ff 100644 --- a/src/main/java/graphql/annotations/processor/typeFunctions/IDFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/IDFunction.java @@ -15,7 +15,7 @@ package graphql.annotations.processor.typeFunctions; import graphql.Scalars; -import graphql.annotations.annotations.GraphQLID; +import graphql.annotations.annotationTypes.GraphQLID; import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.GraphQLType; diff --git a/src/main/java/graphql/annotations/processor/typeFunctions/ObjectFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/ObjectFunction.java index e6edefe0..c262aca9 100644 --- a/src/main/java/graphql/annotations/processor/typeFunctions/ObjectFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/ObjectFunction.java @@ -14,7 +14,7 @@ */ package graphql.annotations.processor.typeFunctions; -import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLName; import graphql.annotations.processor.graphQLProcessors.GraphQLInputProcessor; import graphql.annotations.processor.graphQLProcessors.GraphQLOutputProcessor; import graphql.annotations.processor.ProcessingElementsContainer; diff --git a/src/test/java/graphql/annotations/GraphQLBatchedTest.java b/src/test/java/graphql/annotations/GraphQLBatchedTest.java index 4f1adbd3..ffc93f7c 100644 --- a/src/test/java/graphql/annotations/GraphQLBatchedTest.java +++ b/src/test/java/graphql/annotations/GraphQLBatchedTest.java @@ -17,8 +17,8 @@ import graphql.ExceptionWhileDataFetching; import graphql.ExecutionResult; import graphql.GraphQL; -import graphql.annotations.annotations.GraphQLBatched; -import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLBatched; +import graphql.annotations.annotationTypes.GraphQLField; import graphql.annotations.processor.GraphQLAnnotations; import graphql.execution.batched.BatchedExecutionStrategy; import graphql.schema.GraphQLObjectType; diff --git a/src/test/java/graphql/annotations/GraphQLConnectionTest.java b/src/test/java/graphql/annotations/GraphQLConnectionTest.java index 7290b630..acc739d0 100644 --- a/src/test/java/graphql/annotations/GraphQLConnectionTest.java +++ b/src/test/java/graphql/annotations/GraphQLConnectionTest.java @@ -16,10 +16,10 @@ import graphql.ExecutionResult; import graphql.GraphQL; -import graphql.annotations.annotations.GraphQLConnection; -import graphql.annotations.annotations.GraphQLField; -import graphql.annotations.annotations.GraphQLName; -import graphql.annotations.annotations.GraphQLNonNull; +import graphql.annotations.annotationTypes.GraphQLConnection; +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; import graphql.annotations.dataFetchers.connection.Connection; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; diff --git a/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java b/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java index 1e468912..1279687e 100644 --- a/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java +++ b/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java @@ -16,9 +16,9 @@ import graphql.ExecutionResult; import graphql.GraphQL; -import graphql.annotations.annotations.GraphQLDataFetcher; -import graphql.annotations.annotations.GraphQLField; -import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLDataFetcher; +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; import graphql.annotations.processor.GraphQLAnnotations; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; diff --git a/src/test/java/graphql/annotations/GraphQLEnumTest.java b/src/test/java/graphql/annotations/GraphQLEnumTest.java index 3bbc813e..ca89c72d 100644 --- a/src/test/java/graphql/annotations/GraphQLEnumTest.java +++ b/src/test/java/graphql/annotations/GraphQLEnumTest.java @@ -16,7 +16,7 @@ import graphql.ExecutionResult; import graphql.GraphQL; -import graphql.annotations.annotations.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLField; import graphql.annotations.processor.GraphQLAnnotations; import graphql.schema.*; import org.testng.annotations.BeforeMethod; diff --git a/src/test/java/graphql/annotations/GraphQLExtensionsTest.java b/src/test/java/graphql/annotations/GraphQLExtensionsTest.java index 9b47f6cc..19476156 100644 --- a/src/test/java/graphql/annotations/GraphQLExtensionsTest.java +++ b/src/test/java/graphql/annotations/GraphQLExtensionsTest.java @@ -16,7 +16,7 @@ import graphql.ExecutionResult; import graphql.GraphQL; -import graphql.annotations.annotations.*; +import graphql.annotations.annotationTypes.*; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.retrievers.GraphQLObjectHandler; diff --git a/src/test/java/graphql/annotations/GraphQLFragmentTest.java b/src/test/java/graphql/annotations/GraphQLFragmentTest.java index 391f8e82..157edef7 100644 --- a/src/test/java/graphql/annotations/GraphQLFragmentTest.java +++ b/src/test/java/graphql/annotations/GraphQLFragmentTest.java @@ -17,8 +17,8 @@ import graphql.ExecutionResult; import graphql.GraphQL; import graphql.TypeResolutionEnvironment; -import graphql.annotations.annotations.GraphQLField; -import graphql.annotations.annotations.GraphQLTypeResolver; +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLTypeResolver; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.retrievers.GraphQLInterfaceRetriever; import graphql.schema.GraphQLInterfaceType; diff --git a/src/test/java/graphql/annotations/GraphQLInputTest.java b/src/test/java/graphql/annotations/GraphQLInputTest.java index cf54bc0e..a6f0cf01 100644 --- a/src/test/java/graphql/annotations/GraphQLInputTest.java +++ b/src/test/java/graphql/annotations/GraphQLInputTest.java @@ -17,9 +17,9 @@ import graphql.ExecutionResult; import graphql.GraphQL; import graphql.TypeResolutionEnvironment; -import graphql.annotations.annotations.GraphQLField; -import graphql.annotations.annotations.GraphQLName; -import graphql.annotations.annotations.GraphQLTypeResolver; +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLTypeResolver; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.schema.*; diff --git a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java index 4ea60594..ed401ea1 100644 --- a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java +++ b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java @@ -17,10 +17,10 @@ import graphql.ExecutionResult; import graphql.GraphQL; import graphql.TypeResolutionEnvironment; -import graphql.annotations.annotations.GraphQLDataFetcher; -import graphql.annotations.annotations.GraphQLField; -import graphql.annotations.annotations.GraphQLTypeResolver; -import graphql.annotations.annotations.GraphQLUnion; +import graphql.annotations.annotationTypes.GraphQLDataFetcher; +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLTypeResolver; +import graphql.annotations.annotationTypes.GraphQLUnion; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.retrievers.GraphQLInterfaceRetriever; diff --git a/src/test/java/graphql/annotations/GraphQLObjectTest.java b/src/test/java/graphql/annotations/GraphQLObjectTest.java index f963bc66..3f1c7db7 100644 --- a/src/test/java/graphql/annotations/GraphQLObjectTest.java +++ b/src/test/java/graphql/annotations/GraphQLObjectTest.java @@ -17,7 +17,7 @@ import graphql.ExecutionResult; import graphql.GraphQL; import graphql.Scalars; -import graphql.annotations.annotations.*; +import graphql.annotations.annotationTypes.*; import graphql.annotations.dataFetchers.ExtensionDataFetcherWrapper; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.ProcessingElementsContainer; @@ -542,7 +542,7 @@ public void customType() { private static class TestCustomTypeFunction { @GraphQLField - @graphql.annotations.annotations.GraphQLType(UUIDTypeFunction.class) + @graphql.annotations.annotationTypes.GraphQLType(UUIDTypeFunction.class) public UUID id() { return UUID.randomUUID(); } diff --git a/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java b/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java index a5e186f6..ca4b213a 100644 --- a/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java +++ b/src/test/java/graphql/annotations/GraphQLSimpleSchemaTest.java @@ -16,8 +16,8 @@ import graphql.ExecutionResult; import graphql.GraphQL; -import graphql.annotations.annotations.GraphQLField; -import graphql.annotations.annotations.GraphQLInvokeDetached; +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLInvokeDetached; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.retrievers.GraphQLObjectHandler; import graphql.schema.GraphQLObjectType; diff --git a/src/test/java/graphql/annotations/RelayTest.java b/src/test/java/graphql/annotations/RelayTest.java index a9bbe558..212cd82c 100644 --- a/src/test/java/graphql/annotations/RelayTest.java +++ b/src/test/java/graphql/annotations/RelayTest.java @@ -17,7 +17,7 @@ import graphql.ExecutionResult; import graphql.GraphQL; import graphql.TypeResolutionEnvironment; -import graphql.annotations.annotations.*; +import graphql.annotations.annotationTypes.*; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.strategies.EnhancedExecutionStrategy; import graphql.schema.*; diff --git a/src/test/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunctionTest.java b/src/test/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunctionTest.java index 58ea6773..e27a6a53 100644 --- a/src/test/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunctionTest.java +++ b/src/test/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunctionTest.java @@ -14,10 +14,10 @@ */ package graphql.annotations.processor.typeFunctions; -import graphql.annotations.annotations.GraphQLDescription; -import graphql.annotations.annotations.GraphQLField; -import graphql.annotations.annotations.GraphQLID; -import graphql.annotations.annotations.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLDescription; +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLID; +import graphql.annotations.annotationTypes.GraphQLName; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.ProcessingElementsContainer; import graphql.schema.*; @@ -78,28 +78,28 @@ public void enumeration() { @SuppressWarnings("unused") - public List> listMethod() { + public List> listMethod() { return null; } @SuppressWarnings("unused") - public Iterable> iterableMethod() { + public Iterable> iterableMethod() { return null; } @SuppressWarnings("unused") - public Collection> collectionMethod() { + public Collection> collectionMethod() { return null; } @SuppressWarnings("unused") - public Stream> streamMethod() { + public Stream> streamMethod() { return null; } @SuppressWarnings("unused") - public Set> setMethod() { + public Set> setMethod() { return null; } @@ -156,7 +156,7 @@ public void unparameterizedList() { } @SuppressWarnings("unused") - public Optional> optionalMethod() { + public Optional> optionalMethod() { return Optional.empty(); } diff --git a/src/test/java/graphql/annotations/processor/typeFunctions/IDFunctionTests.java b/src/test/java/graphql/annotations/processor/typeFunctions/IDFunctionTests.java index c7086c18..659f6cdd 100644 --- a/src/test/java/graphql/annotations/processor/typeFunctions/IDFunctionTests.java +++ b/src/test/java/graphql/annotations/processor/typeFunctions/IDFunctionTests.java @@ -15,7 +15,7 @@ package graphql.annotations.processor.typeFunctions; import graphql.annotations.processor.GraphQLAnnotations; -import graphql.annotations.annotations.GraphQLID; +import graphql.annotations.annotationTypes.GraphQLID; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -34,7 +34,7 @@ public void init() { GraphQLAnnotations.getInstance().getTypeRegistry().clear(); } - public @graphql.annotations.annotations.GraphQLID String idStringMethod() { + public @graphql.annotations.annotationTypes.GraphQLID String idStringMethod() { return "asd"; } From ecc67292799471e795fe344bc6fda7b295298290 Mon Sep 17 00:00:00 2001 From: Yarin Date: Wed, 1 Nov 2017 22:01:55 +0200 Subject: [PATCH 19/25] tests fix --- .../dataFetchers/MethodDataFetcher.java | 8 +++--- .../processor/typeFunctions/TypeFunction.java | 8 +++--- .../annotations/GraphQLBatchedTest.java | 10 +++---- .../graphql/annotations/GraphQLInputTest.java | 26 +++++++++---------- .../annotations/GraphQLInterfaceTest.java | 10 +++---- .../annotations/GraphQLObjectTest.java | 14 +++++----- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java b/src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java index 59f54661..782e31a7 100644 --- a/src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java +++ b/src/main/java/graphql/annotations/dataFetchers/MethodDataFetcher.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/graphql/annotations/processor/typeFunctions/TypeFunction.java b/src/main/java/graphql/annotations/processor/typeFunctions/TypeFunction.java index 1951daa8..e099e057 100644 --- a/src/main/java/graphql/annotations/processor/typeFunctions/TypeFunction.java +++ b/src/main/java/graphql/annotations/processor/typeFunctions/TypeFunction.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/test/java/graphql/annotations/GraphQLBatchedTest.java b/src/test/java/graphql/annotations/GraphQLBatchedTest.java index ffc93f7c..a61c3c1b 100644 --- a/src/test/java/graphql/annotations/GraphQLBatchedTest.java +++ b/src/test/java/graphql/annotations/GraphQLBatchedTest.java @@ -43,7 +43,7 @@ public void init() { GraphQLAnnotations.getInstance().getTypeRegistry().clear(); } - private static class SimpleBatchedField { + public static class SimpleBatchedField { @GraphQLField @GraphQLBatched public static List a() { @@ -51,7 +51,7 @@ public static List a() { } } - private static class TestBatchedObject { + public static class TestBatchedObject { @GraphQLField public List fields() { return Arrays.asList(new SimpleBatchedField(), new SimpleBatchedField()); @@ -78,7 +78,7 @@ public void batchedDataFetcher() throws Throwable { assertEquals(fields.get(1).get("a"), "two"); } - private static class NoStaticBatchedField { + public static class NoStaticBatchedField { @GraphQLField @GraphQLBatched public List a() { @@ -91,7 +91,7 @@ public void noStaticField() { GraphQLObjectType object = GraphQLAnnotations.object(NoStaticBatchedField.class); } - private static class NoListBatchedField { + public static class NoListBatchedField { @GraphQLField @GraphQLBatched public String a() { @@ -104,7 +104,7 @@ public void noListField() { GraphQLObjectType object = GraphQLAnnotations.object(NoStaticBatchedField.class); } - private static class NoParameterizedBatchedField { + public static class NoParameterizedBatchedField { @GraphQLField @GraphQLBatched public List a() { diff --git a/src/test/java/graphql/annotations/GraphQLInputTest.java b/src/test/java/graphql/annotations/GraphQLInputTest.java index a6f0cf01..18f59c31 100644 --- a/src/test/java/graphql/annotations/GraphQLInputTest.java +++ b/src/test/java/graphql/annotations/GraphQLInputTest.java @@ -46,7 +46,7 @@ public GraphQLObjectType getType(TypeResolutionEnvironment env) { } } - static class SubInputObject { + public static class SubInputObject { public SubInputObject(@GraphQLName("subKey") String subKey) { this.subKey = subKey; } @@ -55,7 +55,7 @@ public SubInputObject(@GraphQLName("subKey") String subKey) { private String subKey; } - static class InputObject { + public static class InputObject { public InputObject(@GraphQLName("key") String key, @GraphQLName("complex") List complex) { this.key = key; this.complex = complex; @@ -68,7 +68,7 @@ public InputObject(@GraphQLName("key") String key, @GraphQLName("complex") List< private List complex; } - static class RecursiveInputObject { + public static class RecursiveInputObject { public RecursiveInputObject(@GraphQLName("map") HashMap map) { key = (String) map.get("key"); if (map.containsKey("rec")) { @@ -84,12 +84,12 @@ public RecursiveInputObject(@GraphQLName("map") HashMap map) { } @GraphQLTypeResolver(Resolver.class) - interface TestIface { + public interface TestIface { @GraphQLField String value(@GraphQLName("input") InputObject input); } - static class TestObject implements TestIface { + public static class TestObject implements TestIface { @Override public String value(@GraphQLName("input") InputObject input) { @@ -97,7 +97,7 @@ public String value(@GraphQLName("input") InputObject input) { } } - static class TestObjectList { + public static class TestObjectList { @GraphQLField public String value(@GraphQLName("input") List>> input) { InputObject inputObject = input.get(0).get(0).get(0); @@ -105,14 +105,14 @@ public String value(@GraphQLName("input") List>> input) { } } - static class TestObjectRec { + public static class TestObjectRec { @GraphQLField public String value(@GraphQLName("input") RecursiveInputObject input) { return (input.rec != null ? ("rec"+input.rec.key) : input.key) + "a"; } } - static class Code { + public static class Code { public Code(@GraphQLName("map") HashMap map) { this.firstField = (String) map.get("firstField"); this.secondField = (String) map.get("secondField"); @@ -124,7 +124,7 @@ public Code(@GraphQLName("map") HashMap map) { public String secondField; } - static class QueryMultipleDefinitions { + public static class QueryMultipleDefinitions { @GraphQLField public String something(@GraphQLName("code") Code code) { return code.firstField + code.secondField; @@ -136,28 +136,28 @@ public String somethingElse(@GraphQLName("code") Code code) { } } - static class Query { + public static class Query { @GraphQLField public TestIface object() { return new TestObject(); }; } - static class QueryRecursion { + public static class QueryRecursion { @GraphQLField public TestObjectRec object() { return new TestObjectRec(); }; } - static class QueryList { + public static class QueryList { @GraphQLField public TestObjectList object() { return new TestObjectList(); }; } - static class QueryIface { + public static class QueryIface { @GraphQLField public TestObject iface() { return new TestObject(); diff --git a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java index ed401ea1..3bc065fc 100644 --- a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java +++ b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java @@ -80,20 +80,20 @@ public GraphQLObjectType getType(TypeResolutionEnvironment env) { } @GraphQLTypeResolver(Resolver.class) - interface BaseTestIface { + public interface BaseTestIface { @GraphQLField String value(); } @GraphQLTypeResolver(Resolver.class) - interface TestIface extends BaseTestIface { + public interface TestIface extends BaseTestIface { } @GraphQLUnion(possibleTypes = TestObject1.class) - interface TestUnion extends BaseTestIface { + public interface TestUnion extends BaseTestIface { } - static class TestObject implements TestIface { + public static class TestObject implements TestIface { @Override public String value() { @@ -146,7 +146,7 @@ public Object get(DataFetchingEnvironment environment) { } } - static class Query { + public static class Query { @GraphQLDataFetcher(IfaceFetcher.class) @GraphQLField public TestIface iface; diff --git a/src/test/java/graphql/annotations/GraphQLObjectTest.java b/src/test/java/graphql/annotations/GraphQLObjectTest.java index 3f1c7db7..1fbb675b 100644 --- a/src/test/java/graphql/annotations/GraphQLObjectTest.java +++ b/src/test/java/graphql/annotations/GraphQLObjectTest.java @@ -71,7 +71,7 @@ public Object get() { @GraphQLDescription("TestObject object") @GraphQLName("TestObject") - private static class TestObject { + public static class TestObject { @GraphQLField @GraphQLName("field0") @GraphQLDescription("field") @@ -221,7 +221,7 @@ public void fields() { assertTrue(fields.get(7).getType() instanceof graphql.schema.GraphQLNonNull); } - private static class TestObjectInherited extends TestObject { + public static class TestObjectInherited extends TestObject { @Override @GraphQLName("field1") // Test overriding field public String field() { @@ -245,7 +245,7 @@ public void methodInheritance() { assertEquals(((Map) result.getData()).get("field1"), "inherited"); } - private static class TestObjectBridgMethodParent { + public static class TestObjectBridgMethodParent { private final Type id; public TestObjectBridgMethodParent(Type id) { @@ -257,7 +257,7 @@ public Type id() { } } - private static class TestObjectBridgMethod extends TestObjectBridgMethodParent { + public static class TestObjectBridgMethod extends TestObjectBridgMethodParent { public TestObjectBridgMethod() { super(1L); @@ -554,7 +554,7 @@ public void customTypeFunction() { assertEquals(object.getFieldDefinition("id").getType(), GraphQLString); } - private static class TestInputArgument { + public static class TestInputArgument { @GraphQLField public String a; @GraphQLField @@ -566,7 +566,7 @@ public TestInputArgument(@GraphQLName("a") String a, @GraphQLName("b") int b) { } } - private static class TestComplexInputArgument { + public static class TestComplexInputArgument { public Collection inputs; @@ -583,7 +583,7 @@ public Collection getInputs() { - private static class TestObjectInput { + public static class TestObjectInput { @GraphQLField public String test(@GraphQLName("other") int other, @GraphQLName("arg") TestInputArgument arg) { return arg.a; From 2fd32ec1effd4a07a7f56b2261a826ad2931ebb9 Mon Sep 17 00:00:00 2001 From: Yarin Date: Fri, 3 Nov 2017 13:15:25 +0200 Subject: [PATCH 20/25] better way to build fields - with proper builders --- .../ExtensionDataFetcherWrapper.java | 1 - .../retrievers/GraphQLFieldRetriever.java | 301 +++++------------- .../retrievers/fieldBuilders/Builder.java | 5 + .../field/FieldDataFetcherBuilder.java | 120 +++++++ .../fieldBuilders/field/FieldNameBuilder.java | 22 ++ .../fieldBuilders/method/ArgumentBuilder.java | 77 +++++ .../method/DataFetcherBuilder.java | 67 ++++ .../method/DeprecateBuilder.java | 26 ++ .../method/DescriptionBuilder.java | 20 ++ .../fieldBuilders/method/NameBuilder.java | 24 ++ .../fieldBuilders/method/TypeBuilder.java | 38 +++ .../processor/util/ConnectionUtil.java | 22 ++ .../util/DataFetcherConstructor.java | 35 ++ 13 files changed, 534 insertions(+), 224 deletions(-) create mode 100644 src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/Builder.java create mode 100644 src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldDataFetcherBuilder.java create mode 100644 src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilder.java create mode 100644 src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/ArgumentBuilder.java create mode 100644 src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DataFetcherBuilder.java create mode 100644 src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DeprecateBuilder.java create mode 100644 src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DescriptionBuilder.java create mode 100644 src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/NameBuilder.java create mode 100644 src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/TypeBuilder.java create mode 100644 src/main/java/graphql/annotations/processor/util/ConnectionUtil.java create mode 100644 src/main/java/graphql/annotations/processor/util/DataFetcherConstructor.java diff --git a/src/main/java/graphql/annotations/dataFetchers/ExtensionDataFetcherWrapper.java b/src/main/java/graphql/annotations/dataFetchers/ExtensionDataFetcherWrapper.java index 28867009..09e543bc 100644 --- a/src/main/java/graphql/annotations/dataFetchers/ExtensionDataFetcherWrapper.java +++ b/src/main/java/graphql/annotations/dataFetchers/ExtensionDataFetcherWrapper.java @@ -32,7 +32,6 @@ public ExtensionDataFetcherWrapper(Class declaringClass, DataFetcher dataFetc this.dataFetcher = dataFetcher; } - @SuppressWarnings("unchecked") @Override public T get(DataFetchingEnvironment environment) { Object source = environment.getSource(); diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java index 0cae89ee..ddaaed22 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,19 +17,22 @@ import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.ProcessingElementsContainer; -import graphql.annotations.dataFetchers.RelayMutationMethodDataFetcher; import graphql.annotations.annotationTypes.*; import graphql.annotations.annotationTypes.GraphQLType; -import graphql.annotations.dataFetchers.BatchedMethodDataFetcher; import graphql.annotations.dataFetchers.MethodDataFetcher; import graphql.annotations.dataFetchers.connection.ConnectionDataFetcher; import graphql.annotations.dataFetchers.ExtensionDataFetcherWrapper; import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.retrievers.fieldBuilders.Builder; +import graphql.annotations.processor.retrievers.fieldBuilders.field.FieldDataFetcherBuilder; +import graphql.annotations.processor.retrievers.fieldBuilders.field.FieldNameBuilder; +import graphql.annotations.processor.retrievers.fieldBuilders.method.*; import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; import graphql.annotations.processor.exceptions.CannotCastMemberException; import graphql.annotations.processor.searchAlgorithms.ParentalSearch; -import graphql.annotations.processor.typeFunctions.BatchedTypeFunction; import graphql.annotations.processor.typeFunctions.TypeFunction; +import graphql.annotations.processor.util.ConnectionUtil; +import graphql.annotations.processor.util.DataFetcherConstructor; import graphql.relay.Relay; import graphql.schema.*; import graphql.schema.GraphQLNonNull; @@ -37,14 +40,11 @@ import java.lang.reflect.*; import java.util.*; import java.util.stream.Collectors; -import java.util.stream.Stream; import static graphql.Scalars.GraphQLBoolean; -import static graphql.annotations.processor.util.ReflectionKit.constructNewInstance; import static graphql.annotations.processor.util.ReflectionKit.newInstance; import static graphql.annotations.processor.util.NamingKit.toGraphqlName; import static graphql.annotations.processor.util.ObjectUtil.getAllFields; -import static graphql.schema.GraphQLArgument.newArgument; import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; import static graphql.schema.GraphQLInputObjectField.newInputObjectField; import static java.util.Arrays.stream; @@ -52,23 +52,24 @@ public class GraphQLFieldRetriever { - private static final List TYPES_FOR_CONNECTION = Arrays.asList(GraphQLObjectType.class, GraphQLInterfaceType.class, GraphQLUnionType.class, GraphQLTypeReference.class); - private static final String DEFAULT_INPUT_PREFIX = "Input"; private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; private BreadthFirstSearch breadthFirstSearch; private ParentalSearch parentalSearch; private GraphQLInputObjectRetriever graphQLInputObjectRetriever; + private DataFetcherConstructor dataFetcherConstructor; - public GraphQLFieldRetriever(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, BreadthFirstSearch breadthFirstSearch, ParentalSearch parentalSearch, GraphQLInputObjectRetriever graphQLInputObjectRetriever) { + public GraphQLFieldRetriever(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, BreadthFirstSearch breadthFirstSearch, ParentalSearch parentalSearch, + GraphQLInputObjectRetriever graphQLInputObjectRetriever, DataFetcherConstructor dataFetcherConstructor) { this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; this.breadthFirstSearch = breadthFirstSearch; this.parentalSearch = parentalSearch; this.graphQLInputObjectRetriever = graphQLInputObjectRetriever; + this.dataFetcherConstructor = dataFetcherConstructor; } public GraphQLFieldRetriever() { - this(new GraphQLObjectInfoRetriever(), new BreadthFirstSearch(new GraphQLObjectInfoRetriever()), new ParentalSearch(new GraphQLObjectInfoRetriever()), new GraphQLInputObjectRetriever() ); + this(new GraphQLObjectInfoRetriever(), new BreadthFirstSearch(new GraphQLObjectInfoRetriever()), new ParentalSearch(new GraphQLObjectInfoRetriever()), new GraphQLInputObjectRetriever(), new DataFetcherConstructor()); } public List getExtensionFields(Class object, List fieldsDefined, ProcessingElementsContainer container) throws CannotCastMemberException { @@ -80,7 +81,7 @@ public List getExtensionFields(Class object, List getExtensionFields(Class object, List getExtensionFields(Class object, List args = new ArgumentBuilder(method, typeFunction, graphQLInputObjectRetriever, builder, container, outputType).build(); + GraphQLFieldDefinition relayFieldDefinition = handleRelayArguments(method, container, builder, outputType, args); + builder.description(new DescriptionBuilder(method).build()) + .deprecate(new DeprecateBuilder(method).build()) + .dataFetcher(new DataFetcherBuilder(method, outputType, typeFunction, container, relayFieldDefinition, args, dataFetcherConstructor, isConnection).build()); + return new GraphQLAnnotations.GraphQLFieldDefinitionWrapper(builder.build()); + } - - TypeFunction finalTypeFunction = typeFunction; - List args = Arrays.asList(method.getParameters()).stream(). - filter(p -> !DataFetchingEnvironment.class.isAssignableFrom(p.getType())). - map(parameter -> { - Class t = parameter.getType(); - graphql.schema.GraphQLInputType graphQLType = graphQLInputObjectRetriever.getInputObject(finalTypeFunction.buildType(t, parameter.getAnnotatedType(),container), DEFAULT_INPUT_PREFIX,container.getTypeRegistry()); - return getArgument(parameter, graphQLType); - }).collect(Collectors.toList()); - + private GraphQLFieldDefinition handleRelayArguments(Method method, ProcessingElementsContainer container, GraphQLFieldDefinition.Builder builder, GraphQLOutputType outputType, List args) { GraphQLFieldDefinition relayFieldDefinition = null; if (method.isAnnotationPresent(GraphQLRelayMutation.class)) { - if (!(outputType instanceof GraphQLObjectType || outputType instanceof GraphQLInterfaceType)) { - throw new RuntimeException("outputType should be an object or an interface"); - } - StringBuilder titleBuffer = new StringBuilder(method.getName()); - titleBuffer.setCharAt(0, Character.toUpperCase(titleBuffer.charAt(0))); - String title = titleBuffer.toString(); - List fieldDefinitions = outputType instanceof GraphQLObjectType ? - ((GraphQLObjectType) outputType).getFieldDefinitions() : - ((GraphQLInterfaceType) outputType).getFieldDefinitions(); - relayFieldDefinition = container.getRelay().mutationWithClientMutationId(title, method.getName(), - args.stream(). - map(t -> newInputObjectField().name(t.getName()).type(t.getType()).description(t.getDescription()).build()). - collect(Collectors.toList()), fieldDefinitions, new StaticDataFetcher(null)); - builder.argument(relayFieldDefinition.getArguments()); - builder.type(relayFieldDefinition.getType()); - } else { - builder.argument(args); + relayFieldDefinition = buildRelayMutation(method, container, builder, outputType, args); } - - GraphQLDescription description = method.getAnnotation(GraphQLDescription.class); - if (description != null) { - builder.description(description.value()); - } - - GraphQLDeprecate deprecate = method.getAnnotation(GraphQLDeprecate.class); - if (deprecate != null) { - builder.deprecate(deprecate.value()); - } - if (method.getAnnotation(Deprecated.class) != null) { - builder.deprecate("Deprecated"); - } - - GraphQLDataFetcher dataFetcher = method.getAnnotation(GraphQLDataFetcher.class); - DataFetcher actualDataFetcher; - if (dataFetcher == null && method.getAnnotation(GraphQLBatched.class) != null) { - actualDataFetcher = new BatchedMethodDataFetcher(method,typeFunction, container); - } else if (dataFetcher == null) { - actualDataFetcher = new MethodDataFetcher(method,typeFunction, container); - } else { - actualDataFetcher = constructDataFetcher(method.getName(), dataFetcher); - } - - if (method.isAnnotationPresent(GraphQLRelayMutation.class) && relayFieldDefinition != null) { - actualDataFetcher = new RelayMutationMethodDataFetcher(method, args, relayFieldDefinition.getArgument("input").getType(), relayFieldDefinition.getType()); + else { + builder.argument(args); } + return relayFieldDefinition; + } + private void handleConnectionArgument(ProcessingElementsContainer container, GraphQLFieldDefinition.Builder builder, boolean isConnection) { if (isConnection) { - actualDataFetcher = new ConnectionDataFetcher(method.getAnnotation(GraphQLConnection.class).connection(), actualDataFetcher); + builder.argument(container.getRelay().getConnectionFieldArguments()); } - - builder.dataFetcher(actualDataFetcher); - - return new GraphQLAnnotations.GraphQLFieldDefinitionWrapper(builder.build()); } - public GraphQLFieldDefinition getField(Field field,ProcessingElementsContainer container) throws GraphQLAnnotationsException { - GraphQLFieldDefinition.Builder builder = newFieldDefinition(); - GraphQLName name = field.getAnnotation(GraphQLName.class); - builder.name(toGraphqlName(name == null ? field.getName() : name.value())); - GraphQLType annotation = field.getAnnotation(GraphQLType.class); - + private TypeFunction getTypeFunction(Method method, ProcessingElementsContainer container) { + GraphQLType annotation = method.getAnnotation(GraphQLType.class); TypeFunction typeFunction = container.getDefaultTypeFunction(); if (annotation != null) { typeFunction = newInstance(annotation.value()); } + return typeFunction; + } + + private GraphQLFieldDefinition buildRelayMutation(Method method, ProcessingElementsContainer container, GraphQLFieldDefinition.Builder builder, GraphQLOutputType outputType, List args) { + GraphQLFieldDefinition relayFieldDefinition; + if (!(outputType instanceof GraphQLObjectType || outputType instanceof GraphQLInterfaceType)) { + throw new RuntimeException("outputType should be an object or an interface"); + } + StringBuilder titleBuffer = new StringBuilder(method.getName()); + titleBuffer.setCharAt(0, Character.toUpperCase(titleBuffer.charAt(0))); + String title = titleBuffer.toString(); + List fieldDefinitions = outputType instanceof GraphQLObjectType ? + ((GraphQLObjectType) outputType).getFieldDefinitions() : + ((GraphQLInterfaceType) outputType).getFieldDefinitions(); + relayFieldDefinition = container.getRelay().mutationWithClientMutationId(title, method.getName(), + args.stream(). + map(t -> newInputObjectField().name(t.getName()).type(t.getType()).description(t.getDescription()).build()). + collect(Collectors.toList()), fieldDefinitions, new StaticDataFetcher(null)); + builder.argument(relayFieldDefinition.getArguments()); + builder.type(relayFieldDefinition.getType()); + return relayFieldDefinition; + } - GraphQLOutputType outputType = (GraphQLOutputType) typeFunction.buildType(field.getType(), field.getAnnotatedType(),container); + public GraphQLFieldDefinition getField(Field field, ProcessingElementsContainer container) throws GraphQLAnnotationsException { + GraphQLFieldDefinition.Builder builder = newFieldDefinition(); + builder.name(new FieldNameBuilder(field).build()); + TypeFunction typeFunction = getTypeFunction(field, container); - boolean isConnection = isConnection(field, outputType); + GraphQLOutputType outputType = (GraphQLOutputType) typeFunction.buildType(field.getType(), field.getAnnotatedType(), container); + boolean isConnection = ConnectionUtil.isConnection(field, outputType); if (isConnection) { - outputType = getGraphQLConnection(field, outputType,container.getRelay(),container.getTypeRegistry()); + outputType = getGraphQLConnection(field, outputType, container.getRelay(), container.getTypeRegistry()); builder.argument(container.getRelay().getConnectionFieldArguments()); } builder.type(outputType); - GraphQLDescription description = field.getAnnotation(GraphQLDescription.class); - if (description != null) { - builder.description(description.value()); - } - - GraphQLDeprecate deprecate = field.getAnnotation(GraphQLDeprecate.class); - if (deprecate != null) { - builder.deprecate(deprecate.value()); - } - if (field.getAnnotation(Deprecated.class) != null) { - builder.deprecate("Deprecated"); - } - - GraphQLDataFetcher dataFetcher = field.getAnnotation(GraphQLDataFetcher.class); - DataFetcher actualDataFetcher = null; - if (nonNull(dataFetcher)) { - actualDataFetcher = constructDataFetcher(field.getName(), dataFetcher); - } - - if (actualDataFetcher == null) { - - StringBuilder fluentBuffer = new StringBuilder(field.getName()); - fluentBuffer.setCharAt(0, Character.toLowerCase(fluentBuffer.charAt(0))); - String fluentGetter = fluentBuffer.toString(); - - boolean hasFluentGetter = false; - Method fluentMethod = null; - try { - fluentMethod = field.getDeclaringClass().getMethod(fluentGetter); - hasFluentGetter = true; - } catch (NoSuchMethodException x) { - } - - // if there is getter for fields type, use propertyDataFetcher, otherwise use method directly - if (outputType == GraphQLBoolean || (outputType instanceof GraphQLNonNull && ((GraphQLNonNull) outputType).getWrappedType() == GraphQLBoolean)) { - if (checkIfPrefixGetterExists(field.getDeclaringClass(), "is", field.getName()) || - checkIfPrefixGetterExists(field.getDeclaringClass(), "get", field.getName())) { - actualDataFetcher = new ExtensionDataFetcherWrapper(field.getDeclaringClass(), new PropertyDataFetcher(field.getName())); - } - } else if (checkIfPrefixGetterExists(field.getDeclaringClass(), "get", field.getName())) { - actualDataFetcher = new ExtensionDataFetcherWrapper(field.getDeclaringClass(), new PropertyDataFetcher(field.getName())); - } else if (hasFluentGetter) { - actualDataFetcher = new MethodDataFetcher(fluentMethod, typeFunction,container); - } + builder.description(new DescriptionBuilder(field).build()); - if (actualDataFetcher == null) { - actualDataFetcher = new ExtensionDataFetcherWrapper(field.getDeclaringClass(), new FieldDataFetcher(field.getName())); - } - } + builder.deprecate(new DeprecateBuilder(field).build()); - - if (isConnection) { - actualDataFetcher = new ConnectionDataFetcher(field.getAnnotation(GraphQLConnection.class).connection(), actualDataFetcher); - } - - builder.dataFetcher(actualDataFetcher); + builder.dataFetcher(new FieldDataFetcherBuilder(field, dataFetcherConstructor, outputType, typeFunction, container, isConnection).build()); return new GraphQLAnnotations.GraphQLFieldDefinitionWrapper(builder.build()); } - private void buildName(Method method, GraphQLFieldDefinition.Builder builder) { - String name = method.getName().replaceFirst("^(is|get|set)(.+)", "$2"); - name = Character.toLowerCase(name.charAt(0)) + name.substring(1); - GraphQLName nameAnn = method.getAnnotation(GraphQLName.class); - builder.name(toGraphqlName(nameAnn == null ? name : nameAnn.value())); - } + private TypeFunction getTypeFunction(Field field, ProcessingElementsContainer container) { + GraphQLType annotation = field.getAnnotation(GraphQLType.class); - private boolean isConnection(AccessibleObject obj, GraphQLOutputType type) { - if (type instanceof graphql.schema.GraphQLNonNull) { - type = (GraphQLOutputType) ((GraphQLNonNull) type).getWrappedType(); + TypeFunction typeFunction = container.getDefaultTypeFunction(); + + if (annotation != null) { + typeFunction = newInstance(annotation.value()); } - final GraphQLOutputType actualType = type; - return obj.isAnnotationPresent(GraphQLConnection.class) && - actualType instanceof GraphQLList && TYPES_FOR_CONNECTION.stream().anyMatch(aClass -> aClass.isInstance(((GraphQLList) actualType).getWrappedType())); + return typeFunction; } private GraphQLOutputType getGraphQLConnection(AccessibleObject field, GraphQLOutputType type, Relay relay, Map typeRegistry) { @@ -326,57 +233,5 @@ private GraphQLObjectType getActualType(GraphQLObjectType type, Map ctr = annotatedDataFetcher.value().getDeclaredConstructor( - stream(args).map(v -> String.class).toArray(Class[]::new)); - return constructNewInstance(ctr, (Object[]) args); - } catch (final NoSuchMethodException e) { - throw new GraphQLAnnotationsException("Unable to instantiate DataFetcher via constructor for: " + fieldName, e); - } - } - } - - - // check if there is getter for field, basic functionality taken from PropertyDataFetcher - private boolean checkIfPrefixGetterExists(Class c, String prefix, String propertyName) { - String getterName = prefix + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); - try { - Method method = c.getMethod(getterName); - } catch (NoSuchMethodException x) { - return false; - } - - return true; - } } diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/Builder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/Builder.java new file mode 100644 index 00000000..bcfd694c --- /dev/null +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/Builder.java @@ -0,0 +1,5 @@ +package graphql.annotations.processor.retrievers.fieldBuilders; + +public interface Builder { + public T build(); +} diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldDataFetcherBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldDataFetcherBuilder.java new file mode 100644 index 00000000..b0db06cb --- /dev/null +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldDataFetcherBuilder.java @@ -0,0 +1,120 @@ +package graphql.annotations.processor.retrievers.fieldBuilders.field; + +import graphql.annotations.annotationTypes.GraphQLConnection; +import graphql.annotations.annotationTypes.GraphQLDataFetcher; +import graphql.annotations.dataFetchers.ExtensionDataFetcherWrapper; +import graphql.annotations.dataFetchers.MethodDataFetcher; +import graphql.annotations.dataFetchers.connection.ConnectionDataFetcher; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.retrievers.fieldBuilders.Builder; +import graphql.annotations.processor.typeFunctions.TypeFunction; +import graphql.annotations.processor.util.DataFetcherConstructor; +import graphql.schema.*; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import static graphql.Scalars.GraphQLBoolean; +import static java.util.Objects.nonNull; + +public class FieldDataFetcherBuilder implements Builder { + private Field field; + private DataFetcherConstructor dataFetcherConstructor; + private GraphQLOutputType outputType; + private TypeFunction typeFunction; + private ProcessingElementsContainer container; + private boolean isConnection; + + public FieldDataFetcherBuilder(Field field, DataFetcherConstructor dataFetcherConstructor, GraphQLOutputType outputType, TypeFunction typeFunction, ProcessingElementsContainer container, boolean isConnection) { + this.field = field; + this.dataFetcherConstructor = dataFetcherConstructor; + this.outputType = outputType; + this.typeFunction = typeFunction; + this.container = container; + this.isConnection = isConnection; + } + + @Override + public DataFetcher build() { + GraphQLDataFetcher dataFetcher = field.getAnnotation(GraphQLDataFetcher.class); + DataFetcher actualDataFetcher = null; + if (nonNull(dataFetcher)) { + actualDataFetcher = dataFetcherConstructor.constructDataFetcher(field.getName(), dataFetcher); + } + + if (actualDataFetcher == null) { + actualDataFetcher = handleNullCase(actualDataFetcher); + } + + + if (isConnection) { + actualDataFetcher = new ConnectionDataFetcher(field.getAnnotation(GraphQLConnection.class).connection(), actualDataFetcher); + } + return actualDataFetcher; + } + + private DataFetcher handleNullCase(DataFetcher actualDataFetcher) { + + // if there is getter for fields type, use propertyDataFetcher, otherwise use method directly + if (isaBoolean()) { + actualDataFetcher = getBooleanDataFetcher(actualDataFetcher); + } else if (checkIfPrefixGetterExists(field.getDeclaringClass(), "get", field.getName())) { + actualDataFetcher = wrapExtension(new PropertyDataFetcher(field.getName())); + } else{ + actualDataFetcher = getDataFetcherWithFluentGetter(actualDataFetcher); + } + + if (actualDataFetcher == null) { + actualDataFetcher = wrapExtension(new FieldDataFetcher(field.getName())); + } + return actualDataFetcher; + } + + private DataFetcher getDataFetcherWithFluentGetter(DataFetcher actualDataFetcher) { + StringBuilder fluentBuffer = new StringBuilder(field.getName()); + fluentBuffer.setCharAt(0, Character.toLowerCase(fluentBuffer.charAt(0))); + String fluentGetter = fluentBuffer.toString(); + + boolean hasFluentGetter = false; + Method fluentMethod = null; + try { + fluentMethod = field.getDeclaringClass().getMethod(fluentGetter); + hasFluentGetter = true; + } catch (NoSuchMethodException x) { + } + + if (hasFluentGetter) { + actualDataFetcher = new MethodDataFetcher(fluentMethod, typeFunction, container); + } + return actualDataFetcher; + } + + private ExtensionDataFetcherWrapper wrapExtension(DataFetcher dataFetcher) { + return new ExtensionDataFetcherWrapper(field.getDeclaringClass(), dataFetcher); + } + + private DataFetcher getBooleanDataFetcher(DataFetcher actualDataFetcher) { + if (checkIfPrefixGetterExists(field.getDeclaringClass(), "is", field.getName()) || + checkIfPrefixGetterExists(field.getDeclaringClass(), "get", field.getName())) { + actualDataFetcher = wrapExtension(new PropertyDataFetcher(field.getName())); + } + return actualDataFetcher; + } + + private boolean isaBoolean() { + return outputType == GraphQLBoolean || (outputType instanceof GraphQLNonNull && ((GraphQLNonNull) outputType).getWrappedType() == GraphQLBoolean); + } + + // check if there is getter for field, basic functionality taken from PropertyDataFetcher + private boolean checkIfPrefixGetterExists(Class c, String prefix, String propertyName) { + String getterName = prefix + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); + try { + Method method = c.getMethod(getterName); + } catch (NoSuchMethodException x) { + return false; + } + + return true; + } + +} diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilder.java new file mode 100644 index 00000000..0d8a0b32 --- /dev/null +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilder.java @@ -0,0 +1,22 @@ +package graphql.annotations.processor.retrievers.fieldBuilders.field; + +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.processor.retrievers.fieldBuilders.Builder; + +import java.lang.reflect.Field; + +import static graphql.annotations.processor.util.NamingKit.toGraphqlName; + +public class FieldNameBuilder implements Builder { + private Field field; + + public FieldNameBuilder(Field field) { + this.field = field; + } + + @Override + public String build() { + GraphQLName name = field.getAnnotation(GraphQLName.class); + return toGraphqlName(name == null ? field.getName() : name.value()); + } +} diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/ArgumentBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/ArgumentBuilder.java new file mode 100644 index 00000000..8c0737e8 --- /dev/null +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/ArgumentBuilder.java @@ -0,0 +1,77 @@ +package graphql.annotations.processor.retrievers.fieldBuilders.method; + +import graphql.annotations.annotationTypes.GraphQLDefaultValue; +import graphql.annotations.annotationTypes.GraphQLDescription; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.annotations.processor.retrievers.GraphQLInputObjectRetriever; +import graphql.annotations.processor.retrievers.fieldBuilders.Builder; +import graphql.annotations.processor.typeFunctions.TypeFunction; +import graphql.schema.*; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static graphql.annotations.processor.util.NamingKit.toGraphqlName; +import static graphql.annotations.processor.util.ReflectionKit.newInstance; +import static graphql.schema.GraphQLArgument.newArgument; +import static graphql.schema.GraphQLInputObjectField.newInputObjectField; + +public class ArgumentBuilder implements Builder> { + private static final String DEFAULT_INPUT_PREFIX = "Input"; + + private Method method; + private TypeFunction typeFunction; + private GraphQLInputObjectRetriever graphQLInputObjectRetriever; + private GraphQLFieldDefinition.Builder builder; + private ProcessingElementsContainer container; + private GraphQLOutputType outputType; + + public ArgumentBuilder(Method method, TypeFunction typeFunction, GraphQLInputObjectRetriever graphQLInputObjectRetriever, GraphQLFieldDefinition.Builder builder, ProcessingElementsContainer container, GraphQLOutputType outputType) { + this.method = method; + this.typeFunction = typeFunction; + this.graphQLInputObjectRetriever = graphQLInputObjectRetriever; + this.builder = builder; + this.container = container; + this.outputType = outputType; + } + + @Override + public List build() { + TypeFunction finalTypeFunction = typeFunction; + List args = Arrays.asList(method.getParameters()).stream(). + filter(p -> !DataFetchingEnvironment.class.isAssignableFrom(p.getType())). + map(parameter -> { + Class t = parameter.getType(); + graphql.schema.GraphQLInputType graphQLType = graphQLInputObjectRetriever.getInputObject(finalTypeFunction.buildType(t, parameter.getAnnotatedType(), container), DEFAULT_INPUT_PREFIX, container.getTypeRegistry()); + return getArgument(parameter, graphQLType); + }).collect(Collectors.toList()); + + return args; + } + + private GraphQLArgument getArgument(Parameter parameter, graphql.schema.GraphQLInputType t) throws + GraphQLAnnotationsException { + GraphQLArgument.Builder builder = newArgument().type(t); + GraphQLDescription description = parameter.getAnnotation(GraphQLDescription.class); + if (description != null) { + builder.description(description.value()); + } + GraphQLDefaultValue defaultValue = parameter.getAnnotation(GraphQLDefaultValue.class); + if (defaultValue != null) { + builder.defaultValue(newInstance(defaultValue.value()).get()); + } + GraphQLName name = parameter.getAnnotation(GraphQLName.class); + if (name != null) { + builder.name(toGraphqlName(name.value())); + } else { + builder.name(toGraphqlName(parameter.getName())); + } + return builder.build(); + } + +} diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DataFetcherBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DataFetcherBuilder.java new file mode 100644 index 00000000..0f42ca17 --- /dev/null +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DataFetcherBuilder.java @@ -0,0 +1,67 @@ +package graphql.annotations.processor.retrievers.fieldBuilders.method; + +import graphql.annotations.annotationTypes.GraphQLBatched; +import graphql.annotations.annotationTypes.GraphQLConnection; +import graphql.annotations.annotationTypes.GraphQLDataFetcher; +import graphql.annotations.annotationTypes.GraphQLRelayMutation; +import graphql.annotations.dataFetchers.BatchedMethodDataFetcher; +import graphql.annotations.dataFetchers.MethodDataFetcher; +import graphql.annotations.dataFetchers.RelayMutationMethodDataFetcher; +import graphql.annotations.dataFetchers.connection.ConnectionDataFetcher; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.retrievers.fieldBuilders.Builder; +import graphql.annotations.processor.typeFunctions.TypeFunction; +import graphql.annotations.processor.util.DataFetcherConstructor; +import graphql.schema.DataFetcher; +import graphql.schema.GraphQLArgument; +import graphql.schema.GraphQLFieldDefinition; +import graphql.schema.GraphQLOutputType; + +import java.lang.reflect.Method; +import java.util.List; + +public class DataFetcherBuilder implements Builder { + private Method method; + private GraphQLOutputType outputType; + private TypeFunction typeFunction; + private ProcessingElementsContainer container; + private GraphQLFieldDefinition relayFieldDefinition; + private List args; + private DataFetcherConstructor dataFetcherConstructor; + private boolean isConnection; + + public DataFetcherBuilder(Method method, GraphQLOutputType outputType, TypeFunction typeFunction, + ProcessingElementsContainer container, GraphQLFieldDefinition relayFieldDefinition, + List args, DataFetcherConstructor dataFetcherConstructor, boolean isConnection) { + this.method = method; + this.outputType = outputType; + this.typeFunction = typeFunction; + this.container = container; + this.relayFieldDefinition = relayFieldDefinition; + this.args = args; + this.dataFetcherConstructor = dataFetcherConstructor; + this.isConnection = isConnection; + } + + @Override + public DataFetcher build() { + GraphQLDataFetcher dataFetcher = method.getAnnotation(GraphQLDataFetcher.class); + DataFetcher actualDataFetcher; + if (dataFetcher == null && method.getAnnotation(GraphQLBatched.class) != null) { + actualDataFetcher = new BatchedMethodDataFetcher(method, typeFunction, container); + } else if (dataFetcher == null) { + actualDataFetcher = new MethodDataFetcher(method, typeFunction, container); + } else { + actualDataFetcher = dataFetcherConstructor.constructDataFetcher(method.getName(), dataFetcher); + } + + if (method.isAnnotationPresent(GraphQLRelayMutation.class) && relayFieldDefinition != null) { + actualDataFetcher = new RelayMutationMethodDataFetcher(method, args, relayFieldDefinition.getArgument("input").getType(), relayFieldDefinition.getType()); + } + + if (isConnection){ + actualDataFetcher = new ConnectionDataFetcher(method.getAnnotation(GraphQLConnection.class).connection(), actualDataFetcher); + } + return actualDataFetcher; + } +} diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DeprecateBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DeprecateBuilder.java new file mode 100644 index 00000000..a54ba7df --- /dev/null +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DeprecateBuilder.java @@ -0,0 +1,26 @@ +package graphql.annotations.processor.retrievers.fieldBuilders.method; + +import graphql.annotations.annotationTypes.GraphQLDeprecate; +import graphql.annotations.processor.retrievers.fieldBuilders.Builder; + +import java.lang.reflect.AccessibleObject; + +public class DeprecateBuilder implements Builder { + private AccessibleObject object; + + public DeprecateBuilder(AccessibleObject object) { + this.object = object; + } + + @Override + public String build() { + GraphQLDeprecate deprecate = object.getAnnotation(GraphQLDeprecate.class); + if (deprecate != null) { + return deprecate.value(); + } + if (object.getAnnotation(Deprecated.class) != null) { + return "Deprecated"; + } + return null; + } +} diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DescriptionBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DescriptionBuilder.java new file mode 100644 index 00000000..d4acaa95 --- /dev/null +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/DescriptionBuilder.java @@ -0,0 +1,20 @@ +package graphql.annotations.processor.retrievers.fieldBuilders.method; + +import graphql.annotations.annotationTypes.GraphQLDescription; +import graphql.annotations.processor.retrievers.fieldBuilders.Builder; + +import java.lang.reflect.AccessibleObject; + +public class DescriptionBuilder implements Builder { + private AccessibleObject object; + + public DescriptionBuilder(AccessibleObject method) { + this.object = method; + } + + @Override + public String build() { + GraphQLDescription description = object.getAnnotation(GraphQLDescription.class); + return description==null? null : description.value(); + } +} diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/NameBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/NameBuilder.java new file mode 100644 index 00000000..63039c41 --- /dev/null +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/NameBuilder.java @@ -0,0 +1,24 @@ +package graphql.annotations.processor.retrievers.fieldBuilders.method; + +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.processor.retrievers.fieldBuilders.Builder; + +import java.lang.reflect.Method; + +import static graphql.annotations.processor.util.NamingKit.toGraphqlName; + +public class NameBuilder implements Builder { + private Method method; + + public NameBuilder(Method method) { + this.method = method; + } + + @Override + public String build() { + String name = method.getName().replaceFirst("^(is|get|set)(.+)", "$2"); + name = Character.toLowerCase(name.charAt(0)) + name.substring(1); + GraphQLName nameAnn = method.getAnnotation(GraphQLName.class); + return toGraphqlName(nameAnn == null ? name : nameAnn.value()); + } +} diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/TypeBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/TypeBuilder.java new file mode 100644 index 00000000..563336fc --- /dev/null +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/TypeBuilder.java @@ -0,0 +1,38 @@ +package graphql.annotations.processor.retrievers.fieldBuilders.method; + +import graphql.annotations.annotationTypes.GraphQLBatched; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.retrievers.fieldBuilders.Builder; +import graphql.annotations.processor.typeFunctions.BatchedTypeFunction; +import graphql.annotations.processor.typeFunctions.TypeFunction; +import graphql.schema.GraphQLOutputType; + +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Method; + +public class TypeBuilder implements Builder { + private Method method; + private TypeFunction typeFunction; + private ProcessingElementsContainer container; + + public TypeBuilder(Method method, TypeFunction typeFunction, ProcessingElementsContainer container) { + this.method = method; + this.typeFunction = typeFunction; + this.container = container; + } + + @Override + public GraphQLOutputType build() { + AnnotatedType annotatedReturnType = method.getAnnotatedReturnType(); + + TypeFunction outputTypeFunction; + if (method.getAnnotation(GraphQLBatched.class) != null) { + outputTypeFunction = new BatchedTypeFunction(typeFunction); + } else { + outputTypeFunction = typeFunction; + } + + return (GraphQLOutputType) outputTypeFunction.buildType(method.getReturnType(), annotatedReturnType, container); + } + +} diff --git a/src/main/java/graphql/annotations/processor/util/ConnectionUtil.java b/src/main/java/graphql/annotations/processor/util/ConnectionUtil.java new file mode 100644 index 00000000..a6db2677 --- /dev/null +++ b/src/main/java/graphql/annotations/processor/util/ConnectionUtil.java @@ -0,0 +1,22 @@ +package graphql.annotations.processor.util; + +import graphql.annotations.annotationTypes.GraphQLConnection; +import graphql.schema.*; + +import java.lang.reflect.AccessibleObject; +import java.util.Arrays; +import java.util.List; + +public class ConnectionUtil { + private static final List TYPES_FOR_CONNECTION = Arrays.asList(GraphQLObjectType.class, GraphQLInterfaceType.class, GraphQLUnionType.class, GraphQLTypeReference.class); + + public static boolean isConnection(AccessibleObject obj, GraphQLOutputType type) { + if (type instanceof graphql.schema.GraphQLNonNull) { + type = (GraphQLOutputType) ((GraphQLNonNull) type).getWrappedType(); + } + final GraphQLOutputType actualType = type; + return obj.isAnnotationPresent(GraphQLConnection.class) && + actualType instanceof GraphQLList && TYPES_FOR_CONNECTION.stream().anyMatch(aClass -> aClass.isInstance(((GraphQLList) actualType).getWrappedType())); + } + +} diff --git a/src/main/java/graphql/annotations/processor/util/DataFetcherConstructor.java b/src/main/java/graphql/annotations/processor/util/DataFetcherConstructor.java new file mode 100644 index 00000000..acd68f80 --- /dev/null +++ b/src/main/java/graphql/annotations/processor/util/DataFetcherConstructor.java @@ -0,0 +1,35 @@ +package graphql.annotations.processor.util; + +import graphql.annotations.annotationTypes.GraphQLDataFetcher; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; +import graphql.schema.DataFetcher; + +import java.lang.reflect.Constructor; +import java.util.stream.Stream; + +import static graphql.annotations.processor.util.ReflectionKit.constructNewInstance; +import static graphql.annotations.processor.util.ReflectionKit.newInstance; +import static java.util.Arrays.stream; + +public class DataFetcherConstructor { + public DataFetcher constructDataFetcher(String fieldName, GraphQLDataFetcher annotatedDataFetcher) { + final String[] args; + if (annotatedDataFetcher.firstArgIsTargetName()) { + args = Stream.concat(Stream.of(fieldName), stream(annotatedDataFetcher.args())).toArray(String[]::new); + } else { + args = annotatedDataFetcher.args(); + } + if (args.length == 0) { + return newInstance(annotatedDataFetcher.value()); + } else { + try { + final Constructor ctr = annotatedDataFetcher.value().getDeclaredConstructor( + stream(args).map(v -> String.class).toArray(Class[]::new)); + return constructNewInstance(ctr, (Object[]) args); + } catch (final NoSuchMethodException e) { + throw new GraphQLAnnotationsException("Unable to instantiate DataFetcher via constructor for: " + fieldName, e); + } + } + } + +} From a3c86df2f44a4e44aa258212b0cf51aa11c3d376 Mon Sep 17 00:00:00 2001 From: Yarin Date: Fri, 3 Nov 2017 13:16:40 +0200 Subject: [PATCH 21/25] prettify --- .../processor/retrievers/GraphQLFieldRetriever.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java index ddaaed22..57d67084 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java @@ -159,8 +159,7 @@ private GraphQLFieldDefinition buildRelayMutation(Method method, ProcessingEleme args.stream(). map(t -> newInputObjectField().name(t.getName()).type(t.getType()).description(t.getDescription()).build()). collect(Collectors.toList()), fieldDefinitions, new StaticDataFetcher(null)); - builder.argument(relayFieldDefinition.getArguments()); - builder.type(relayFieldDefinition.getType()); + builder.argument(relayFieldDefinition.getArguments()).type(relayFieldDefinition.getType()); return relayFieldDefinition; } @@ -176,13 +175,9 @@ public GraphQLFieldDefinition getField(Field field, ProcessingElementsContainer builder.argument(container.getRelay().getConnectionFieldArguments()); } - builder.type(outputType); - - builder.description(new DescriptionBuilder(field).build()); - - builder.deprecate(new DeprecateBuilder(field).build()); - - builder.dataFetcher(new FieldDataFetcherBuilder(field, dataFetcherConstructor, outputType, typeFunction, container, isConnection).build()); + builder.type(outputType).description(new DescriptionBuilder(field).build()) + .deprecate(new DeprecateBuilder(field).build()) + .dataFetcher(new FieldDataFetcherBuilder(field, dataFetcherConstructor, outputType, typeFunction, container, isConnection).build()); return new GraphQLAnnotations.GraphQLFieldDefinitionWrapper(builder.build()); } From b171b4e97e15a233f65f19789a69e9994be03def Mon Sep 17 00:00:00 2001 From: Yarin Date: Sat, 4 Nov 2017 13:53:17 +0200 Subject: [PATCH 22/25] name&packages changes --- .../retrievers/GraphQLFieldRetriever.java | 16 ++++++---------- .../{method => }/ArgumentBuilder.java | 2 +- .../{method => }/DeprecateBuilder.java | 2 +- .../{method => }/DescriptionBuilder.java | 3 +-- ...uilder.java => MethodDataFetcherBuilder.java} | 8 ++++---- .../{NameBuilder.java => MethodNameBuilder.java} | 4 ++-- .../{TypeBuilder.java => MethodTypeBuilder.java} | 4 ++-- 7 files changed, 17 insertions(+), 22 deletions(-) rename src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/{method => }/ArgumentBuilder.java (98%) rename src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/{method => }/DeprecateBuilder.java (90%) rename src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/{method => }/DescriptionBuilder.java (77%) rename src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/{DataFetcherBuilder.java => MethodDataFetcherBuilder.java} (86%) rename src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/{NameBuilder.java => MethodNameBuilder.java} (87%) rename src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/{TypeBuilder.java => MethodTypeBuilder.java} (87%) diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java index 57d67084..664ae10a 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java @@ -19,11 +19,10 @@ import graphql.annotations.processor.ProcessingElementsContainer; import graphql.annotations.annotationTypes.*; import graphql.annotations.annotationTypes.GraphQLType; -import graphql.annotations.dataFetchers.MethodDataFetcher; -import graphql.annotations.dataFetchers.connection.ConnectionDataFetcher; -import graphql.annotations.dataFetchers.ExtensionDataFetcherWrapper; import graphql.annotations.processor.GraphQLAnnotations; -import graphql.annotations.processor.retrievers.fieldBuilders.Builder; +import graphql.annotations.processor.retrievers.fieldBuilders.ArgumentBuilder; +import graphql.annotations.processor.retrievers.fieldBuilders.DeprecateBuilder; +import graphql.annotations.processor.retrievers.fieldBuilders.DescriptionBuilder; import graphql.annotations.processor.retrievers.fieldBuilders.field.FieldDataFetcherBuilder; import graphql.annotations.processor.retrievers.fieldBuilders.field.FieldNameBuilder; import graphql.annotations.processor.retrievers.fieldBuilders.method.*; @@ -41,14 +40,11 @@ import java.util.*; import java.util.stream.Collectors; -import static graphql.Scalars.GraphQLBoolean; import static graphql.annotations.processor.util.ReflectionKit.newInstance; -import static graphql.annotations.processor.util.NamingKit.toGraphqlName; import static graphql.annotations.processor.util.ObjectUtil.getAllFields; import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; import static graphql.schema.GraphQLInputObjectField.newInputObjectField; import static java.util.Arrays.stream; -import static java.util.Objects.nonNull; public class GraphQLFieldRetriever { @@ -100,8 +96,8 @@ public List getExtensionFields(Class object, List { +public class MethodDataFetcherBuilder implements Builder { private Method method; private GraphQLOutputType outputType; private TypeFunction typeFunction; @@ -30,9 +30,9 @@ public class DataFetcherBuilder implements Builder { private DataFetcherConstructor dataFetcherConstructor; private boolean isConnection; - public DataFetcherBuilder(Method method, GraphQLOutputType outputType, TypeFunction typeFunction, - ProcessingElementsContainer container, GraphQLFieldDefinition relayFieldDefinition, - List args, DataFetcherConstructor dataFetcherConstructor, boolean isConnection) { + public MethodDataFetcherBuilder(Method method, GraphQLOutputType outputType, TypeFunction typeFunction, + ProcessingElementsContainer container, GraphQLFieldDefinition relayFieldDefinition, + List args, DataFetcherConstructor dataFetcherConstructor, boolean isConnection) { this.method = method; this.outputType = outputType; this.typeFunction = typeFunction; diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/NameBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilder.java similarity index 87% rename from src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/NameBuilder.java rename to src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilder.java index 63039c41..4d4a056f 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/NameBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilder.java @@ -7,10 +7,10 @@ import static graphql.annotations.processor.util.NamingKit.toGraphqlName; -public class NameBuilder implements Builder { +public class MethodNameBuilder implements Builder { private Method method; - public NameBuilder(Method method) { + public MethodNameBuilder(Method method) { this.method = method; } diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/TypeBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodTypeBuilder.java similarity index 87% rename from src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/TypeBuilder.java rename to src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodTypeBuilder.java index 563336fc..09e3b3d3 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/TypeBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodTypeBuilder.java @@ -10,12 +10,12 @@ import java.lang.reflect.AnnotatedType; import java.lang.reflect.Method; -public class TypeBuilder implements Builder { +public class MethodTypeBuilder implements Builder { private Method method; private TypeFunction typeFunction; private ProcessingElementsContainer container; - public TypeBuilder(Method method, TypeFunction typeFunction, ProcessingElementsContainer container) { + public MethodTypeBuilder(Method method, TypeFunction typeFunction, ProcessingElementsContainer container) { this.method = method; this.typeFunction = typeFunction; this.container = container; From a056b3c8afce28f5e72dc4b0aebe5f5f9ff13856 Mon Sep 17 00:00:00 2001 From: Yarin Date: Sat, 4 Nov 2017 14:27:02 +0200 Subject: [PATCH 23/25] some tests classes --- .../fieldBuilders/ArgumentBuilder.java | 14 +-- .../fieldBuilders/DeprecateBuilder.java | 4 +- .../fieldBuilders/DeprecateBuilderTest.java | 84 ++++++++++++++++ .../fieldBuilders/DescriptionBuilderTest.java | 75 +++++++++++++++ .../field/FieldNameBuilderTest.java | 42 ++++++++ .../method/MethodNameBuilderTest.java | 96 +++++++++++++++++++ 6 files changed, 306 insertions(+), 9 deletions(-) create mode 100644 src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilderTest.java create mode 100644 src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilderTest.java create mode 100644 src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilderTest.java create mode 100644 src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilderTest.java diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java index 3d9b5d92..59f366d1 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java @@ -54,24 +54,24 @@ public List build() { return args; } - private GraphQLArgument getArgument(Parameter parameter, graphql.schema.GraphQLInputType t) throws + private GraphQLArgument getArgument(Parameter parameter, graphql.schema.GraphQLInputType inputType) throws GraphQLAnnotationsException { - GraphQLArgument.Builder builder = newArgument().type(t); + GraphQLArgument.Builder argumentBuilder = newArgument().type(inputType); GraphQLDescription description = parameter.getAnnotation(GraphQLDescription.class); if (description != null) { - builder.description(description.value()); + argumentBuilder.description(description.value()); } GraphQLDefaultValue defaultValue = parameter.getAnnotation(GraphQLDefaultValue.class); if (defaultValue != null) { - builder.defaultValue(newInstance(defaultValue.value()).get()); + argumentBuilder.defaultValue(newInstance(defaultValue.value()).get()); } GraphQLName name = parameter.getAnnotation(GraphQLName.class); if (name != null) { - builder.name(toGraphqlName(name.value())); + argumentBuilder.name(toGraphqlName(name.value())); } else { - builder.name(toGraphqlName(parameter.getName())); + argumentBuilder.name(toGraphqlName(parameter.getName())); } - return builder.build(); + return argumentBuilder.build(); } } diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilder.java index 1a904f87..c01022c5 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilder.java @@ -1,12 +1,12 @@ package graphql.annotations.processor.retrievers.fieldBuilders; import graphql.annotations.annotationTypes.GraphQLDeprecate; -import graphql.annotations.processor.retrievers.fieldBuilders.Builder; import java.lang.reflect.AccessibleObject; public class DeprecateBuilder implements Builder { private AccessibleObject object; + private final String DEFAULT_DEPRECATION_DESCRIPTION = "Deprecated"; public DeprecateBuilder(AccessibleObject object) { this.object = object; @@ -19,7 +19,7 @@ public String build() { return deprecate.value(); } if (object.getAnnotation(Deprecated.class) != null) { - return "Deprecated"; + return DEFAULT_DEPRECATION_DESCRIPTION; } return null; } diff --git a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilderTest.java b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilderTest.java new file mode 100644 index 00000000..a548685c --- /dev/null +++ b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilderTest.java @@ -0,0 +1,84 @@ +package graphql.annotations.processor.retrievers.fieldBuilders; + +import graphql.annotations.annotationTypes.GraphQLDeprecate; +import org.testng.annotations.Test; + +import java.lang.reflect.Method; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNull; + +public class DeprecateBuilderTest { + + @GraphQLDeprecate("test deprecated") + public int testMethod() { + return 1; + } + + @GraphQLDeprecate + public int testMethod2() { + return 1; + } + + @Deprecated + public int testMethod3() { + return 1; + } + + public int testMethod4() { + return 1; + } + + @Test + public void build_graphQLDeprecateAnnotationExistsWithValue_returnAnnotationValue() throws NoSuchMethodException { + // arrange + Method method = getClass().getMethod("testMethod"); + DeprecateBuilder deprecateBuilder = new DeprecateBuilder(method); + + // act + String deprecate = deprecateBuilder.build(); + + // assert + assertEquals(deprecate, "test deprecated"); + } + + + @Test + public void build_graphQLDeprecateAnnotationExistsWithNoValue_returnEmptyString() throws NoSuchMethodException { + // arrange + Method method = getClass().getMethod("testMethod2"); + DeprecateBuilder deprecateBuilder = new DeprecateBuilder(method); + + // act + String deprecate = deprecateBuilder.build(); + + // assert + assertEquals(deprecate, ""); + } + + @Test + public void build_deprecatedAnnotationExists_returnDefaultDeprecationComment() throws NoSuchMethodException { + // arrange + Method method = getClass().getMethod("testMethod3"); + DeprecateBuilder deprecatedBuilder = new DeprecateBuilder(method); + + // act + String deprecate = deprecatedBuilder.build(); + + // assert + assertEquals(deprecate, "Deprecated"); + } + + @Test + public void build_noDeprecatedAnnotation_returnNull() throws NoSuchMethodException { + // arrange + Method method = getClass().getMethod("testMethod4"); + DeprecateBuilder deprecateBuilder = new DeprecateBuilder(method); + + // act + String deprecate = deprecateBuilder.build(); + + // assert + assertNull(deprecate); + } +} diff --git a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilderTest.java b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilderTest.java new file mode 100644 index 00000000..8eeced00 --- /dev/null +++ b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilderTest.java @@ -0,0 +1,75 @@ +package graphql.annotations.processor.retrievers.fieldBuilders; + +import graphql.annotations.annotationTypes.GraphQLDescription; +import org.testng.annotations.Test; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNull; + +public class DescriptionBuilderTest { + + @GraphQLDescription("test description") + public int testField; + + @GraphQLDescription("test description") + public int testMethod(){return 1;} + + public int testField2; + + public int testsMethod2(){return 1;} + + @Test + public void build_descriptionAnnotationExistsOnField_returnCorrectDescription() throws NoSuchFieldException { + // arrange + Field field = getClass().getField("testField"); + DescriptionBuilder descriptionBuilder = new DescriptionBuilder(field); + + // act + String description = descriptionBuilder.build(); + + // assert + assertEquals(description, "test description"); + } + + @Test + public void build_descriptionAnnotationExistsOnMethod_returnCorrectDescription() throws NoSuchMethodException { + // arrange + Method method = getClass().getMethod("testMethod"); + DescriptionBuilder descriptionBuilder = new DescriptionBuilder(method); + + // act + String description = descriptionBuilder.build(); + + // assert + assertEquals(description, "test description"); + } + + @Test + public void build_descriptionAnnotationNotExistsOnField_returnNull() throws NoSuchFieldException { + // arrange + Field field = getClass().getField("testField2"); + DescriptionBuilder descriptionBuilder = new DescriptionBuilder(field); + + // act + String description = descriptionBuilder.build(); + + // assert + assertNull(description); + } + + @Test + public void build_descriptionAnnotationNotExistsOnMethod_returnNull() throws NoSuchMethodException { + // arrange + Method method = getClass().getMethod("testsMethod2"); + DescriptionBuilder descriptionBuilder = new DescriptionBuilder(method); + + // act + String description = descriptionBuilder.build(); + + // assert + assertNull(description); + } +} diff --git a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilderTest.java b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilderTest.java new file mode 100644 index 00000000..7c8c3f94 --- /dev/null +++ b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilderTest.java @@ -0,0 +1,42 @@ +package graphql.annotations.processor.retrievers.fieldBuilders.field; + +import graphql.annotations.annotationTypes.GraphQLName; +import org.testng.annotations.Test; + +import java.lang.reflect.Field; + +import static org.testng.AssertJUnit.assertEquals; + +public class FieldNameBuilderTest { + + public int test1; + + @GraphQLName("test1") + public int test2; + + @Test + public void build_fieldWithGraphQLNameAnnotation_returnAnnotationValue() throws NoSuchFieldException{ + // arrange + Field field = getClass().getField("test2"); + FieldNameBuilder fieldNameBuilder = new FieldNameBuilder(field); + + // act + String name = fieldNameBuilder.build(); + + // assert + assertEquals(name, "test1"); + } + + @Test + public void build_fieldWithNoGraphQLNameAnnotation_returnFieldName() throws NoSuchFieldException{ + // arrange + Field field = getClass().getField("test1"); + FieldNameBuilder fieldNameBuilder = new FieldNameBuilder(field); + + // act + String name = fieldNameBuilder.build(); + + // assert + assertEquals(name, "test1"); + } +} diff --git a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilderTest.java b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilderTest.java new file mode 100644 index 00000000..0aa65edc --- /dev/null +++ b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilderTest.java @@ -0,0 +1,96 @@ +package graphql.annotations.processor.retrievers.fieldBuilders.method; + +import graphql.annotations.annotationTypes.GraphQLName; +import org.testng.annotations.Test; + +import java.lang.reflect.Method; + +import static org.testng.AssertJUnit.assertEquals; + +public class MethodNameBuilderTest { + + @GraphQLName("testName") + public void testMethod1() { + } + + public void getTest() { + } + + public void isTest(){ + } + + public void setTest(){ + + } + + public void test(){ + + } + + @Test + public void build_graphQLNameAnnotationExists_returnAnnotatedName() throws NoSuchMethodException { + // arrange + Method method = getClass().getMethod("testMethod1"); + MethodNameBuilder methodNameBuilder = new MethodNameBuilder(method); + + // act + String name = methodNameBuilder.build(); + + // assert + assertEquals(name, "testName"); + } + + @Test + public void build_graphQLNameAnnotationNotExistsWithGetPrefix_returnCorrectName() throws NoSuchMethodException { + // arrange + Method method = getClass().getMethod("getTest"); + MethodNameBuilder methodNameBuilder = new MethodNameBuilder(method); + + // act + String name = methodNameBuilder.build(); + + // assert + assertEquals(name, "test"); + } + + @Test + public void build_graphQLNameAnnotationNotExistsWithIsPrefix_returnCorrectName() throws NoSuchMethodException{ + // arrange + Method method = getClass().getMethod("isTest"); + MethodNameBuilder methodNameBuilder = new MethodNameBuilder(method); + + // act + String name = methodNameBuilder.build(); + + // assert + assertEquals(name, "test"); + } + + @Test + public void build_graphQLNameAnnotationNotExistsWithSetPrefix_returnCorrectName() throws NoSuchMethodException{ + // arrange + Method method = getClass().getMethod("setTest"); + MethodNameBuilder methodNameBuilder = new MethodNameBuilder(method); + + // act + String name = methodNameBuilder.build(); + + // assert + assertEquals(name, "test"); + } + + + @Test + public void build_graphQLNameAnnotationNotExistsNoPrefix_returnCorrectName() throws NoSuchMethodException{ + // arrange + Method method = getClass().getMethod("test"); + MethodNameBuilder methodNameBuilder = new MethodNameBuilder(method); + + // act + String name = methodNameBuilder.build(); + + // assert + assertEquals(name, "test"); + } + +} From 1291c7af9d02558d6c73211ca013fa6ffd60d1d6 Mon Sep 17 00:00:00 2001 From: Yarin Date: Mon, 6 Nov 2017 21:00:11 +0200 Subject: [PATCH 24/25] fix build --- .../retrievers/GraphQLFieldRetriever.java | 8 ++++---- .../retrievers/fieldBuilders/ArgumentBuilder.java | 14 ++++++++++++++ .../retrievers/fieldBuilders/Builder.java | 14 ++++++++++++++ .../retrievers/fieldBuilders/DeprecateBuilder.java | 14 ++++++++++++++ .../fieldBuilders/DescriptionBuilder.java | 14 ++++++++++++++ .../field/FieldDataFetcherBuilder.java | 14 ++++++++++++++ .../fieldBuilders/field/FieldNameBuilder.java | 14 ++++++++++++++ .../method/MethodDataFetcherBuilder.java | 14 ++++++++++++++ .../fieldBuilders/method/MethodNameBuilder.java | 14 ++++++++++++++ .../fieldBuilders/method/MethodTypeBuilder.java | 14 ++++++++++++++ .../annotations/processor/util/ConnectionUtil.java | 14 ++++++++++++++ .../processor/util/DataFetcherConstructor.java | 14 ++++++++++++++ .../fieldBuilders/DeprecateBuilderTest.java | 14 ++++++++++++++ .../fieldBuilders/DescriptionBuilderTest.java | 14 ++++++++++++++ .../fieldBuilders/field/FieldNameBuilderTest.java | 14 ++++++++++++++ .../method/MethodNameBuilderTest.java | 14 ++++++++++++++ 16 files changed, 214 insertions(+), 4 deletions(-) diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java index 664ae10a..e6317871 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java @@ -1,12 +1,12 @@ /** * Copyright 2016 Yurii Rashkovskii - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java index 59f366d1..95b01155 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders; import graphql.annotations.annotationTypes.GraphQLDefaultValue; diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/Builder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/Builder.java index bcfd694c..a189e476 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/Builder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/Builder.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders; public interface Builder { diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilder.java index c01022c5..0a9d03f0 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilder.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders; import graphql.annotations.annotationTypes.GraphQLDeprecate; diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilder.java index e0e6459e..033e8efc 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilder.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders; import graphql.annotations.annotationTypes.GraphQLDescription; diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldDataFetcherBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldDataFetcherBuilder.java index b0db06cb..e693d262 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldDataFetcherBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldDataFetcherBuilder.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders.field; import graphql.annotations.annotationTypes.GraphQLConnection; diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilder.java index 0d8a0b32..6d19ce93 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilder.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders.field; import graphql.annotations.annotationTypes.GraphQLName; diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodDataFetcherBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodDataFetcherBuilder.java index 00376f3e..58cd108b 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodDataFetcherBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodDataFetcherBuilder.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders.method; import graphql.annotations.annotationTypes.GraphQLBatched; diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilder.java index 4d4a056f..b62bd36d 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilder.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders.method; import graphql.annotations.annotationTypes.GraphQLName; diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodTypeBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodTypeBuilder.java index 09e3b3d3..8e1cb80a 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodTypeBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodTypeBuilder.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders.method; import graphql.annotations.annotationTypes.GraphQLBatched; diff --git a/src/main/java/graphql/annotations/processor/util/ConnectionUtil.java b/src/main/java/graphql/annotations/processor/util/ConnectionUtil.java index a6db2677..b30d0891 100644 --- a/src/main/java/graphql/annotations/processor/util/ConnectionUtil.java +++ b/src/main/java/graphql/annotations/processor/util/ConnectionUtil.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.util; import graphql.annotations.annotationTypes.GraphQLConnection; diff --git a/src/main/java/graphql/annotations/processor/util/DataFetcherConstructor.java b/src/main/java/graphql/annotations/processor/util/DataFetcherConstructor.java index acd68f80..7a168580 100644 --- a/src/main/java/graphql/annotations/processor/util/DataFetcherConstructor.java +++ b/src/main/java/graphql/annotations/processor/util/DataFetcherConstructor.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.util; import graphql.annotations.annotationTypes.GraphQLDataFetcher; diff --git a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilderTest.java b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilderTest.java index a548685c..d10e05c9 100644 --- a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilderTest.java +++ b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DeprecateBuilderTest.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders; import graphql.annotations.annotationTypes.GraphQLDeprecate; diff --git a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilderTest.java b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilderTest.java index 8eeced00..141959c9 100644 --- a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilderTest.java +++ b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/DescriptionBuilderTest.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders; import graphql.annotations.annotationTypes.GraphQLDescription; diff --git a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilderTest.java b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilderTest.java index 7c8c3f94..c79991e1 100644 --- a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilderTest.java +++ b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/field/FieldNameBuilderTest.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders.field; import graphql.annotations.annotationTypes.GraphQLName; diff --git a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilderTest.java b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilderTest.java index 0aa65edc..0beba9fa 100644 --- a/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilderTest.java +++ b/src/test/java/graphql/annotations/processor/retrievers/fieldBuilders/method/MethodNameBuilderTest.java @@ -1,3 +1,17 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ package graphql.annotations.processor.retrievers.fieldBuilders.method; import graphql.annotations.annotationTypes.GraphQLName; From 6746cfee2e6a4337f0f7f339b4b9386c42f67da8 Mon Sep 17 00:00:00 2001 From: Yarin Date: Thu, 9 Nov 2017 10:58:31 +0200 Subject: [PATCH 25/25] code review fixes --- .../GraphQLFieldDefinitionWrapper.java | 31 ++++++++++ .../processor/GraphQLAnnotations.java | 60 +++++++------------ .../ProcessingElementsContainer.java | 11 ++++ .../GraphQLAnnotationsProcessor.java | 18 +++++- .../retrievers/GraphQLFieldRetriever.java | 33 ++++++---- .../GraphQLInputObjectRetriever.java | 4 +- 6 files changed, 101 insertions(+), 56 deletions(-) create mode 100644 src/main/java/graphql/annotations/GraphQLFieldDefinitionWrapper.java diff --git a/src/main/java/graphql/annotations/GraphQLFieldDefinitionWrapper.java b/src/main/java/graphql/annotations/GraphQLFieldDefinitionWrapper.java new file mode 100644 index 00000000..5f32b599 --- /dev/null +++ b/src/main/java/graphql/annotations/GraphQLFieldDefinitionWrapper.java @@ -0,0 +1,31 @@ +/** + * Copyright 2016 Yurii Rashkovskii + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + */ +package graphql.annotations; + +import graphql.schema.GraphQLFieldDefinition; + +public class GraphQLFieldDefinitionWrapper extends GraphQLFieldDefinition { + + public GraphQLFieldDefinitionWrapper(GraphQLFieldDefinition fieldDefinition) { + super(fieldDefinition.getName(), fieldDefinition.getDescription(), fieldDefinition.getType(), + fieldDefinition.getDataFetcher(), fieldDefinition.getArguments(), fieldDefinition.getDeprecationReason()); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof GraphQLFieldDefinition && + ((GraphQLFieldDefinition) obj).getName().contentEquals(getName()); + } +} diff --git a/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java b/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java index be3d8ba6..7ea82e61 100644 --- a/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java @@ -14,22 +14,22 @@ */ package graphql.annotations.processor; -import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; -import graphql.annotations.processor.retrievers.GraphQLObjectHandler; import graphql.annotations.annotationTypes.GraphQLName; import graphql.annotations.annotationTypes.GraphQLTypeExtension; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.graphQLProcessors.GraphQLAnnotationsProcessor; import graphql.annotations.processor.graphQLProcessors.GraphQLInputProcessor; import graphql.annotations.processor.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.processor.retrievers.GraphQLObjectHandler; import graphql.annotations.processor.typeFunctions.DefaultTypeFunction; import graphql.annotations.processor.typeFunctions.TypeFunction; -import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; import graphql.relay.Relay; -import graphql.schema.GraphQLFieldDefinition; import graphql.schema.GraphQLObjectType; import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; -import java.util.*; +import java.util.HashSet; +import java.util.Map; import static graphql.annotations.processor.util.NamingKit.toGraphqlName; @@ -43,26 +43,13 @@ public class GraphQLAnnotations implements GraphQLAnnotationsProcessor { private GraphQLObjectHandler graphQLObjectHandler; private ProcessingElementsContainer container; - private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever; - public GraphQLAnnotations() { - this(new DefaultTypeFunction(new GraphQLInputProcessor(), new GraphQLOutputProcessor()), new GraphQLObjectInfoRetriever(), new GraphQLObjectHandler()); + this(new DefaultTypeFunction(new GraphQLInputProcessor(), new GraphQLOutputProcessor()), new GraphQLObjectHandler()); } - public GraphQLAnnotations(TypeFunction defaultTypeFunction, GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLObjectHandler graphQLObjectHandler) { - this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever; - this.defaultTypeFunction = defaultTypeFunction; + public GraphQLAnnotations(TypeFunction defaultTypeFunction, GraphQLObjectHandler graphQLObjectHandler) { this.graphQLObjectHandler = graphQLObjectHandler; - this.container = initializeContainer(this.defaultTypeFunction); - } - - private ProcessingElementsContainer initializeContainer(TypeFunction defaultTypeFunction) { - Map typeRegistry = new HashMap<>(); - Map, Set>> extensionsTypeRegistry = new HashMap<>(); - final Stack processing = new Stack<>(); - Relay relay = new Relay(); - ProcessingElementsContainer container = new ProcessingElementsContainer(defaultTypeFunction, relay, typeRegistry, extensionsTypeRegistry, processing); - return container; + this.container = new ProcessingElementsContainer(defaultTypeFunction); } public static GraphQLAnnotations instance = new GraphQLAnnotations(); @@ -75,32 +62,16 @@ public void setRelay(Relay relay) { this.container.setRelay(relay); } - public String getTypeName(Class objectClass) { GraphQLName name = objectClass.getAnnotation(GraphQLName.class); return toGraphqlName(name == null ? objectClass.getSimpleName() : name.value()); } public static GraphQLObjectType object(Class object) throws GraphQLAnnotationsException { - return new GraphQLObjectHandler().getObject(object, getInstance().getContainer()); - } - - public static class GraphQLFieldDefinitionWrapper extends GraphQLFieldDefinition { - - public GraphQLFieldDefinitionWrapper(GraphQLFieldDefinition fieldDefinition) { - super(fieldDefinition.getName(), fieldDefinition.getDescription(), fieldDefinition.getType(), - fieldDefinition.getDataFetcher(), fieldDefinition.getArguments(), fieldDefinition.getDeprecationReason()); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof GraphQLFieldDefinition && - ((GraphQLFieldDefinition) obj).getName().contentEquals(getName()); - } + GraphQLAnnotations instance = getInstance(); + return instance.graphQLObjectHandler.getObject(object, instance.getContainer()); } - protected TypeFunction defaultTypeFunction; - public void registerTypeExtension(Class objectClass) { GraphQLTypeExtension typeExtension = objectClass.getAnnotation(GraphQLTypeExtension.class); if (typeExtension == null) { @@ -127,7 +98,7 @@ public void unregisterTypeExtension(Class objectClass) { } public void registerType(TypeFunction typeFunction) { - ((DefaultTypeFunction) defaultTypeFunction).register(typeFunction); + ((DefaultTypeFunction) container.getDefaultTypeFunction()).register(typeFunction); } public static void register(TypeFunction typeFunction) { @@ -142,4 +113,13 @@ public ProcessingElementsContainer getContainer() { return container; } + public void setContainer(ProcessingElementsContainer container) { + this.container = container; + } + + @Reference(target = "(type=default)") + public void setDefaultTypeFunction(TypeFunction function) { + this.container.setDefaultTypeFunction(function); + } + } diff --git a/src/main/java/graphql/annotations/processor/ProcessingElementsContainer.java b/src/main/java/graphql/annotations/processor/ProcessingElementsContainer.java index 7a04ac3a..d202c053 100644 --- a/src/main/java/graphql/annotations/processor/ProcessingElementsContainer.java +++ b/src/main/java/graphql/annotations/processor/ProcessingElementsContainer.java @@ -15,9 +15,13 @@ package graphql.annotations.processor; +import graphql.annotations.processor.graphQLProcessors.GraphQLInputProcessor; +import graphql.annotations.processor.graphQLProcessors.GraphQLOutputProcessor; +import graphql.annotations.processor.typeFunctions.DefaultTypeFunction; import graphql.annotations.processor.typeFunctions.TypeFunction; import graphql.relay.Relay; +import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.Stack; @@ -39,6 +43,13 @@ public ProcessingElementsContainer(TypeFunction defaultTypeFunction, Relay relay this.processing = processing; } + public ProcessingElementsContainer(TypeFunction typeFunction) { + this(typeFunction, new Relay(), new HashMap<>(), new HashMap<>(), new Stack<>()); + } + + public ProcessingElementsContainer(){ + this(new DefaultTypeFunction(new GraphQLInputProcessor(), new GraphQLOutputProcessor()),new Relay(), new HashMap<>(), new HashMap<>(), new Stack<>()); + } public Relay getRelay() { return this.relay; diff --git a/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java b/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java index aea5763a..ef55e477 100644 --- a/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java +++ b/src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,6 +14,9 @@ */ package graphql.annotations.processor.graphQLProcessors; +import graphql.annotations.processor.typeFunctions.TypeFunction; +import graphql.relay.Relay; + public interface GraphQLAnnotationsProcessor { /** * Register a new type extension class. This extension will be used when the extended object will be created. @@ -30,4 +33,17 @@ public interface GraphQLAnnotationsProcessor { */ void unregisterTypeExtension(Class objectClass); + /** + * Allows you to set a custom relay object + * + * @param relay The extension class to register + */ + void setRelay(Relay relay); + + /** + * Allows you to register a new type function + * + * @param typeFunction The extension class to register + */ + void registerType(TypeFunction typeFunction); } diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java index e6317871..4728b6ee 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java @@ -15,36 +15,43 @@ package graphql.annotations.processor.retrievers; -import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; -import graphql.annotations.processor.ProcessingElementsContainer; -import graphql.annotations.annotationTypes.*; +import graphql.annotations.GraphQLFieldDefinitionWrapper; +import graphql.annotations.annotationTypes.GraphQLConnection; +import graphql.annotations.annotationTypes.GraphQLRelayMutation; import graphql.annotations.annotationTypes.GraphQLType; -import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.exceptions.CannotCastMemberException; +import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.retrievers.fieldBuilders.ArgumentBuilder; import graphql.annotations.processor.retrievers.fieldBuilders.DeprecateBuilder; import graphql.annotations.processor.retrievers.fieldBuilders.DescriptionBuilder; import graphql.annotations.processor.retrievers.fieldBuilders.field.FieldDataFetcherBuilder; import graphql.annotations.processor.retrievers.fieldBuilders.field.FieldNameBuilder; -import graphql.annotations.processor.retrievers.fieldBuilders.method.*; +import graphql.annotations.processor.retrievers.fieldBuilders.method.MethodDataFetcherBuilder; +import graphql.annotations.processor.retrievers.fieldBuilders.method.MethodNameBuilder; +import graphql.annotations.processor.retrievers.fieldBuilders.method.MethodTypeBuilder; import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; -import graphql.annotations.processor.exceptions.CannotCastMemberException; import graphql.annotations.processor.searchAlgorithms.ParentalSearch; import graphql.annotations.processor.typeFunctions.TypeFunction; import graphql.annotations.processor.util.ConnectionUtil; import graphql.annotations.processor.util.DataFetcherConstructor; import graphql.relay.Relay; import graphql.schema.*; -import graphql.schema.GraphQLNonNull; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; -import static graphql.annotations.processor.util.ReflectionKit.newInstance; import static graphql.annotations.processor.util.ObjectUtil.getAllFields; +import static graphql.annotations.processor.util.ReflectionKit.newInstance; import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; import static graphql.schema.GraphQLInputObjectField.newInputObjectField; -import static java.util.Arrays.stream; public class GraphQLFieldRetriever { @@ -110,7 +117,7 @@ public GraphQLFieldDefinition getField(Method method, ProcessingElementsContaine builder.description(new DescriptionBuilder(method).build()) .deprecate(new DeprecateBuilder(method).build()) .dataFetcher(new MethodDataFetcherBuilder(method, outputType, typeFunction, container, relayFieldDefinition, args, dataFetcherConstructor, isConnection).build()); - return new GraphQLAnnotations.GraphQLFieldDefinitionWrapper(builder.build()); + return new GraphQLFieldDefinitionWrapper(builder.build()); } private GraphQLFieldDefinition handleRelayArguments(Method method, ProcessingElementsContainer container, GraphQLFieldDefinition.Builder builder, GraphQLOutputType outputType, List args) { @@ -175,7 +182,7 @@ public GraphQLFieldDefinition getField(Field field, ProcessingElementsContainer .deprecate(new DeprecateBuilder(field).build()) .dataFetcher(new FieldDataFetcherBuilder(field, dataFetcherConstructor, outputType, typeFunction, container, isConnection).build()); - return new GraphQLAnnotations.GraphQLFieldDefinitionWrapper(builder.build()); + return new GraphQLFieldDefinitionWrapper(builder.build()); } private TypeFunction getTypeFunction(Field field, ProcessingElementsContainer container) { diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLInputObjectRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLInputObjectRetriever.java index 51e10cc3..3541ac42 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLInputObjectRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLInputObjectRetriever.java @@ -36,7 +36,7 @@ public class GraphQLInputObjectRetriever { public GraphQLInputType getInputObject(graphql.schema.GraphQLType graphQLType, String newNamePrefix, Map typeRegistry) { if (graphQLType instanceof GraphQLObjectType) { - return HandleGraphQLObjectType((GraphQLObjectType) graphQLType, newNamePrefix, typeRegistry); + return handleGraphQLObjectType((GraphQLObjectType) graphQLType, newNamePrefix, typeRegistry); } else if (graphQLType instanceof GraphQLList) { return new GraphQLList(getInputObject(((GraphQLList) graphQLType).getWrappedType(), newNamePrefix, typeRegistry)); } else if (graphQLType instanceof graphql.schema.GraphQLNonNull) { @@ -49,7 +49,7 @@ public GraphQLInputType getInputObject(graphql.schema.GraphQLType graphQLType, S throw new IllegalArgumentException("Cannot convert type to input : " + graphQLType); } - private GraphQLInputType HandleGraphQLObjectType(GraphQLObjectType graphQLType, String newNamePrefix, Map typeRegistry) { + private GraphQLInputType handleGraphQLObjectType(GraphQLObjectType graphQLType, String newNamePrefix, Map typeRegistry) { GraphQLObjectType object = graphQLType; String newObjectName = newNamePrefix + object.getName(); GraphQLType objectInTypeRegistry = typeRegistry.get(newObjectName);