From de01dc5d84320d37843065f6ba3757d1a5a970cf Mon Sep 17 00:00:00 2001 From: Yarin V Date: Mon, 21 Oct 2019 15:35:30 +0300 Subject: [PATCH 01/14] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 290ccde8..72ec1d55 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ [GraphQL-Java](https://github.com/andimarek/graphql-java) is a great library, but its syntax is a little bit verbose. This library offers an annotations-based syntax for GraphQL schema definition. +If you would like to use a tool that creates a graphql spring boot server using graphql-java-annotations, you can view the [graphql-spring-annotations](https://github.com/yarinvak/graphql-spring-annotations) library. + ## Table Of Contents - [Getting Started](#getting-started) From 0ff145aed2c029586bf90e348c85462fc04fe860 Mon Sep 17 00:00:00 2001 From: Yarin Date: Fri, 17 Jan 2020 17:57:19 +0200 Subject: [PATCH 02/14] docs: remove not null from readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72ec1d55..831b38ae 100644 --- a/README.md +++ b/README.md @@ -379,7 +379,7 @@ public class HumanExtension { ## Type Inference -By default, standard GraphQL types (String, Integer, Long, Float, Boolean, Enum, List) will be inferred from Java types. Also, it will respect `@javax.validation.constraints.NotNull` annotation with respect to value's nullability, as well as `@GraphQLNonNull` +By default, standard GraphQL types (String, Integer, Long, Float, Boolean, Enum, List) will be inferred from Java types. Also, it will respect `@GraphQLNonNull` with respect to value's nullability Stream type is also supported and treated as a list. From d2af00052e4a093fc688b1678e135d69d3020517 Mon Sep 17 00:00:00 2001 From: Yarin Date: Sat, 18 Jan 2020 00:43:48 +0200 Subject: [PATCH 03/14] feature: update to gql-java-14 --- build.gradle | 2 +- .../retrievers/GraphQLFieldRetriever.java | 21 ++++++------ .../retrievers/GraphQLTypeRetriever.java | 13 ++++---- .../fieldBuilders/ArgumentBuilder.java | 19 +++++++---- .../util/GraphQLTypeNameResolver.java | 23 +++++++++++++ .../graphql/annotations/GraphQLInputTest.java | 33 +++++++++---------- .../annotations/GraphQLInterfaceTest.java | 10 +++--- .../connection/GraphQLConnectionTest.java | 15 ++++----- .../GraphQLSimpleConnectionTest.java | 3 +- 9 files changed, 82 insertions(+), 57 deletions(-) create mode 100644 src/main/java/graphql/annotations/processor/util/GraphQLTypeNameResolver.java diff --git a/build.gradle b/build.gradle index 3b8ad3ba..100e075e 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,7 @@ gradle.projectsEvaluated { dependencies { compile 'javax.validation:validation-api:1.1.0.Final' - compile 'com.graphql-java:graphql-java:13.0' + compile 'com.graphql-java:graphql-java:14.0' // OSGi compileOnly 'org.osgi:org.osgi.core:6.0.0' diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java index cc8dc4ac..6060e9eb 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. @@ -49,6 +49,7 @@ import java.util.Map; import java.util.stream.Collectors; +import static graphql.annotations.processor.util.GraphQLTypeNameResolver.getName; import static graphql.annotations.processor.util.ReflectionKit.newInstance; import static graphql.schema.FieldCoordinates.coordinates; import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; @@ -154,10 +155,10 @@ private GraphQLFieldDefinition handleRelayArguments(Method method, ProcessingEle relayFieldDefinition = buildRelayMutation(method, container, builder, outputType, args); // Getting the data fetcher from the old field type and putting it as the new type - String newParentType = relayFieldDefinition.getType().getName(); + String newParentType = (getName(relayFieldDefinition.getType())); relayFieldDefinition.getType().getChildren().forEach(field -> { - DataFetcher dataFetcher = CodeRegistryUtil.getDataFetcher(container.getCodeRegistryBuilder(), outputType.getName(), (GraphQLFieldDefinition) field); - container.getCodeRegistryBuilder().dataFetcher(coordinates(newParentType, field.getName()), dataFetcher); + DataFetcher dataFetcher = CodeRegistryUtil.getDataFetcher(container.getCodeRegistryBuilder(), getName(outputType), (GraphQLFieldDefinition) field); + container.getCodeRegistryBuilder().dataFetcher(coordinates(newParentType, getName(field)), dataFetcher); }); } else { @@ -217,10 +218,10 @@ private GraphQLOutputType getGraphQLConnection(AccessibleObject field, graphql.s } private GraphQLOutputType internalGetGraphQLConnection(AccessibleObject field, GraphQLList listType, Relay relay, Map typeRegistry) { - GraphQLOutputType wrappedType = (GraphQLOutputType) listType.getWrappedType(); + GraphQLType wrappedType = 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); + connectionName = connectionName.isEmpty() ? getName(wrappedType) : connectionName; + GraphQLObjectType edgeType = getActualType(relay.edgeType(connectionName, (GraphQLOutputType) wrappedType, null, Collections.emptyList()), typeRegistry); return getActualType(relay.connectionType(connectionName, edgeType, Collections.emptyList()), typeRegistry); } diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java index 94628f85..1f0a48b9 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.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. @@ -23,6 +23,7 @@ import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.searchAlgorithms.SearchAlgorithm; import graphql.annotations.processor.typeBuilders.*; +import graphql.annotations.processor.util.GraphQLTypeNameResolver; import graphql.schema.*; import org.osgi.service.component.annotations.*; @@ -90,11 +91,11 @@ public GraphQLType getGraphQLType(Class object, ProcessingElementsContainer c DirectiveWirer directiveWirer = new DirectiveWirer(); // wire the type with the directives and change the original type - type = directiveWirer.wire((GraphQLDirectiveContainer) type, + type = (GraphQLType) directiveWirer.wire((GraphQLDirectiveContainer) type, new DirectiveWiringMapRetriever().getDirectiveWiringMap(object, container), container.getCodeRegistryBuilder(), null); - container.getTypeRegistry().put(type.getName(), type); + container.getTypeRegistry().put(GraphQLTypeNameResolver.getName(type), type); container.getProcessing().pop(); return type; 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 461851e4..f505c47d 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.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,16 +17,19 @@ import graphql.annotations.annotationTypes.GraphQLDefaultValue; import graphql.annotations.annotationTypes.GraphQLDescription; import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.directives.AnnotationsDirectiveWiring; import graphql.annotations.directives.DirectiveWirer; import graphql.annotations.directives.DirectiveWiringMapRetriever; import graphql.annotations.processor.ProcessingElementsContainer; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.typeFunctions.TypeFunction; +import graphql.annotations.processor.util.GraphQLTypeNameResolver; import graphql.schema.*; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; @@ -81,9 +84,11 @@ private GraphQLArgument getArgument(Parameter parameter, graphql.schema.GraphQLI argumentBuilder.name(toGraphqlName(parameter.getName())); } argumentBuilder.withDirectives(new DirectivesBuilder(parameter, container).build()); - return (GraphQLArgument) new DirectiveWirer().wire(argumentBuilder.build(), - new DirectiveWiringMapRetriever().getDirectiveWiringMap(parameter, container), container.getCodeRegistryBuilder(), - inputType.getName()); + GraphQLArgument builtArgument = argumentBuilder.build(); + HashMap directiveWiringMap = new DirectiveWiringMapRetriever().getDirectiveWiringMap(parameter, container); + return (GraphQLArgument) new DirectiveWirer().wire(builtArgument, + directiveWiringMap, container.getCodeRegistryBuilder(), + GraphQLTypeNameResolver.getName(inputType)); } } diff --git a/src/main/java/graphql/annotations/processor/util/GraphQLTypeNameResolver.java b/src/main/java/graphql/annotations/processor/util/GraphQLTypeNameResolver.java new file mode 100644 index 00000000..34f555e4 --- /dev/null +++ b/src/main/java/graphql/annotations/processor/util/GraphQLTypeNameResolver.java @@ -0,0 +1,23 @@ +package graphql.annotations.processor.util; + +import graphql.schema.*; + +public class GraphQLTypeNameResolver { + public static String getName(GraphQLSchemaElement graphQLSchemaElement) { + try { + return ((GraphQLNamedSchemaElement) graphQLSchemaElement).getName(); + } catch (Exception exception) { + if (graphQLSchemaElement instanceof GraphQLNonNull) { + return getName(((GraphQLNonNull) graphQLSchemaElement).getWrappedType()); + } else if (graphQLSchemaElement instanceof GraphQLList) { + GraphQLType iterator = (GraphQLType) graphQLSchemaElement; + do { + iterator = ((GraphQLList) iterator).getWrappedType(); + } while (iterator instanceof GraphQLList); + return getName(iterator); + } else { + throw new RuntimeException("Cannot determine name for schema element"); + } + } + } +} diff --git a/src/test/java/graphql/annotations/GraphQLInputTest.java b/src/test/java/graphql/annotations/GraphQLInputTest.java index bf918ebc..e7d84221 100644 --- a/src/test/java/graphql/annotations/GraphQLInputTest.java +++ b/src/test/java/graphql/annotations/GraphQLInputTest.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,10 +22,7 @@ import graphql.annotations.annotationTypes.GraphQLTypeResolver; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; -import graphql.schema.GraphQLInputObjectType; -import graphql.schema.GraphQLObjectType; -import graphql.schema.GraphQLSchema; -import graphql.schema.TypeResolver; +import graphql.schema.*; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -297,10 +294,10 @@ public void testInputAndOutputWithSameName() { // arrange + act GraphQLSchema schema = newSchema().query(this.graphQLAnnotations.object(QueryInputAndOutput.class)).build(); // assert - assertEquals(schema.getQueryType().getFieldDefinition("getHero").getType().getName(), "hero"); - assertEquals(schema.getQueryType().getFieldDefinition("getString").getArgument("input").getType().getName(), "Inputhero"); - assertEquals(((GraphQLInputObjectType) schema.getQueryType().getFieldDefinition("getString") - .getArgument("input").getType()).getField("skill").getType().getName(), "InputSkill"); + assertEquals(((GraphQLNamedType) (schema.getQueryType().getFieldDefinition("getHero").getType())).getName(), "hero"); + assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getString").getArgument("input").getType()).getName(), "Inputhero"); + assertEquals(((GraphQLNamedType) ((GraphQLInputObjectType) schema.getQueryType().getFieldDefinition("getString") + .getArgument("input").getType()).getField("skill").getType()).getName(), "InputSkill"); } @Test @@ -308,8 +305,8 @@ public void testInputAndOutputSameClass() { // arrange + act GraphQLSchema schema = newSchema().query(this.graphQLAnnotations.object(QueryInputAndOutput2.class)).build(); // assert - assertEquals(schema.getQueryType().getFieldDefinition("getSkill").getType().getName(), "Skill"); - assertEquals(schema.getQueryType().getFieldDefinition("getA").getArgument("skill").getType().getName(), "InputSkill"); + assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getSkill").getType()).getName(), "Skill"); + assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getA").getArgument("skill").getType()).getName(), "InputSkill"); } @GraphQLName("A") @@ -366,11 +363,11 @@ public void testInputAndOutputWithSameNameWithChildrenWithSameName() { // arrange + act GraphQLSchema schema = newSchema().query(this.graphQLAnnotations.object(QuerySameNameWithChildren.class)).build(); // assert - assertEquals(schema.getQueryType().getFieldDefinition("getAout").getType().getName(), "A"); - assertEquals(schema.getQueryType().getFieldDefinition("getAout").getType().getClass(), GraphQLObjectType.class); - assertEquals(schema.getQueryType().getFieldDefinition("getBout").getType().getName(), "B"); + assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getAout").getType()).getName(), "A"); + assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getAout").getType()).getClass(), GraphQLObjectType.class); + assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getBout").getType()).getName(), "B"); assertEquals(schema.getQueryType().getFieldDefinition("getBout").getType().getClass(), GraphQLObjectType.class); - assertEquals(schema.getQueryType().getFieldDefinition("getA").getArgument("input").getType().getName(), "InputA"); + assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getA").getArgument("input").getType()).getName(), "InputA"); assertEquals(schema.getQueryType().getFieldDefinition("getA").getArgument("input").getType().getClass(), GraphQLInputObjectType.class); assertEquals(schema.getQueryType().getFieldDefinition("getB").getArgument("input").getType().getClass(), GraphQLInputObjectType.class); diff --git a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java index f461fc9f..f69af33a 100644 --- a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java +++ b/src/test/java/graphql/annotations/GraphQLInterfaceTest.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. @@ -129,7 +129,7 @@ public void testUnion() { @Test public void testInterfaces() { GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); - List ifaces = object.getInterfaces(); + List ifaces = object.getInterfaces(); assertEquals(ifaces.size(), 1); assertEquals(ifaces.get(0).getName(), "TestIface"); } diff --git a/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java b/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java index 94283ac7..1e47182e 100644 --- a/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java +++ b/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.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,10 +24,7 @@ import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.util.CustomRelay; import graphql.relay.Relay; -import graphql.schema.DataFetchingEnvironment; -import graphql.schema.GraphQLList; -import graphql.schema.GraphQLObjectType; -import graphql.schema.GraphQLSchema; +import graphql.schema.*; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -162,7 +159,7 @@ public void customRelayMethodList() { graphql.schema.GraphQLObjectType f = (GraphQLObjectType) schema.getType("ObjConnection"); assertTrue(f.getFieldDefinitions().size() == 4); assertTrue(f.getFieldDefinition("nodes").getType() instanceof GraphQLList); - assertEquals(((GraphQLList) f.getFieldDefinition("nodes").getType()).getWrappedType().getName(), "Obj"); + assertEquals(((GraphQLNamedType) ((GraphQLList) f.getFieldDefinition("nodes").getType()).getWrappedType()).getName(), "Obj"); GraphQLObjectType pageInfo = (GraphQLObjectType) schema.getType("PageInfo"); assertTrue(pageInfo.getFieldDefinition("additionalInfo") != null); diff --git a/src/test/java/graphql/annotations/connection/GraphQLSimpleConnectionTest.java b/src/test/java/graphql/annotations/connection/GraphQLSimpleConnectionTest.java index 43008ec8..3f948332 100644 --- a/src/test/java/graphql/annotations/connection/GraphQLSimpleConnectionTest.java +++ b/src/test/java/graphql/annotations/connection/GraphQLSimpleConnectionTest.java @@ -23,6 +23,7 @@ import graphql.annotations.processor.GraphQLAnnotations; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; +import graphql.schema.GraphQLNamedType; import graphql.schema.GraphQLSchema; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -50,7 +51,7 @@ public void init() { public void simpleConnection_buildSchema_TypeOfSimpleConnectionIsGraphQLList() throws Exception { GraphQLSchema schema = newAnnotationsSchema().query(MainConnection.class).build(); - String objsTypeName = schema.getQueryType().getFieldDefinition("objs").getType().getName(); + String objsTypeName = ((GraphQLNamedType)schema.getQueryType().getFieldDefinition("objs").getType()).getName(); assertThat(objsTypeName, is("ObjChunk")); } From 5d5c1455cf476d8d3e39694e74980c8980b9284e Mon Sep 17 00:00:00 2001 From: Yarin Date: Sun, 19 Jan 2020 01:25:56 +0200 Subject: [PATCH 04/14] breaking change: transform directives to work with graphql-java SchemaTransformer, and remove all deprecated methods from GraphQLAnnotations class --- .../annotations/AnnotationsSchemaCreator.java | 48 +- .../AnnotationsWiringEnvironment.java | 3 +- .../AnnotationsWiringEnvironmentImpl.java | 13 +- .../directives/DirectiveSchemaVisitor.java | 173 ++ .../directives/DirectiveWirer.java | 101 - .../processor/GraphQLAnnotations.java | 21 - .../directives/DirectiveArgumentCreator.java | 3 +- .../retrievers/GraphQLFieldRetriever.java | 24 +- .../retrievers/GraphQLTypeRetriever.java | 9 - .../fieldBuilders/ArgumentBuilder.java | 11 +- .../processor/util/CodeRegistryUtil.java | 21 +- ...DirectivesViaAnnotationDefinitionTest.java | 9 +- ...aphQLDirectivesViaClassDefinitionTest.java | 94 +- ...phQLDirectivesViaMethodDefinitionTest.java | 9 +- .../annotations/GraphQLObjectTest.java | 1802 ++++++++--------- .../annotations/SchemaTransformerTest.java | 111 + .../directives/DirectiveWirerTest.java | 1034 +++++----- 17 files changed, 1806 insertions(+), 1680 deletions(-) create mode 100644 src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java delete mode 100644 src/main/java/graphql/annotations/directives/DirectiveWirer.java create mode 100644 src/test/java/graphql/annotations/SchemaTransformerTest.java diff --git a/src/main/java/graphql/annotations/AnnotationsSchemaCreator.java b/src/main/java/graphql/annotations/AnnotationsSchemaCreator.java index 2b9c48e8..1001b5ef 100644 --- a/src/main/java/graphql/annotations/AnnotationsSchemaCreator.java +++ b/src/main/java/graphql/annotations/AnnotationsSchemaCreator.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. @@ -14,17 +14,22 @@ */ package graphql.annotations; +import graphql.annotations.directives.AnnotationsDirectiveWiring; +import graphql.annotations.directives.DirectiveSchemaVisitor; +import graphql.annotations.processor.DirectiveAndWiring; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.typeFunctions.TypeFunction; import graphql.relay.Relay; import graphql.schema.GraphQLDirective; import graphql.schema.GraphQLSchema; import graphql.schema.GraphQLType; +import graphql.schema.SchemaTransformer; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; +import static graphql.schema.GraphQLSchema.newSchema; + public class AnnotationsSchemaCreator { public static Builder newAnnotationsSchema() { @@ -43,6 +48,7 @@ public static class Builder { private Boolean shouldAlwaysPrettify = null; private GraphQLAnnotations graphQLAnnotations; private GraphQLSchema.Builder graphqlSchemaBuilder; + private SchemaTransformer schemaTransformer = new SchemaTransformer(); /** * You can set your own schema builder, but its optional @@ -114,12 +120,18 @@ public Builder directives(Set> directiveClasses) { return this; } + public Builder directives(Class... directiveClasses) { + this.directivesObjectList.addAll(Arrays.asList(directiveClasses)); + return this; + } + /** * Add directive declaration class to create directives for the graphql schema + * * @param directiveContainerClass a directive container class (directives are defined as methods inside the class) * @return the builder after adding the directive container class to the list of directive container classes */ - public Builder directives(Class directiveContainerClass){ + public Builder directives(Class directiveContainerClass) { this.directiveContainerClasses.add(directiveContainerClass); return this; } @@ -234,7 +246,7 @@ public GraphQLSchema build() { } Set directives = directivesObjectList.stream().map(dir -> graphQLAnnotations.directive(dir)).collect(Collectors.toSet()); - directiveContainerClasses.forEach(dir->directives.addAll(graphQLAnnotations.directives(dir))); + directiveContainerClasses.forEach(dir -> directives.addAll(graphQLAnnotations.directives(dir))); Set additionalTypes = additionalTypesList.stream().map(additionalType -> additionalType.isInterface() ? @@ -252,7 +264,25 @@ public GraphQLSchema build() { } this.graphqlSchemaBuilder.additionalTypes(additionalTypes).additionalType(Relay.pageInfoType) .codeRegistry(graphQLAnnotations.getContainer().getCodeRegistryBuilder().build()); - return this.graphqlSchemaBuilder.build(); + GraphQLSchema schema = this.graphqlSchemaBuilder.build(); + // wire with directives + HashMap directiveWiringHashMap = transformDirectiveRegistry(this.graphQLAnnotations.getContainer().getDirectiveRegistry()); + DirectiveSchemaVisitor directiveSchemaVisitor = new DirectiveSchemaVisitor(directiveWiringHashMap, graphQLAnnotations.getContainer().getCodeRegistryBuilder()); + GraphQLSchema trasnformedSchema = this.schemaTransformer.transform(schema, directiveSchemaVisitor); + return newSchema(trasnformedSchema).codeRegistry(graphQLAnnotations.getContainer().getCodeRegistryBuilder().build()).build(); + } + + private HashMap transformDirectiveRegistry(Map directiveRegistry) { + HashMap map = new HashMap<>(); + directiveRegistry.forEach((directiveName, directiveAndWiring) -> { + try { + map.put(directiveName, directiveAndWiring.getWiringClass().newInstance()); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + + return map; } } } diff --git a/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironment.java b/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironment.java index 4dcc6350..71f641a9 100644 --- a/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironment.java +++ b/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironment.java @@ -17,6 +17,7 @@ import graphql.schema.GraphQLCodeRegistry; import graphql.schema.GraphQLDirective; import graphql.schema.GraphQLDirectiveContainer; +import graphql.schema.GraphQLSchemaElement; public interface AnnotationsWiringEnvironment { /** @@ -33,7 +34,7 @@ public interface AnnotationsWiringEnvironment { * * @return the parent name of the element */ - String getParentName(); + GraphQLSchemaElement getParentElement(); /** diff --git a/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironmentImpl.java b/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironmentImpl.java index b3fbb963..576fba59 100644 --- a/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironmentImpl.java +++ b/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironmentImpl.java @@ -17,18 +17,19 @@ import graphql.schema.GraphQLCodeRegistry; import graphql.schema.GraphQLDirective; import graphql.schema.GraphQLDirectiveContainer; +import graphql.schema.GraphQLSchemaElement; public class AnnotationsWiringEnvironmentImpl implements AnnotationsWiringEnvironment { private final GraphQLDirectiveContainer element; private final GraphQLDirective directive; - private final String parentName; + private final GraphQLSchemaElement parentElement; private GraphQLCodeRegistry.Builder codeRegistryBuilder; public AnnotationsWiringEnvironmentImpl(GraphQLDirectiveContainer element, GraphQLDirective directive, - String parentName, GraphQLCodeRegistry.Builder codeRegistryBuilder) { + GraphQLSchemaElement parentELement, GraphQLCodeRegistry.Builder codeRegistryBuilder) { this.element = element; this.directive = directive; - this.parentName = parentName; + this.parentElement = parentELement; this.codeRegistryBuilder = codeRegistryBuilder; } @@ -43,8 +44,8 @@ public GraphQLDirective getDirective() { } @Override - public String getParentName() { - return parentName; + public GraphQLSchemaElement getParentElement() { + return parentElement; } @Override @@ -60,7 +61,7 @@ public boolean equals(Object o) { AnnotationsWiringEnvironmentImpl that = (AnnotationsWiringEnvironmentImpl) o; if (element != null ? !element.equals(that.element) : that.element != null) return false; - if (parentName != null ? !parentName.equals(that.parentName) : that.parentName != null) return false; + if (parentElement != null ? !parentElement.equals(that.parentElement) : that.parentElement != null) return false; if (codeRegistryBuilder != null ? !codeRegistryBuilder.equals(that.codeRegistryBuilder) : that.codeRegistryBuilder != null) return false; return directive != null ? directive.equals(that.directive) : that.directive == null; diff --git a/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java b/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java new file mode 100644 index 00000000..ee6ab5de --- /dev/null +++ b/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java @@ -0,0 +1,173 @@ +package graphql.annotations.directives; + +import graphql.introspection.Introspection; +import graphql.schema.*; +import graphql.util.TraversalControl; +import graphql.util.TraverserContext; + +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static graphql.util.TreeTransformerUtil.changeNode; + +public class DirectiveSchemaVisitor implements GraphQLTypeVisitor { + private HashMap directiveWiringMap; + private GraphQLCodeRegistry.Builder codeRegistryBuilder; + + @FunctionalInterface + interface WiringFunction { + GraphQLDirectiveContainer apply(GraphQLDirective a, GraphQLDirectiveContainer b, + AnnotationsDirectiveWiring wiring, GraphQLSchemaElement parentElement) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException; + } + + private Map functionMap; + + + public DirectiveSchemaVisitor(HashMap directiveWiringMap, GraphQLCodeRegistry.Builder codeRegistryBuilder) { + this.directiveWiringMap = directiveWiringMap; + this.functionMap = createFunctionsMap(); + this.codeRegistryBuilder = codeRegistryBuilder; + } + + @Override + public TraversalControl visitGraphQLArgument(GraphQLArgument node, TraverserContext context) { + return this.visitGraphQLType(GraphQLArgument.class, node, context); + } + + + @Override + public TraversalControl visitGraphQLInterfaceType(GraphQLInterfaceType node, TraverserContext context) { + return this.visitGraphQLType(GraphQLInterfaceType.class, node, context); + } + + @Override + public TraversalControl visitGraphQLEnumType(GraphQLEnumType node, TraverserContext context) { + return this.visitGraphQLType(GraphQLEnumType.class, node, context); + } + + @Override + public TraversalControl visitGraphQLEnumValueDefinition(GraphQLEnumValueDefinition node, TraverserContext context) { + return this.visitGraphQLType(GraphQLEnumValueDefinition.class, node, context); + } + + @Override + public TraversalControl visitGraphQLFieldDefinition(GraphQLFieldDefinition node, TraverserContext context) { + return this.visitGraphQLType(GraphQLFieldDefinition.class, node, context); + } + + @Override + public TraversalControl visitGraphQLDirective(GraphQLDirective node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLInputObjectField(GraphQLInputObjectField node, TraverserContext context) { + return this.visitGraphQLType(GraphQLInputObjectField.class, node, context); + } + + @Override + public TraversalControl visitGraphQLInputObjectType(GraphQLInputObjectType node, TraverserContext context) { + return this.visitGraphQLType(GraphQLInputObjectType.class, node, context); + } + + @Override + public TraversalControl visitGraphQLList(GraphQLList node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLNonNull(GraphQLNonNull node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLObjectType(GraphQLObjectType node, TraverserContext context) { + return this.visitGraphQLType(GraphQLObjectType.class, node, context); + } + + @Override + public TraversalControl visitGraphQLScalarType(GraphQLScalarType node, TraverserContext context) { + return this.visitGraphQLType(GraphQLScalarType.class, node, context); + } + + @Override + public TraversalControl visitGraphQLTypeReference(GraphQLTypeReference node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLUnionType(GraphQLUnionType node, TraverserContext context) { + return this.visitGraphQLType(GraphQLUnionType.class, node, context); + } + + private TraversalControl visitGraphQLType(Class typeOfContainer, + GraphQLDirectiveContainer node, TraverserContext context) { + List directives = node.getDirectives(); + if (directives.size() == 0) { + return TraversalControl.CONTINUE; + } + GraphQLDirectiveContainer newNode = node; + for (GraphQLDirective directive : directives) { + AnnotationsDirectiveWiring wiring = this.directiveWiringMap.get(directive.getName()); + if (wiring != null) { + try { + GraphQLSchemaElement parentElement = context.getParentNode(); + newNode = functionMap.get(typeOfContainer).apply(directive, newNode, + wiring, parentElement); + } catch (Exception e) { + e.printStackTrace(); + return TraversalControl.CONTINUE; + } + } + } + return changeNode(context, newNode); + } + + private void putInMap(Map map, Class clazz, String functionName, + Introspection.DirectiveLocation... locations) { + map.put(clazz, (d, e, wiring, parentElement) -> { + assertLocation(d, e, locations); + AnnotationsWiringEnvironmentImpl environment = + new AnnotationsWiringEnvironmentImpl(e, e.getDirective(d.getName()), parentElement, codeRegistryBuilder); + return (GraphQLDirectiveContainer) wiring.getClass().getMethod(functionName, AnnotationsWiringEnvironment.class) + .invoke(wiring, environment); + }); + } + + private Map createFunctionsMap() { + Map functionMap = new HashMap<>(); + putInMap(functionMap, GraphQLFieldDefinition.class, "onField", Introspection.DirectiveLocation.FIELD, Introspection.DirectiveLocation.FIELD_DEFINITION); + putInMap(functionMap, GraphQLObjectType.class, "onObject", Introspection.DirectiveLocation.OBJECT); + putInMap(functionMap, GraphQLArgument.class, "onArgument", Introspection.DirectiveLocation.ARGUMENT_DEFINITION); + putInMap(functionMap, GraphQLInterfaceType.class, "onInterface", Introspection.DirectiveLocation.INTERFACE); + putInMap(functionMap, GraphQLUnionType.class, "onUnion", Introspection.DirectiveLocation.UNION); + putInMap(functionMap, GraphQLEnumType.class, "onEnum", Introspection.DirectiveLocation.ENUM); + putInMap(functionMap, GraphQLEnumValueDefinition.class, "onEnumValue", Introspection.DirectiveLocation.ENUM_VALUE); + putInMap(functionMap, GraphQLScalarType.class, "onScalar", Introspection.DirectiveLocation.SCALAR); + putInMap(functionMap, GraphQLInputObjectType.class, "onInputObjectType", Introspection.DirectiveLocation.INPUT_OBJECT); + putInMap(functionMap, GraphQLInputObjectField.class, "onInputObjectField", Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION); + + return functionMap; + } + + private void assertLocation(GraphQLDirective graphQLDirective, GraphQLDirectiveContainer element, Introspection.DirectiveLocation... validLocations) { + boolean isSupported = false; + for (Introspection.DirectiveLocation validLocation : validLocations) { + if (graphQLDirective.validLocations().contains(validLocation)) { + isSupported = true; + } + } + if (!isSupported) { + throw getInvalidDirectiveLocationException(element, graphQLDirective, validLocations); + } + } + + private InvalidDirectiveLocationException getInvalidDirectiveLocationException(GraphQLDirectiveContainer element, GraphQLDirective graphQLDirective, Introspection.DirectiveLocation... validLocations) { + return new InvalidDirectiveLocationException("The element: '" + element.getName() + "' is annotated with the directive: '" + + graphQLDirective.getName() + "' which is not valid on the element location: '" + Arrays.toString(Arrays.stream(validLocations).map(Enum::name).toArray()) + "'", null); + } +} diff --git a/src/main/java/graphql/annotations/directives/DirectiveWirer.java b/src/main/java/graphql/annotations/directives/DirectiveWirer.java deleted file mode 100644 index 0ae85e15..00000000 --- a/src/main/java/graphql/annotations/directives/DirectiveWirer.java +++ /dev/null @@ -1,101 +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.directives; - -import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; -import graphql.introspection.Introspection; -import graphql.schema.*; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -public class DirectiveWirer { - @FunctionalInterface - interface WiringFunction { - GraphQLDirectiveContainer apply(GraphQLDirective a, GraphQLDirectiveContainer b, - AnnotationsDirectiveWiring wiring, GraphQLCodeRegistry.Builder codeRegistryBuilder, String parentName) - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException; - } - - private Map functionMap; - - public DirectiveWirer() { - functionMap = createFunctionsMap(); - } - - private void putInMap(Map map, Class clazz, String functionName, - Introspection.DirectiveLocation... locations) { - map.put(clazz, (d, e, wiring, codeRegistryBuilder, parentName) -> { - assertLocation(d, e, locations); - AnnotationsWiringEnvironmentImpl environment = - new AnnotationsWiringEnvironmentImpl(e, e.getDirective(d.getName()), parentName, codeRegistryBuilder); - return (GraphQLDirectiveContainer) wiring.getClass().getMethod(functionName, AnnotationsWiringEnvironment.class) - .invoke(wiring, environment); - }); - } - - private Map createFunctionsMap() { - Map functionMap = new HashMap<>(); - putInMap(functionMap, GraphQLFieldDefinition.class, "onField", Introspection.DirectiveLocation.FIELD, Introspection.DirectiveLocation.FIELD_DEFINITION); - putInMap(functionMap, GraphQLObjectType.class, "onObject", Introspection.DirectiveLocation.OBJECT); - putInMap(functionMap, GraphQLArgument.class, "onArgument", Introspection.DirectiveLocation.ARGUMENT_DEFINITION); - putInMap(functionMap, GraphQLInterfaceType.class, "onInterface", Introspection.DirectiveLocation.INTERFACE); - putInMap(functionMap, GraphQLUnionType.class, "onUnion", Introspection.DirectiveLocation.UNION); - putInMap(functionMap, GraphQLEnumType.class, "onEnum", Introspection.DirectiveLocation.ENUM); - putInMap(functionMap, GraphQLEnumValueDefinition.class, "onEnumValue", Introspection.DirectiveLocation.ENUM_VALUE); - putInMap(functionMap, GraphQLScalarType.class, "onScalar", Introspection.DirectiveLocation.SCALAR); - putInMap(functionMap, GraphQLInputObjectType.class, "onInputObjectType", Introspection.DirectiveLocation.INPUT_OBJECT); - putInMap(functionMap, GraphQLInputObjectField.class, "onInputObjectField", Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION); - - return functionMap; - } - - public GraphQLDirectiveContainer wire(GraphQLDirectiveContainer element, HashMap directiveWiringMap - , GraphQLCodeRegistry.Builder codeRegistryBuilder, String parentName) { - for (Map.Entry entry : directiveWiringMap.entrySet()) { - GraphQLDirective graphQLDirective = entry.getKey(); - AnnotationsDirectiveWiring wiring = entry.getValue(); - - Class aClass = element.getClass(); - try { - element = functionMap.get(aClass).apply(graphQLDirective, element, wiring, codeRegistryBuilder, parentName); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - throw new GraphQLAnnotationsException(e.getMessage(), e); - } - } - - return element; - } - - private void assertLocation(GraphQLDirective graphQLDirective, GraphQLDirectiveContainer element, Introspection.DirectiveLocation... validLocations) { - boolean isSupported = false; - for (Introspection.DirectiveLocation validLocation : validLocations) { - if (graphQLDirective.validLocations().contains(validLocation)) { - isSupported = true; - } - } - if (!isSupported) { - throw getInvalidDirectiveLocationException(element, graphQLDirective, validLocations); - } - } - - private InvalidDirectiveLocationException getInvalidDirectiveLocationException(GraphQLDirectiveContainer element, GraphQLDirective graphQLDirective, Introspection.DirectiveLocation... validLocations) { - return new InvalidDirectiveLocationException("The element: '" + element.getName() + "' is annotated with the directive: '" - + graphQLDirective.getName() + "' which is not valid on the element location: '" + Arrays.toString(Arrays.stream(validLocations).map(Enum::name).toArray()) + "'", null); - } - -} diff --git a/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java b/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java index 38122693..e094383c 100644 --- a/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java +++ b/src/main/java/graphql/annotations/processor/GraphQLAnnotations.java @@ -129,18 +129,6 @@ public GraphQLObjectType object(Class object) throws GraphQLAnnotationsExcept } } - @Deprecated - public GraphQLObjectType object(Class object, DirectiveAndWiring... directives) throws GraphQLAnnotationsException { - Arrays.stream(directives).forEach(directiveAndWiring -> this.getContainer().getDirectiveRegistry().put(directiveAndWiring.getDirective().getName(), directiveAndWiring)); - try { - return this.graphQLObjectHandler.getGraphQLType(object, this.getContainer()); - } catch (GraphQLAnnotationsException e) { - this.getContainer().getProcessing().clear(); - this.getTypeRegistry().clear(); - throw e; - } - } - public GraphQLDirective directive(Class object) throws GraphQLAnnotationsException { if (!object.isAnnotationPresent(GraphQLDirectiveDefinition.class)){ throw new GraphQLAnnotationsException(String.format(NOT_PROPERLY_ANNOTATION_ERROR, object.getSimpleName()), null); @@ -158,11 +146,6 @@ public GraphQLDirective directive(Class object) throws GraphQLAnnotationsExce } } - @Deprecated - public GraphQLDirective directiveViaAnnotation(Class annotationClass) { - return this.directive(annotationClass); - } - public Set directives(Class directivesDeclarationClass) { Method[] methods = directivesDeclarationClass.getMethods(); Set directiveSet = new HashSet<>(); @@ -189,10 +172,6 @@ public void registerTypeFunction(TypeFunction typeFunction) { ((DefaultTypeFunction) container.getDefaultTypeFunction()).register(typeFunction); } - @Deprecated - public void register(TypeFunction typeFunction) { - this.registerTypeFunction(typeFunction); - } public Map getTypeRegistry() { return container.getTypeRegistry(); diff --git a/src/main/java/graphql/annotations/processor/directives/DirectiveArgumentCreator.java b/src/main/java/graphql/annotations/processor/directives/DirectiveArgumentCreator.java index 39ba355d..5fbbbbd1 100644 --- a/src/main/java/graphql/annotations/processor/directives/DirectiveArgumentCreator.java +++ b/src/main/java/graphql/annotations/processor/directives/DirectiveArgumentCreator.java @@ -15,7 +15,6 @@ package graphql.annotations.processor.directives; import graphql.annotations.processor.ProcessingElementsContainer; -import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.typeFunctions.TypeFunction; import graphql.schema.GraphQLArgument; import graphql.schema.GraphQLInputType; @@ -45,7 +44,7 @@ public GraphQLArgument getArgument(Field field, Class containingClass) { try { builder.defaultValue(getDefaultValue(field, containingClass)); } catch (IllegalAccessException | InstantiationException e) { - throw new GraphQLAnnotationsException(e); + builder.defaultValue(null); } return builder.build(); diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java index 6060e9eb..ad954b47 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java @@ -17,8 +17,6 @@ import graphql.annotations.annotationTypes.GraphQLRelayMutation; import graphql.annotations.connection.GraphQLConnection; -import graphql.annotations.directives.DirectiveWirer; -import graphql.annotations.directives.DirectiveWiringMapRetriever; import graphql.annotations.processor.ProcessingElementsContainer; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.retrievers.fieldBuilders.ArgumentBuilder; @@ -93,10 +91,7 @@ public GraphQLFieldDefinition getField(String parentName, Method method, Process DataFetcher dataFetcher = new MethodDataFetcherBuilder(method, outputType, typeFunction, container, relayFieldDefinition, args, dataFetcherConstructor, isConnection).build(); container.getCodeRegistryBuilder().dataFetcher(coordinates(parentName, fieldName), dataFetcher); - - return (GraphQLFieldDefinition) new DirectiveWirer().wire(builder.build(), - new DirectiveWiringMapRetriever().getDirectiveWiringMap(method, container), - container.getCodeRegistryBuilder(), parentName); + return builder.build(); } public GraphQLFieldDefinition getField(String parentName, Field field, ProcessingElementsContainer container) throws GraphQLAnnotationsException { @@ -121,9 +116,7 @@ public GraphQLFieldDefinition getField(String parentName, Field field, Processin GraphQLDirective[] graphQLDirectives = new DirectivesBuilder(field, container).build(); builder.withDirectives(graphQLDirectives); - return (GraphQLFieldDefinition) new DirectiveWirer().wire(builder.build(), - new DirectiveWiringMapRetriever().getDirectiveWiringMap(field, container), - container.getCodeRegistryBuilder(), parentName); + return builder.build(); } public GraphQLInputObjectField getInputField(Method method, ProcessingElementsContainer container, String parentName) throws GraphQLAnnotationsException { @@ -132,10 +125,8 @@ public GraphQLInputObjectField getInputField(Method method, ProcessingElementsCo TypeFunction typeFunction = getTypeFunction(method, container); GraphQLInputType inputType = (GraphQLInputType) new MethodTypeBuilder(method, typeFunction, container, true).build(); builder.withDirectives(new DirectivesBuilder(method, container).build()); - return (GraphQLInputObjectField) new DirectiveWirer().wire(builder.type(inputType) - .description(new DescriptionBuilder(method).build()).build(), - new DirectiveWiringMapRetriever().getDirectiveWiringMap(method, container), container.getCodeRegistryBuilder(), parentName - ); + return builder.type(inputType) + .description(new DescriptionBuilder(method).build()).build(); } public GraphQLInputObjectField getInputField(Field field, ProcessingElementsContainer container, String parentName) throws GraphQLAnnotationsException { @@ -144,9 +135,8 @@ public GraphQLInputObjectField getInputField(Field field, ProcessingElementsCont TypeFunction typeFunction = getTypeFunction(field, container); GraphQLType graphQLType = typeFunction.buildType(true, field.getType(), field.getAnnotatedType(), container); builder.withDirectives(new DirectivesBuilder(field, container).build()); - return (GraphQLInputObjectField) new DirectiveWirer().wire(builder.type((GraphQLInputType) graphQLType) - .description(new DescriptionBuilder(field).build()).build(), - new DirectiveWiringMapRetriever().getDirectiveWiringMap(field, container), container.getCodeRegistryBuilder(), parentName); + return builder.type((GraphQLInputType) graphQLType) + .description(new DescriptionBuilder(field).build()).build(); } private GraphQLFieldDefinition handleRelayArguments(Method method, ProcessingElementsContainer container, GraphQLFieldDefinition.Builder builder, GraphQLOutputType outputType, List args) { @@ -157,7 +147,7 @@ private GraphQLFieldDefinition handleRelayArguments(Method method, ProcessingEle // Getting the data fetcher from the old field type and putting it as the new type String newParentType = (getName(relayFieldDefinition.getType())); relayFieldDefinition.getType().getChildren().forEach(field -> { - DataFetcher dataFetcher = CodeRegistryUtil.getDataFetcher(container.getCodeRegistryBuilder(), getName(outputType), (GraphQLFieldDefinition) field); + DataFetcher dataFetcher = CodeRegistryUtil.getDataFetcher(container.getCodeRegistryBuilder(), outputType, (GraphQLFieldDefinition) field); container.getCodeRegistryBuilder().dataFetcher(coordinates(newParentType, getName(field)), dataFetcher); }); diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java index 1f0a48b9..7e85f567 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java @@ -16,8 +16,6 @@ import graphql.annotations.annotationTypes.GraphQLTypeResolver; import graphql.annotations.annotationTypes.GraphQLUnion; -import graphql.annotations.directives.DirectiveWirer; -import graphql.annotations.directives.DirectiveWiringMapRetriever; import graphql.annotations.processor.ProcessingElementsContainer; import graphql.annotations.processor.exceptions.CannotCastMemberException; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; @@ -88,13 +86,6 @@ public GraphQLType getGraphQLType(Class object, ProcessingElementsContainer c } } - DirectiveWirer directiveWirer = new DirectiveWirer(); - - // wire the type with the directives and change the original type - type = (GraphQLType) directiveWirer.wire((GraphQLDirectiveContainer) type, - new DirectiveWiringMapRetriever().getDirectiveWiringMap(object, container), - container.getCodeRegistryBuilder(), null); - container.getTypeRegistry().put(GraphQLTypeNameResolver.getName(type), type); container.getProcessing().pop(); 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 f505c47d..541262c7 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java @@ -17,19 +17,14 @@ import graphql.annotations.annotationTypes.GraphQLDefaultValue; import graphql.annotations.annotationTypes.GraphQLDescription; import graphql.annotations.annotationTypes.GraphQLName; -import graphql.annotations.directives.AnnotationsDirectiveWiring; -import graphql.annotations.directives.DirectiveWirer; -import graphql.annotations.directives.DirectiveWiringMapRetriever; import graphql.annotations.processor.ProcessingElementsContainer; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; import graphql.annotations.processor.typeFunctions.TypeFunction; -import graphql.annotations.processor.util.GraphQLTypeNameResolver; import graphql.schema.*; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; @@ -84,11 +79,7 @@ private GraphQLArgument getArgument(Parameter parameter, graphql.schema.GraphQLI argumentBuilder.name(toGraphqlName(parameter.getName())); } argumentBuilder.withDirectives(new DirectivesBuilder(parameter, container).build()); - GraphQLArgument builtArgument = argumentBuilder.build(); - HashMap directiveWiringMap = new DirectiveWiringMapRetriever().getDirectiveWiringMap(parameter, container); - return (GraphQLArgument) new DirectiveWirer().wire(builtArgument, - directiveWiringMap, container.getCodeRegistryBuilder(), - GraphQLTypeNameResolver.getName(inputType)); + return argumentBuilder.build(); } } diff --git a/src/main/java/graphql/annotations/processor/util/CodeRegistryUtil.java b/src/main/java/graphql/annotations/processor/util/CodeRegistryUtil.java index f9e70aca..9c587797 100644 --- a/src/main/java/graphql/annotations/processor/util/CodeRegistryUtil.java +++ b/src/main/java/graphql/annotations/processor/util/CodeRegistryUtil.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. @@ -19,8 +19,6 @@ import java.util.function.BiFunction; -import static graphql.schema.GraphQLObjectType.newObject; - public class CodeRegistryUtil { /** * This util method helps you wrap your datafetcher with some lambda code @@ -31,21 +29,22 @@ public class CodeRegistryUtil { */ public static void wrapDataFetcher(GraphQLFieldDefinition fieldDefinition, AnnotationsWiringEnvironment environment, BiFunction mapFunction) { - DataFetcher originalDataFetcher = getDataFetcher(environment.getCodeRegistryBuilder(), environment.getParentName(), fieldDefinition); + String parentName = ((GraphQLNamedSchemaElement) environment.getParentElement()).getName(); + DataFetcher originalDataFetcher = getDataFetcher(environment.getCodeRegistryBuilder(), environment.getParentElement(), fieldDefinition); DataFetcher wrappedDataFetcher = DataFetcherFactories.wrapDataFetcher(originalDataFetcher, mapFunction); environment.getCodeRegistryBuilder() - .dataFetcher(FieldCoordinates.coordinates(environment.getParentName(), fieldDefinition.getName()), wrappedDataFetcher); + .dataFetcher(FieldCoordinates.coordinates(parentName, fieldDefinition.getName()), wrappedDataFetcher); } /** * this util method helps you retrieve the data fetcher from the code registry if you do not have the whole parent object (only parent name) * * @param codeRegistryBuilder the code registry builder - * @param parentName the parent name + * @param parentElement the parent name * @param fieldDefinition the field definition which the data fetcher is linked to * @return the data fetcher */ - public static DataFetcher getDataFetcher(GraphQLCodeRegistry.Builder codeRegistryBuilder, String parentName, GraphQLFieldDefinition fieldDefinition) { - return codeRegistryBuilder.getDataFetcher(newObject().name(parentName).build(), fieldDefinition); + public static DataFetcher getDataFetcher(GraphQLCodeRegistry.Builder codeRegistryBuilder, GraphQLSchemaElement parentElement, GraphQLFieldDefinition fieldDefinition) { + return codeRegistryBuilder.getDataFetcher((GraphQLFieldsContainer) parentElement, fieldDefinition); } } diff --git a/src/test/java/graphql/annotations/GraphQLDirectivesViaAnnotationDefinitionTest.java b/src/test/java/graphql/annotations/GraphQLDirectivesViaAnnotationDefinitionTest.java index 78241019..bb234144 100644 --- a/src/test/java/graphql/annotations/GraphQLDirectivesViaAnnotationDefinitionTest.java +++ b/src/test/java/graphql/annotations/GraphQLDirectivesViaAnnotationDefinitionTest.java @@ -36,7 +36,7 @@ import java.lang.annotation.Target; import java.util.Map; -import static graphql.schema.GraphQLSchema.newSchema; +import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema; import static org.testng.Assert.*; public class GraphQLDirectivesViaAnnotationDefinitionTest { @@ -46,12 +46,7 @@ public class GraphQLDirectivesViaAnnotationDefinitionTest { @BeforeMethod public void setUp() { this.graphQLAnnotations = new GraphQLAnnotations(); - this.graphQLAnnotations.directive(Upper.class); - this.graphQLAnnotations.directive(Suffix.class); - this.graphQLAnnotations.directive(DirectiveWithList.class); - GraphQLObjectType object = this.graphQLAnnotations.object(Query.class); - GraphQLCodeRegistry codeRegistry = graphQLAnnotations.getContainer().getCodeRegistryBuilder().build(); - this.schema = newSchema().query(object).codeRegistry(codeRegistry).build(); + this.schema = newAnnotationsSchema().query(Query.class).directives(Upper.class, Suffix.class, DirectiveWithList.class).build(); } /** diff --git a/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.java b/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.java index f2030f80..272da2e1 100644 --- a/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.java +++ b/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.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. @@ -16,14 +16,14 @@ import graphql.ExecutionResult; import graphql.GraphQL; -import graphql.annotations.annotationTypes.directives.definition.GraphQLDirectiveDefinition; -import graphql.annotations.annotationTypes.directives.activation.GraphQLDirectives; import graphql.annotations.annotationTypes.GraphQLField; import graphql.annotations.annotationTypes.GraphQLName; -import graphql.annotations.directives.AnnotationsDirectiveWiring; -import graphql.annotations.directives.AnnotationsWiringEnvironment; import graphql.annotations.annotationTypes.directives.activation.Directive; +import graphql.annotations.annotationTypes.directives.activation.GraphQLDirectives; import graphql.annotations.annotationTypes.directives.definition.DirectiveLocations; +import graphql.annotations.annotationTypes.directives.definition.GraphQLDirectiveDefinition; +import graphql.annotations.directives.AnnotationsDirectiveWiring; +import graphql.annotations.directives.AnnotationsWiringEnvironment; import graphql.annotations.processor.DirectiveAndWiring; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; @@ -33,14 +33,10 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; import java.util.Map; import static graphql.Scalars.GraphQLBoolean; -import static graphql.Scalars.GraphQLString; +import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema; import static graphql.schema.GraphQLDirective.newDirective; import static graphql.schema.GraphQLSchema.newSchema; import static org.testng.Assert.*; @@ -123,7 +119,7 @@ public static String nameWithFalse() { public static class Query2 { @GraphQLField - @GraphQLDirectives(@Directive(name = "upperCase")) + @GraphQLDirectives(@Directive(name = "upperCaseNoDefault", argumentsValues = {"true"})) public static String nameWithNoArgs() { return "yarin"; } @@ -168,42 +164,32 @@ public static String nameWithInputObject(@GraphQLName("inputObject") InputObject } - - - - @Test public void queryNameWithInputObject_directivesProvidedToRegistry_wiringOfInputObjectIsActivated() { - GraphQLDirective suffixDirective = GraphQLDirective.newDirective().name("suffix").argument(builder -> builder.name("suffix").type(GraphQLString)) - .validLocations(Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION, Introspection.DirectiveLocation.FIELD_DEFINITION).build(); - - this.graphQLAnnotations.getContainer().getDirectiveRegistry().put(suffixDirective.getName(), new DirectiveAndWiring(suffixDirective, SuffixWiring.class)); - GraphQLObjectType object = this.graphQLAnnotations.object(Query5.class); - GraphQLCodeRegistry codeRegistry = graphQLAnnotations.getContainer().getCodeRegistryBuilder().build(); - GraphQLSchema schema = newSchema().query(object).codeRegistry(codeRegistry).build(); + GraphQLSchema schema = newAnnotationsSchema().query(Query5.class).directive(SuffixDirective.class).build(); GraphQLFieldDefinition nameWithInputObject = schema.getQueryType().getFieldDefinition("nameWithInputObject"); GraphQLInputObjectField field = ((GraphQLInputObjectType) nameWithInputObject.getArgument("inputObject").getType()).getField("acoolSuffix"); assertNotNull(field); } + @GraphQLName("suffix") + @GraphQLDirectiveDefinition(wiring = SuffixWiring.class) + @DirectiveLocations({Introspection.DirectiveLocation.FIELD_DEFINITION, Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION, Introspection.DirectiveLocation.ARGUMENT_DEFINITION}) + class SuffixDirective { + @GraphQLName("suffix") + public String suffix; + } + @Test public void queryNameWithArgument_directivesProvidedToRegistry_wiringOfArgumentIsActivated() { - GraphQLDirective suffixDirective = GraphQLDirective.newDirective().name("suffix").argument(builder -> builder.name("suffix").type(GraphQLString)) - .validLocations(Introspection.DirectiveLocation.FIELD_DEFINITION, Introspection.DirectiveLocation.ARGUMENT_DEFINITION).build(); - this.graphQLAnnotations.getContainer().getDirectiveRegistry().put(suffixDirective.getName(), new DirectiveAndWiring(suffixDirective, SuffixWiring.class)); - GraphQLObjectType object = this.graphQLAnnotations.object(Query4.class); - GraphQLCodeRegistry codeRegistry = graphQLAnnotations.getContainer().getCodeRegistryBuilder().build(); - GraphQLSchema schema = newSchema().query(object).codeRegistry(codeRegistry).build(); - + GraphQLSchema schema = newAnnotationsSchema().query(Query4.class).directive(SuffixDirective.class).build(); ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("query { nameWithArgument(extensionArgcoolSuffixForArg: \"ext\") }"); assertTrue(result.getErrors().isEmpty()); } @Test(expectedExceptions = GraphQLAnnotationsException.class) public void queryName_noDirectivesProvidedToRegistry_exceptionIsThrown() throws Exception { - GraphQLObjectType object = this.graphQLAnnotations.object(Query.class); - GraphQLCodeRegistry codeRegistry = graphQLAnnotations.getContainer().getCodeRegistryBuilder().build(); - GraphQLSchema schema = newSchema().query(object).codeRegistry(codeRegistry).build(); + GraphQLSchema schema = newAnnotationsSchema().query(Query.class).build(); GraphQL.newGraphQL(schema).build().execute("query { name }"); } @@ -212,16 +198,22 @@ public void queryName_noDirectivesProvidedToRegistry_exceptionIsThrown() throws @DirectiveLocations(Introspection.DirectiveLocation.FIELD_DEFINITION) @GraphQLDirectiveDefinition(wiring = UpperWiring.class) public static class UpperCase { + boolean isActive = true; + } + + @GraphQLName("upperCaseNoDefault") + @DirectiveLocations(Introspection.DirectiveLocation.FIELD_DEFINITION) + @GraphQLDirectiveDefinition(wiring = UpperWiring.class) + public static class UpperCaseNoDefault { boolean isActive; } + @Test public void queryName_directivesProvidedToRegistry_wiringIsActivated() throws Exception { this.graphQLAnnotations.directive(UpperCase.class); - GraphQLObjectType object = this.graphQLAnnotations.object(Query.class); - GraphQLCodeRegistry codeRegistry = graphQLAnnotations.getContainer().getCodeRegistryBuilder().build(); - GraphQLSchema schema = newSchema().query(object).codeRegistry(codeRegistry).build(); + GraphQLSchema schema = newAnnotationsSchema().query(Query.class).directive(UpperCase.class).build(); ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("query { name }"); assertTrue(result.getErrors().isEmpty()); @@ -244,12 +236,7 @@ public void queryNameWithFalse_directivesProvidedToRegistry_wiringIsActivated() @Test public void queryNameWithNoArgs_directivesProvidedToRegistry_wiringIsActivated() throws Exception { - GraphQLDirective upperCase = newDirective().name("upperCase").argument(builder -> builder.name("isActive").type(GraphQLBoolean).defaultValue(true)) - .validLocations(Introspection.DirectiveLocation.FIELD_DEFINITION).build(); - this.graphQLAnnotations.getContainer().getDirectiveRegistry().put(upperCase.getName(), new DirectiveAndWiring(upperCase, UpperWiring.class)); - GraphQLObjectType object = this.graphQLAnnotations.object(Query2.class); - GraphQLCodeRegistry codeRegistry = graphQLAnnotations.getContainer().getCodeRegistryBuilder().build(); - GraphQLSchema schema = newSchema().query(object).codeRegistry(codeRegistry).build(); + GraphQLSchema schema = newAnnotationsSchema().query(Query2.class).directive(UpperCaseNoDefault.class).build(); ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("query { nameWithNoArgs }"); assertTrue(result.getErrors().isEmpty()); @@ -258,29 +245,14 @@ public void queryNameWithNoArgs_directivesProvidedToRegistry_wiringIsActivated() @Test(expectedExceptions = GraphQLAnnotationsException.class) public void queryNameWithNoArgs_noDefaultValue_exceptionIsThrown() throws Exception { - GraphQLDirective upperCase = newDirective().name("upperCase").argument(builder -> builder.name("isActive").type(GraphQLBoolean)) - .validLocations(Introspection.DirectiveLocation.FIELD_DEFINITION).build(); - this.graphQLAnnotations.getContainer().getDirectiveRegistry().put(upperCase.getName(), new DirectiveAndWiring(upperCase, UpperWiring.class)); - GraphQLObjectType object = this.graphQLAnnotations.object(Query2.class); - GraphQLCodeRegistry codeRegistry = graphQLAnnotations.getContainer().getCodeRegistryBuilder().build(); - - GraphQLSchema schema = newSchema().query(object).codeRegistry(codeRegistry).build(); + GraphQLSchema schema = newAnnotationsSchema().query(Query2.class).directive(UpperCase.class).build(); GraphQL.newGraphQL(schema).build().execute("query { nameWithNoArgs }"); } @Test public void queryName_chainedDirectives_wiringIsActivatedInCorrectOrder() throws Exception { - GraphQLDirective upperCase = newDirective().name("upperCase").argument(builder -> builder.name("isActive").type(GraphQLBoolean).defaultValue(true)) - .validLocations(Introspection.DirectiveLocation.FIELD_DEFINITION).build(); - GraphQLDirective suffixDirective = GraphQLDirective.newDirective().name("suffix").argument(builder -> builder.name("suffix").type(GraphQLString)) - .validLocations(Introspection.DirectiveLocation.FIELD_DEFINITION, Introspection.DirectiveLocation.ARGUMENT_DEFINITION).build(); - this.graphQLAnnotations.getContainer().getDirectiveRegistry().put(upperCase.getName(), new DirectiveAndWiring(upperCase, UpperWiring.class)); - this.graphQLAnnotations.getContainer().getDirectiveRegistry().put(suffixDirective.getName(), new DirectiveAndWiring(suffixDirective, SuffixWiring.class)); - GraphQLObjectType object = this.graphQLAnnotations.object(Query3.class); - GraphQLCodeRegistry codeRegistry = graphQLAnnotations.getContainer().getCodeRegistryBuilder().build(); - - GraphQLSchema schema = newSchema().query(object).codeRegistry(codeRegistry).build(); + GraphQLSchema schema = newAnnotationsSchema().query(Query3.class).directives(SuffixDirective.class, UpperCase.class).build(); ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("query { name }"); assertTrue(result.getErrors().isEmpty()); diff --git a/src/test/java/graphql/annotations/GraphQLDirectivesViaMethodDefinitionTest.java b/src/test/java/graphql/annotations/GraphQLDirectivesViaMethodDefinitionTest.java index 3272dd31..38059589 100644 --- a/src/test/java/graphql/annotations/GraphQLDirectivesViaMethodDefinitionTest.java +++ b/src/test/java/graphql/annotations/GraphQLDirectivesViaMethodDefinitionTest.java @@ -24,15 +24,13 @@ import graphql.annotations.annotationTypes.directives.definition.GraphQLDirectiveDefinition; import graphql.annotations.processor.GraphQLAnnotations; import graphql.introspection.Introspection; -import graphql.schema.GraphQLCodeRegistry; -import graphql.schema.GraphQLObjectType; import graphql.schema.GraphQLSchema; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.util.Map; -import static graphql.schema.GraphQLSchema.newSchema; +import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -60,10 +58,7 @@ public static String name() { @BeforeMethod public void setUp() { this.graphQLAnnotations = new GraphQLAnnotations(); - this.graphQLAnnotations.directives(DirectivesContainer.class); - GraphQLObjectType object = this.graphQLAnnotations.object(DirectivesContainer.class); - GraphQLCodeRegistry codeRegistry = graphQLAnnotations.getContainer().getCodeRegistryBuilder().build(); - this.schema = newSchema().query(object).codeRegistry(codeRegistry).build(); + this.schema = newAnnotationsSchema().query(DirectivesContainer.class).directives(DirectivesContainer.class).build(); } diff --git a/src/test/java/graphql/annotations/GraphQLObjectTest.java b/src/test/java/graphql/annotations/GraphQLObjectTest.java index 1c74bf56..890fdcc4 100644 --- a/src/test/java/graphql/annotations/GraphQLObjectTest.java +++ b/src/test/java/graphql/annotations/GraphQLObjectTest.java @@ -1,901 +1,901 @@ -/** - * 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.ExecutionResult; -import graphql.GraphQL; -import graphql.Scalars; -import graphql.annotations.annotationTypes.*; -import graphql.annotations.annotationTypes.GraphQLNonNull; -import graphql.annotations.processor.GraphQLAnnotations; -import graphql.annotations.processor.ProcessingElementsContainer; -import graphql.annotations.processor.retrievers.GraphQLFieldRetriever; -import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; -import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; -import graphql.annotations.processor.searchAlgorithms.ParentalSearch; -import graphql.annotations.processor.typeBuilders.InputObjectBuilder; -import graphql.annotations.processor.typeFunctions.TypeFunction; -import graphql.annotations.processor.util.CodeRegistryUtil; -import graphql.schema.*; -import graphql.schema.GraphQLType; -import graphql.schema.idl.SchemaParser; -import graphql.schema.idl.SchemaPrinter; -import graphql.schema.idl.TypeDefinitionRegistry; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.lang.reflect.AnnotatedType; -import java.util.*; -import java.util.function.Supplier; - -import static graphql.Scalars.GraphQLString; -import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema; -import static graphql.annotations.processor.util.InputPropertiesUtil.DEFAULT_INPUT_PREFIX; -import static graphql.annotations.processor.util.InputPropertiesUtil.DEFAULT_INPUT_SUFFIX; -import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; -import static graphql.schema.GraphQLSchema.newSchema; -import static org.testng.Assert.*; - -@SuppressWarnings("unchecked") -public class GraphQLObjectTest { - - private GraphQLAnnotations graphQLAnnotations; - - @BeforeMethod - public void init() { - this.graphQLAnnotations = new GraphQLAnnotations(); - } - - public static class DefaultAValue implements Supplier { - - @Override - public Object get() { - return "default"; - } - } - - @GraphQLDescription("TestObject object") - @GraphQLName("TestObject") - public static class TestObject { - @GraphQLField - @GraphQLName("field0") - @GraphQLDescription("field") - public - @GraphQLNonNull - String field() { - return "test"; - } - - @GraphQLField - 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, @GraphQLName("a") String a, @GraphQLName("b") String b) { - return a; - } - - @GraphQLField - @Deprecated - public String deprecated() { - return null; - } - - @GraphQLField - @GraphQLDeprecate("Reason") - public String deprecate() { - return null; - } - - @GraphQLField - public String publicTest = "public"; - - @GraphQLField - private String privateTest = "private"; - - public String getPrivateTest() { - return privateTest; - } - - public void setPrivateTest(String privateTest) { - this.privateTest = privateTest; - } - - @GraphQLNonNull - @GraphQLField - @GraphQLName("z_nonOptionalString") - private String z; - - public String getZ() { - return z; - } - - public void setZ(String z) { - this.z = z; - } - - } - - private static class TestDefaults { - } - - private static class TestObjectNamedArgs { - @GraphQLField - public String fieldWithNamedArgs(@GraphQLName("namedArg") String firstArgument) { - return firstArgument; - } - } - - public static class TestMappedObject { - @GraphQLField - public String name; - - @GraphQLField - public String aaa; - } - - public static class TestObjectDB { - public String aaa; - - private String name; - - public String getName() { - return name; - } - - public TestObjectDB(String name, String aaa) { - this.name = name; - this.aaa = aaa; - } - } - - public static class TestQuery { - @GraphQLField - @GraphQLDataFetcher(ObjectFetcher.class) - public TestMappedObject object; - } - - public static class ObjectFetcher implements DataFetcher { - - @Override - public TestObjectDB get(DataFetchingEnvironment environment) { - return new TestObjectDB("test", "test"); - } - } - - public static class NameTest { - @GraphQLField - public Boolean isCool; - - @GraphQLField - @GraphQLPrettify - public Boolean isAwesome; - - @GraphQLField - @GraphQLPrettify - @GraphQLName("yarinnn") - public Boolean isYarin; - - @GraphQLField - public String getX() { - return "Asdf0"; - } - - @GraphQLField - @GraphQLPrettify - public String getY() { - return "asd"; - } - - @GraphQLField - @GraphQLPrettify - @GraphQLName("daniel") - public String setM() { - return "Asdf"; - } - - } - - @Test - public void objectCreation_nameIsCorrect() { - // Act - GraphQLObjectType object = this.graphQLAnnotations.object(NameTest.class); - - // Assert - assertNotNull(object.getFieldDefinition("awesome")); - assertNotNull(object.getFieldDefinition("isCool")); - assertNotNull(object.getFieldDefinition("yarinnn")); - assertNotNull(object.getFieldDefinition("getX")); - assertNotNull(object.getFieldDefinition("y")); - assertNotNull(object.getFieldDefinition("daniel")); - } - - @Test - public void fetchTestMappedObject_assertNameIsMappedFromDBObject() { - GraphQLSchema schema = newAnnotationsSchema().query(TestQuery.class).build(); - - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{object {name aaa}}"); - assertTrue(result.getErrors().isEmpty()); - assertEquals(((LinkedHashMap) (((LinkedHashMap) result.getData()).get("object"))).get("name"), "test"); - assertEquals(((LinkedHashMap) (((LinkedHashMap) result.getData()).get("object"))).get("aaa"), "test"); - } - - @Test - public void namedFields() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectNamedArgs.class); - List fields = object.getFieldDefinitions(); - assertEquals(fields.size(), 1); - - List args = fields.get(0).getArguments(); - assertEquals(args.size(), 1); - - GraphQLArgument arg = args.get(0); - assertEquals(arg.getName(), "namedArg"); - } - - @Test - public void metainformation() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); - assertEquals(object.getName(), "TestObject"); - assertEquals(object.getDescription(), "TestObject object"); - } - - @Test - public void objectClass() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); - assertTrue(object instanceof GraphQLObjectType); - } - - @Test - public void testSchema() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); - String schema = new SchemaPrinter().print(object); - assertTrue(schema.contains("type TestObject {")); - TypeDefinitionRegistry reg = new SchemaParser().parse(schema); - assertTrue(reg.getType("TestObject").isPresent()); - assertEquals(new SchemaParser().parse(schema).getType("TestObject").get().getChildren().size(), 8); - } - - @Test - public void fields() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); - List fields = object.getFieldDefinitions(); - assertEquals(fields.size(), 8); - - fields.sort((o1, o2) -> o1.getName().compareTo(o2.getName())); - - assertEquals(fields.get(2).getName(), "field0"); - assertEquals(fields.get(2).getDescription(), "field"); - assertTrue(fields.get(2).getType() instanceof graphql.schema.GraphQLNonNull); - assertEquals(((graphql.schema.GraphQLNonNull) fields.get(2).getType()).getWrappedType(), GraphQLString); - - assertEquals(fields.get(3).getName(), "fieldWithArgs"); - List args = fields.get(3).getArguments(); - assertEquals(args.size(), 2); - assertEquals(args.get(0).getName(), "a"); - assertTrue(args.get(0).getType() instanceof graphql.schema.GraphQLNonNull); - assertEquals(((graphql.schema.GraphQLNonNull) args.get(0).getType()).getWrappedType(), GraphQLString); - assertEquals(args.get(1).getName(), "b"); - assertEquals(args.get(1).getType(), GraphQLString); - assertEquals(args.get(1).getDescription(), "b"); - - assertEquals(fields.get(4).getName(), "fieldWithArgsAndEnvironment"); - args = fields.get(4).getArguments(); - assertEquals(args.size(), 2); - - assertEquals(fields.get(1).getName(), "deprecated"); - assertTrue(fields.get(1).isDeprecated()); - - assertEquals(fields.get(0).getName(), "deprecate"); - assertTrue(fields.get(0).isDeprecated()); - assertEquals(fields.get(0).getDeprecationReason(), "Reason"); - - assertEquals(fields.get(5).getName(), "privateTest"); - assertEquals(fields.get(6).getName(), "publicTest"); - - DataFetcher dataFetcher1 = CodeRegistryUtil.getDataFetcher(this.graphQLAnnotations.getContainer().getCodeRegistryBuilder(), "TestObject", fields.get(5)); - DataFetcher dataFetcher2 = CodeRegistryUtil.getDataFetcher(this.graphQLAnnotations.getContainer().getCodeRegistryBuilder(), "TestObject", fields.get(6)); - assertEquals(dataFetcher1.getClass(), PropertyDataFetcher.class); - assertEquals(dataFetcher2.getClass(), PropertyDataFetcher.class); - - assertEquals(fields.get(7).getName(), "z_nonOptionalString"); - assertTrue(fields.get(7).getType() instanceof graphql.schema.GraphQLNonNull); - } - - public static class TestObjectInherited extends TestObject { - @Override - @GraphQLName("field1") // Test overriding field - public String field() { - return "inherited"; - } - } - - @Test - public void methodInheritance() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); - GraphQLObjectType objectInherited = this.graphQLAnnotations.object(TestObjectInherited.class); - assertEquals(object.getFieldDefinitions().size(), objectInherited.getFieldDefinitions().size()); - - GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); - GraphQLSchema schemaInherited = newAnnotationsSchema().query(TestObjectInherited.class).build(); - - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field0}", new TestObject()); - assertEquals(((Map) result.getData()).get("field0"), "test"); - GraphQL graphQL = GraphQL.newGraphQL(schemaInherited).build(); - result = graphQL.execute("{field1}", new TestObjectInherited()); - assertEquals(((Map) result.getData()).get("field1"), "inherited"); - } - - public static class TestObjectBridgMethodParent { - private final Type id; - - public TestObjectBridgMethodParent(Type id) { - this.id = id; - } - - public Type id() { - return id; - } - } - - public static class TestObjectBridgMethod extends TestObjectBridgMethodParent { - - public TestObjectBridgMethod() { - super(1L); - } - - @Override - @GraphQLField - public Long id() { - return super.id(); - } - } - - @Test - public void methodInheritanceWithGenerics() { - GraphQLSchema schema = newAnnotationsSchema().query(TestObjectBridgMethod.class).build(); - - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{id}", new TestObjectBridgMethod()); - assertEquals(((Map) result.getData()).get("id"), 1L); - } - - public interface Iface { - @GraphQLField - default String field() { - return "field"; - } - } - - public static class IfaceImpl implements Iface { - } - - @Test - public void interfaceInheritance() { - GraphQLObjectType object = this.graphQLAnnotations.object(IfaceImpl.class); - assertEquals(object.getFieldDefinitions().size(), 1); - assertEquals(object.getFieldDefinition("field").getType(), GraphQLString); - - } - - private static class TestAccessors { - @GraphQLField - public String getValue() { - return "hello"; - } - - @GraphQLField - public String setAnotherValue(String s) { - return s; - } - } - - @Test - public void accessors() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestAccessors.class); - List fields = object.getFieldDefinitions(); - assertEquals(fields.size(), 2); - fields.sort(Comparator.comparing(GraphQLFieldDefinition::getName)); - - assertEquals(fields.get(0).getName(), "getValue"); - assertEquals(fields.get(1).getName(), "setAnotherValue"); - } - - - @Test - public void defaults() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestDefaults.class); - assertEquals(object.getName(), "TestDefaults"); - assertNull(object.getDescription()); - } - - public static class TestField { - @GraphQLField - @GraphQLName("field1") - public String field = "test"; - } - - public static class PrivateTestField { - - @GraphQLField - @GraphQLName("field1") - private String field = "test"; - - public String getField() { - return field; - } - - public void setField(String field) { - this.field = field; - } - - @GraphQLField - private String field2 = "test"; - - public String field2() { - return field2; - } - - public PrivateTestField sfield2(String field2) { - this.field2 = field2; - return this; - } - - @GraphQLField - private boolean booleanField = true; - - public boolean isBooleanField() { - return booleanField; - } - - public void setBooleanField(boolean booleanField) { - this.booleanField = booleanField; - } - } - - @Test - public void field() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestField.class); - List fields = object.getFieldDefinitions(); - assertEquals(fields.size(), 1); - assertEquals(fields.get(0).getName(), "field1"); - } - - private static class OnMethodTest { - private String value; - - @GraphQLField - public String getValue() { - return value; - } - } - - @Test - public void onMethod() { - GraphQLObjectType object = this.graphQLAnnotations.object(OnMethodTest.class); - List fields = object.getFieldDefinitions(); - assertEquals(fields.size(), 1); - assertEquals(fields.get(0).getName(), "getValue"); - } - - public static class TestFetcher implements DataFetcher { - - @Override - public Object get(DataFetchingEnvironment environment) { - return "test"; - } - } - - private static class TestDataFetcher { - - @GraphQLField - @GraphQLDataFetcher(TestFetcher.class) - public String field; - - @GraphQLField - @GraphQLDataFetcher(TestFetcher.class) - public String someField() { - return "not test"; - } - - } - - @Test - public void dataFetcher() { - GraphQLSchema schema = newAnnotationsSchema().query(TestDataFetcher.class).build(); - - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field someField}", new TestObject()); - assertTrue(result.getErrors().isEmpty()); - assertEquals(((Map) result.getData()).get("field"), "test"); - assertEquals(((Map) result.getData()).get("someField"), "test"); - } - - @Test - public void query() { - GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); - - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field0}", new TestObject()); - assertTrue(result.getErrors().isEmpty()); - assertEquals(((Map) result.getData()).get("field0"), "test"); - - result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgs(a: \"test\", b: \"passed\")}", new TestObject()); - assertTrue(result.getErrors().isEmpty()); - assertEquals(((Map) result.getData()).get("fieldWithArgs"), "passed"); - - result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgsAndEnvironment(a: \"test\", b: \"passed\")}", new TestObject()); - assertTrue(result.getErrors().isEmpty()); - assertEquals(((Map) result.getData()).get("fieldWithArgsAndEnvironment"), "test"); - - } - - @Test - public void queryField() { - GraphQLSchema schema = newAnnotationsSchema().query(TestField.class).build(); - - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field1}", new TestField()); - assertTrue(result.getErrors().isEmpty()); - assertEquals(((Map) result.getData()).get("field1"), "test"); - } - - @Test - public void queryPrivateField() { - GraphQLSchema schema = newAnnotationsSchema().query(PrivateTestField.class).build(); - - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field1, field2, booleanField}", new PrivateTestField()); - assertTrue(result.getErrors().isEmpty()); - assertEquals(((Map) result.getData()).get("field1"), "test"); - assertEquals(((Map) result.getData()).get("field2"), "test"); - assertTrue(((Map) result.getData()).get("booleanField")); - - } - - @Test - public void defaultArg() { - GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); - - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgs(a: \"test\")}", new TestObject()); - assertTrue(result.getErrors().isEmpty()); - assertEquals(((Map) result.getData()).get("fieldWithArgs"), "default"); - } - - - public static class Class1 { - @GraphQLField - public Class2 class2; - @GraphQLField - public String value; - } - - public static class Class2 { - @GraphQLField - public Class1 class1; - @GraphQLField - public String value; - } - - @Test - public void recursiveTypes() { - GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations(); - GraphQLObjectType object = graphQLAnnotations.getObjectHandler().getGraphQLType(Class1.class, graphQLAnnotations.getContainer()); - GraphQLSchema schema = newSchema().query(object).build(); - - Class1 class1 = new Class1(); - Class2 class2 = new Class2(); - class1.class2 = class2; - class2.class1 = class1; - class2.value = "hello"; - class1.value = "bye"; - - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ class2 { value } }", class1); - assertTrue(result.getErrors().isEmpty()); - Map data = (Map) result.getData(); - assertEquals(((Map) data.get("class2")).get("value"), "hello"); - - result = GraphQL.newGraphQL(schema).build().execute("{ class2 { class1 { value } } }", class1); - assertTrue(result.getErrors().isEmpty()); - data = (Map) result.getData(); - Map k1 = (Map) ((Map) data.get("class2")).get("class1"); - assertEquals(k1.get("value"), "bye"); - - result = GraphQL.newGraphQL(schema).build().execute("{ class2 { class1 { class2 { value } } } }", class1); - assertTrue(result.getErrors().isEmpty()); - } - - private static class TestCustomType { - @GraphQLField - public UUID id() { - return UUID.randomUUID(); - } - } - - @Test - public void customType() { - this.graphQLAnnotations.registerTypeFunction(new UUIDTypeFunction()); - GraphQLObjectType object = this.graphQLAnnotations.object(TestCustomType.class); - assertEquals(object.getFieldDefinition("id").getType(), GraphQLString); - } - - private static class TestCustomTypeFunction { - @GraphQLField - @graphql.annotations.annotationTypes.GraphQLType(UUIDTypeFunction.class) - public UUID id() { - return UUID.randomUUID(); - } - } - - @Test - public void customTypeFunction() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestCustomTypeFunction.class); - assertEquals(object.getFieldDefinition("id").getType(), GraphQLString); - } - - public static class TestInputArgument { - @GraphQLField - public String a; - @GraphQLField - public int b; - - public TestInputArgument(@GraphQLName("a") String a, @GraphQLName("b") int b) { - this.a = a; - this.b = b; - } - } - - public static class TestComplexInputArgument { - - public Collection inputs; - - public TestComplexInputArgument(@GraphQLName("inputs") Collection inputs) { - this.inputs = inputs; - } - - @GraphQLField - public Collection inputs() { - return inputs; - } - - } - - - public static class TestObjectInput { - @GraphQLField - public String test(@GraphQLName("other") int other, @GraphQLName("arg") TestInputArgument arg) { - return arg.a; - } - - @GraphQLField - public String test2(@GraphQLName("other") int other, @GraphQLName("arg") TestComplexInputArgument arg) { - return arg.inputs.iterator().next().a; - } - } - - public static class InputObject { - @GraphQLField - int a; - - @GraphQLField - int b; - } - - @Test - public void inputObjectArgument() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectInput.class); - GraphQLArgument argument = object.getFieldDefinition("test").getArgument("arg"); - assertTrue(argument.getType() instanceof GraphQLInputObjectType); - assertEquals(argument.getName(), "arg"); - - GraphQLSchema schema = newAnnotationsSchema().query(TestObjectInput.class).build(); - 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"); - } - - @Test - public void complexInputObjectArgument() { - GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectInput.class); - GraphQLArgument argument = object.getFieldDefinition("test2").getArgument("arg"); - assertTrue(argument.getType() instanceof GraphQLInputObjectType); - assertEquals(argument.getName(), "arg"); - - GraphQLSchema schema = newAnnotationsSchema().query(TestObjectInput.class).build(); - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ test2(arg: {inputs:[{ a:\"ok\", b:2 }]}, other:0) }", new TestObjectInput()); - assertTrue(result.getErrors().isEmpty()); - Map v = result.getData(); - assertEquals(v.get("test2"), "ok"); - } - - @Test - public void inputObject() { - GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); - GraphQLInputObjectType type = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), - new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). - getInputObjectBuilder(InputObject.class, this.graphQLAnnotations.getContainer()).build(); - - assertEquals(type.getName(), DEFAULT_INPUT_PREFIX + InputObject.class.getSimpleName(), "Type name prefix did not match expected value"); - assertEquals(type.getFields().size(), InputObject.class.getDeclaredFields().length); - } - - @Test - public void inputObjectCustomPrefixes() { - GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); - ProcessingElementsContainer container = this.graphQLAnnotations.getContainer(); - container.setInputPrefix(""); - container.setInputSuffix("Input"); - GraphQLInputObjectType type = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), - new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). - getInputObjectBuilder(InputObject.class, this.graphQLAnnotations.getContainer()).build(); - - assertEquals(type.getName(), "" + InputObject.class.getSimpleName() + "Input", "Type name prefix did not match expected value"); - assertEquals(type.getFields().size(), InputObject.class.getDeclaredFields().length); - container.setInputPrefix(DEFAULT_INPUT_PREFIX); - container.setInputSuffix(DEFAULT_INPUT_SUFFIX); - } - - public static class UUIDTypeFunction implements TypeFunction { - @Override - 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"; - } - - public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { - return GraphQLString; - } - } - - public static class OptionalTest { - @GraphQLField - public Optional empty = Optional.empty(); - @GraphQLField - public Optional nonempty = Optional.of("test"); - - public OptionalTest() { - } - - public OptionalTest(Optional empty, Optional nonempty) { - this.empty = empty; - this.nonempty = nonempty; - } - - @Override - public String toString() { - return "OptionalTest" + - "{empty=" + empty + - ", nonempty=" + nonempty + - '}'; - } - } - - @Test - public void queryOptional() { - GraphQLObjectType object = this.graphQLAnnotations.object(OptionalTest.class); - GraphQLSchema schema = newSchema().query(object).build(); - - GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{empty, nonempty}", new OptionalTest()); - assertTrue(result.getErrors().isEmpty()); - Map v = (Map) result.getData(); - assertNull(v.get("empty")); - assertEquals(v.get("nonempty"), "test"); - } - - @Test - public void optionalInput() { - GraphQLObjectType object = this.graphQLAnnotations.object(OptionalTest.class); - GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); - GraphQLInputObjectType inputObject = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), - new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). - getInputObjectBuilder(OptionalTest.class, this.graphQLAnnotations.getContainer()).build(); - - 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"); - return new OptionalTest(Optional.ofNullable(input.get("empty")), Optional.ofNullable(input.get("nonempty"))); - }).build()).build(); - GraphQLSchema schema = newSchema().query(object).mutation(mutation).build(); - - GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("mutation {test(input: {empty: \"test\"}) { empty nonempty } }", new OptionalTest()); - assertTrue(result.getErrors().isEmpty()); - Map v = (Map) ((Map) result.getData()).get("test"); - assertEquals(v.get("empty"), "test"); - assertNull(v.get("nonempty")); - } - - public static class EnumTest { - public enum E {A, B} - - @GraphQLField - public E e; - - public EnumTest() { - } - - public EnumTest(E e) { - this.e = e; - } - - @Override - public String toString() { - return "EnumTest{" + "e=" + e + '}'; - } - } - - @Test - public void queryEnum() { - GraphQLObjectType object = this.graphQLAnnotations.object(EnumTest.class); - GraphQLSchema schema = newSchema().query(object).build(); - GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - - ExecutionResult result = graphQL.execute("{e}", new EnumTest(EnumTest.E.B)); - assertTrue(result.getErrors().isEmpty()); - Map v = (Map) result.getData(); - assertEquals(v.get("e"), "B"); - } - - public static class ParametrizedArgsTest { - @GraphQLField - public String first(List l) { - return l.get(0); - } - } - - @Test - public void parametrizedArg() { - GraphQLObjectType object = this.graphQLAnnotations.object(ParametrizedArgsTest.class); - GraphQLInputType t = object.getFieldDefinition("first").getArguments().get(0).getType(); - assertTrue(t instanceof GraphQLList); - assertEquals(((GraphQLList) t).getWrappedType(), Scalars.GraphQLString); - } - - @GraphQLField - public static class InheritGraphQLFieldTest { - public String inheritedOn; - - @GraphQLField(false) - public String forcedOff; - - public String on() { - return "on"; - } - - @GraphQLField(false) - public String off() { - return "off"; - } - - } - - @Test - public void inheritGraphQLField() { - GraphQLObjectType object = this.graphQLAnnotations.object(InheritGraphQLFieldTest.class); - assertNotNull(object.getFieldDefinition("on")); - assertNull(object.getFieldDefinition("off")); - assertNotNull(object.getFieldDefinition("inheritedOn")); - assertNull(object.getFieldDefinition("forcedOff")); - } - - -} +///** +// * 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.ExecutionResult; +//import graphql.GraphQL; +//import graphql.Scalars; +//import graphql.annotations.annotationTypes.*; +//import graphql.annotations.annotationTypes.GraphQLNonNull; +//import graphql.annotations.processor.GraphQLAnnotations; +//import graphql.annotations.processor.ProcessingElementsContainer; +//import graphql.annotations.processor.retrievers.GraphQLFieldRetriever; +//import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; +//import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; +//import graphql.annotations.processor.searchAlgorithms.ParentalSearch; +//import graphql.annotations.processor.typeBuilders.InputObjectBuilder; +//import graphql.annotations.processor.typeFunctions.TypeFunction; +//import graphql.annotations.processor.util.CodeRegistryUtil; +//import graphql.schema.*; +//import graphql.schema.GraphQLType; +//import graphql.schema.idl.SchemaParser; +//import graphql.schema.idl.SchemaPrinter; +//import graphql.schema.idl.TypeDefinitionRegistry; +//import org.testng.annotations.BeforeMethod; +//import org.testng.annotations.Test; +// +//import java.lang.reflect.AnnotatedType; +//import java.util.*; +//import java.util.function.Supplier; +// +//import static graphql.Scalars.GraphQLString; +//import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema; +//import static graphql.annotations.processor.util.InputPropertiesUtil.DEFAULT_INPUT_PREFIX; +//import static graphql.annotations.processor.util.InputPropertiesUtil.DEFAULT_INPUT_SUFFIX; +//import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; +//import static graphql.schema.GraphQLSchema.newSchema; +//import static org.testng.Assert.*; +// +//@SuppressWarnings("unchecked") +//public class GraphQLObjectTest { +// +// private GraphQLAnnotations graphQLAnnotations; +// +// @BeforeMethod +// public void init() { +// this.graphQLAnnotations = new GraphQLAnnotations(); +// } +// +// public static class DefaultAValue implements Supplier { +// +// @Override +// public Object get() { +// return "default"; +// } +// } +// +// @GraphQLDescription("TestObject object") +// @GraphQLName("TestObject") +// public static class TestObject { +// @GraphQLField +// @GraphQLName("field0") +// @GraphQLDescription("field") +// public +// @GraphQLNonNull +// String field() { +// return "test"; +// } +// +// @GraphQLField +// 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, @GraphQLName("a") String a, @GraphQLName("b") String b) { +// return a; +// } +// +// @GraphQLField +// @Deprecated +// public String deprecated() { +// return null; +// } +// +// @GraphQLField +// @GraphQLDeprecate("Reason") +// public String deprecate() { +// return null; +// } +// +// @GraphQLField +// public String publicTest = "public"; +// +// @GraphQLField +// private String privateTest = "private"; +// +// public String getPrivateTest() { +// return privateTest; +// } +// +// public void setPrivateTest(String privateTest) { +// this.privateTest = privateTest; +// } +// +// @GraphQLNonNull +// @GraphQLField +// @GraphQLName("z_nonOptionalString") +// private String z; +// +// public String getZ() { +// return z; +// } +// +// public void setZ(String z) { +// this.z = z; +// } +// +// } +// +// private static class TestDefaults { +// } +// +// private static class TestObjectNamedArgs { +// @GraphQLField +// public String fieldWithNamedArgs(@GraphQLName("namedArg") String firstArgument) { +// return firstArgument; +// } +// } +// +// public static class TestMappedObject { +// @GraphQLField +// public String name; +// +// @GraphQLField +// public String aaa; +// } +// +// public static class TestObjectDB { +// public String aaa; +// +// private String name; +// +// public String getName() { +// return name; +// } +// +// public TestObjectDB(String name, String aaa) { +// this.name = name; +// this.aaa = aaa; +// } +// } +// +// public static class TestQuery { +// @GraphQLField +// @GraphQLDataFetcher(ObjectFetcher.class) +// public TestMappedObject object; +// } +// +// public static class ObjectFetcher implements DataFetcher { +// +// @Override +// public TestObjectDB get(DataFetchingEnvironment environment) { +// return new TestObjectDB("test", "test"); +// } +// } +// +// public static class NameTest { +// @GraphQLField +// public Boolean isCool; +// +// @GraphQLField +// @GraphQLPrettify +// public Boolean isAwesome; +// +// @GraphQLField +// @GraphQLPrettify +// @GraphQLName("yarinnn") +// public Boolean isYarin; +// +// @GraphQLField +// public String getX() { +// return "Asdf0"; +// } +// +// @GraphQLField +// @GraphQLPrettify +// public String getY() { +// return "asd"; +// } +// +// @GraphQLField +// @GraphQLPrettify +// @GraphQLName("daniel") +// public String setM() { +// return "Asdf"; +// } +// +// } +// +// @Test +// public void objectCreation_nameIsCorrect() { +// // Act +// GraphQLObjectType object = this.graphQLAnnotations.object(NameTest.class); +// +// // Assert +// assertNotNull(object.getFieldDefinition("awesome")); +// assertNotNull(object.getFieldDefinition("isCool")); +// assertNotNull(object.getFieldDefinition("yarinnn")); +// assertNotNull(object.getFieldDefinition("getX")); +// assertNotNull(object.getFieldDefinition("y")); +// assertNotNull(object.getFieldDefinition("daniel")); +// } +// +// @Test +// public void fetchTestMappedObject_assertNameIsMappedFromDBObject() { +// GraphQLSchema schema = newAnnotationsSchema().query(TestQuery.class).build(); +// +// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{object {name aaa}}"); +// assertTrue(result.getErrors().isEmpty()); +// assertEquals(((LinkedHashMap) (((LinkedHashMap) result.getData()).get("object"))).get("name"), "test"); +// assertEquals(((LinkedHashMap) (((LinkedHashMap) result.getData()).get("object"))).get("aaa"), "test"); +// } +// +// @Test +// public void namedFields() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectNamedArgs.class); +// List fields = object.getFieldDefinitions(); +// assertEquals(fields.size(), 1); +// +// List args = fields.get(0).getArguments(); +// assertEquals(args.size(), 1); +// +// GraphQLArgument arg = args.get(0); +// assertEquals(arg.getName(), "namedArg"); +// } +// +// @Test +// public void metainformation() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); +// assertEquals(object.getName(), "TestObject"); +// assertEquals(object.getDescription(), "TestObject object"); +// } +// +// @Test +// public void objectClass() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); +// assertTrue(object instanceof GraphQLObjectType); +// } +// +// @Test +// public void testSchema() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); +// String schema = new SchemaPrinter().print(object); +// assertTrue(schema.contains("type TestObject {")); +// TypeDefinitionRegistry reg = new SchemaParser().parse(schema); +// assertTrue(reg.getType("TestObject").isPresent()); +// assertEquals(new SchemaParser().parse(schema).getType("TestObject").get().getChildren().size(), 8); +// } +// +// @Test +// public void fields() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); +// List fields = object.getFieldDefinitions(); +// assertEquals(fields.size(), 8); +// +// fields.sort((o1, o2) -> o1.getName().compareTo(o2.getName())); +// +// assertEquals(fields.get(2).getName(), "field0"); +// assertEquals(fields.get(2).getDescription(), "field"); +// assertTrue(fields.get(2).getType() instanceof graphql.schema.GraphQLNonNull); +// assertEquals(((graphql.schema.GraphQLNonNull) fields.get(2).getType()).getWrappedType(), GraphQLString); +// +// assertEquals(fields.get(3).getName(), "fieldWithArgs"); +// List args = fields.get(3).getArguments(); +// assertEquals(args.size(), 2); +// assertEquals(args.get(0).getName(), "a"); +// assertTrue(args.get(0).getType() instanceof graphql.schema.GraphQLNonNull); +// assertEquals(((graphql.schema.GraphQLNonNull) args.get(0).getType()).getWrappedType(), GraphQLString); +// assertEquals(args.get(1).getName(), "b"); +// assertEquals(args.get(1).getType(), GraphQLString); +// assertEquals(args.get(1).getDescription(), "b"); +// +// assertEquals(fields.get(4).getName(), "fieldWithArgsAndEnvironment"); +// args = fields.get(4).getArguments(); +// assertEquals(args.size(), 2); +// +// assertEquals(fields.get(1).getName(), "deprecated"); +// assertTrue(fields.get(1).isDeprecated()); +// +// assertEquals(fields.get(0).getName(), "deprecate"); +// assertTrue(fields.get(0).isDeprecated()); +// assertEquals(fields.get(0).getDeprecationReason(), "Reason"); +// +// assertEquals(fields.get(5).getName(), "privateTest"); +// assertEquals(fields.get(6).getName(), "publicTest"); +// +// DataFetcher dataFetcher1 = CodeRegistryUtil.getDataFetcher(this.graphQLAnnotations.getContainer().getCodeRegistryBuilder(), "TestObject", fields.get(5)); +// DataFetcher dataFetcher2 = CodeRegistryUtil.getDataFetcher(this.graphQLAnnotations.getContainer().getCodeRegistryBuilder(), "TestObject", fields.get(6)); +// assertEquals(dataFetcher1.getClass(), PropertyDataFetcher.class); +// assertEquals(dataFetcher2.getClass(), PropertyDataFetcher.class); +// +// assertEquals(fields.get(7).getName(), "z_nonOptionalString"); +// assertTrue(fields.get(7).getType() instanceof graphql.schema.GraphQLNonNull); +// } +// +// public static class TestObjectInherited extends TestObject { +// @Override +// @GraphQLName("field1") // Test overriding field +// public String field() { +// return "inherited"; +// } +// } +// +// @Test +// public void methodInheritance() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); +// GraphQLObjectType objectInherited = this.graphQLAnnotations.object(TestObjectInherited.class); +// assertEquals(object.getFieldDefinitions().size(), objectInherited.getFieldDefinitions().size()); +// +// GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); +// GraphQLSchema schemaInherited = newAnnotationsSchema().query(TestObjectInherited.class).build(); +// +// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field0}", new TestObject()); +// assertEquals(((Map) result.getData()).get("field0"), "test"); +// GraphQL graphQL = GraphQL.newGraphQL(schemaInherited).build(); +// result = graphQL.execute("{field1}", new TestObjectInherited()); +// assertEquals(((Map) result.getData()).get("field1"), "inherited"); +// } +// +// public static class TestObjectBridgMethodParent { +// private final Type id; +// +// public TestObjectBridgMethodParent(Type id) { +// this.id = id; +// } +// +// public Type id() { +// return id; +// } +// } +// +// public static class TestObjectBridgMethod extends TestObjectBridgMethodParent { +// +// public TestObjectBridgMethod() { +// super(1L); +// } +// +// @Override +// @GraphQLField +// public Long id() { +// return super.id(); +// } +// } +// +// @Test +// public void methodInheritanceWithGenerics() { +// GraphQLSchema schema = newAnnotationsSchema().query(TestObjectBridgMethod.class).build(); +// +// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{id}", new TestObjectBridgMethod()); +// assertEquals(((Map) result.getData()).get("id"), 1L); +// } +// +// public interface Iface { +// @GraphQLField +// default String field() { +// return "field"; +// } +// } +// +// public static class IfaceImpl implements Iface { +// } +// +// @Test +// public void interfaceInheritance() { +// GraphQLObjectType object = this.graphQLAnnotations.object(IfaceImpl.class); +// assertEquals(object.getFieldDefinitions().size(), 1); +// assertEquals(object.getFieldDefinition("field").getType(), GraphQLString); +// +// } +// +// private static class TestAccessors { +// @GraphQLField +// public String getValue() { +// return "hello"; +// } +// +// @GraphQLField +// public String setAnotherValue(String s) { +// return s; +// } +// } +// +// @Test +// public void accessors() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestAccessors.class); +// List fields = object.getFieldDefinitions(); +// assertEquals(fields.size(), 2); +// fields.sort(Comparator.comparing(GraphQLFieldDefinition::getName)); +// +// assertEquals(fields.get(0).getName(), "getValue"); +// assertEquals(fields.get(1).getName(), "setAnotherValue"); +// } +// +// +// @Test +// public void defaults() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestDefaults.class); +// assertEquals(object.getName(), "TestDefaults"); +// assertNull(object.getDescription()); +// } +// +// public static class TestField { +// @GraphQLField +// @GraphQLName("field1") +// public String field = "test"; +// } +// +// public static class PrivateTestField { +// +// @GraphQLField +// @GraphQLName("field1") +// private String field = "test"; +// +// public String getField() { +// return field; +// } +// +// public void setField(String field) { +// this.field = field; +// } +// +// @GraphQLField +// private String field2 = "test"; +// +// public String field2() { +// return field2; +// } +// +// public PrivateTestField sfield2(String field2) { +// this.field2 = field2; +// return this; +// } +// +// @GraphQLField +// private boolean booleanField = true; +// +// public boolean isBooleanField() { +// return booleanField; +// } +// +// public void setBooleanField(boolean booleanField) { +// this.booleanField = booleanField; +// } +// } +// +// @Test +// public void field() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestField.class); +// List fields = object.getFieldDefinitions(); +// assertEquals(fields.size(), 1); +// assertEquals(fields.get(0).getName(), "field1"); +// } +// +// private static class OnMethodTest { +// private String value; +// +// @GraphQLField +// public String getValue() { +// return value; +// } +// } +// +// @Test +// public void onMethod() { +// GraphQLObjectType object = this.graphQLAnnotations.object(OnMethodTest.class); +// List fields = object.getFieldDefinitions(); +// assertEquals(fields.size(), 1); +// assertEquals(fields.get(0).getName(), "getValue"); +// } +// +// public static class TestFetcher implements DataFetcher { +// +// @Override +// public Object get(DataFetchingEnvironment environment) { +// return "test"; +// } +// } +// +// private static class TestDataFetcher { +// +// @GraphQLField +// @GraphQLDataFetcher(TestFetcher.class) +// public String field; +// +// @GraphQLField +// @GraphQLDataFetcher(TestFetcher.class) +// public String someField() { +// return "not test"; +// } +// +// } +// +// @Test +// public void dataFetcher() { +// GraphQLSchema schema = newAnnotationsSchema().query(TestDataFetcher.class).build(); +// +// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field someField}", new TestObject()); +// assertTrue(result.getErrors().isEmpty()); +// assertEquals(((Map) result.getData()).get("field"), "test"); +// assertEquals(((Map) result.getData()).get("someField"), "test"); +// } +// +// @Test +// public void query() { +// GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); +// +// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field0}", new TestObject()); +// assertTrue(result.getErrors().isEmpty()); +// assertEquals(((Map) result.getData()).get("field0"), "test"); +// +// result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgs(a: \"test\", b: \"passed\")}", new TestObject()); +// assertTrue(result.getErrors().isEmpty()); +// assertEquals(((Map) result.getData()).get("fieldWithArgs"), "passed"); +// +// result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgsAndEnvironment(a: \"test\", b: \"passed\")}", new TestObject()); +// assertTrue(result.getErrors().isEmpty()); +// assertEquals(((Map) result.getData()).get("fieldWithArgsAndEnvironment"), "test"); +// +// } +// +// @Test +// public void queryField() { +// GraphQLSchema schema = newAnnotationsSchema().query(TestField.class).build(); +// +// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field1}", new TestField()); +// assertTrue(result.getErrors().isEmpty()); +// assertEquals(((Map) result.getData()).get("field1"), "test"); +// } +// +// @Test +// public void queryPrivateField() { +// GraphQLSchema schema = newAnnotationsSchema().query(PrivateTestField.class).build(); +// +// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field1, field2, booleanField}", new PrivateTestField()); +// assertTrue(result.getErrors().isEmpty()); +// assertEquals(((Map) result.getData()).get("field1"), "test"); +// assertEquals(((Map) result.getData()).get("field2"), "test"); +// assertTrue(((Map) result.getData()).get("booleanField")); +// +// } +// +// @Test +// public void defaultArg() { +// GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); +// +// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgs(a: \"test\")}", new TestObject()); +// assertTrue(result.getErrors().isEmpty()); +// assertEquals(((Map) result.getData()).get("fieldWithArgs"), "default"); +// } +// +// +// public static class Class1 { +// @GraphQLField +// public Class2 class2; +// @GraphQLField +// public String value; +// } +// +// public static class Class2 { +// @GraphQLField +// public Class1 class1; +// @GraphQLField +// public String value; +// } +// +// @Test +// public void recursiveTypes() { +// GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations(); +// GraphQLObjectType object = graphQLAnnotations.getObjectHandler().getGraphQLType(Class1.class, graphQLAnnotations.getContainer()); +// GraphQLSchema schema = newSchema().query(object).build(); +// +// Class1 class1 = new Class1(); +// Class2 class2 = new Class2(); +// class1.class2 = class2; +// class2.class1 = class1; +// class2.value = "hello"; +// class1.value = "bye"; +// +// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ class2 { value } }", class1); +// assertTrue(result.getErrors().isEmpty()); +// Map data = (Map) result.getData(); +// assertEquals(((Map) data.get("class2")).get("value"), "hello"); +// +// result = GraphQL.newGraphQL(schema).build().execute("{ class2 { class1 { value } } }", class1); +// assertTrue(result.getErrors().isEmpty()); +// data = (Map) result.getData(); +// Map k1 = (Map) ((Map) data.get("class2")).get("class1"); +// assertEquals(k1.get("value"), "bye"); +// +// result = GraphQL.newGraphQL(schema).build().execute("{ class2 { class1 { class2 { value } } } }", class1); +// assertTrue(result.getErrors().isEmpty()); +// } +// +// private static class TestCustomType { +// @GraphQLField +// public UUID id() { +// return UUID.randomUUID(); +// } +// } +// +// @Test +// public void customType() { +// this.graphQLAnnotations.registerTypeFunction(new UUIDTypeFunction()); +// GraphQLObjectType object = this.graphQLAnnotations.object(TestCustomType.class); +// assertEquals(object.getFieldDefinition("id").getType(), GraphQLString); +// } +// +// private static class TestCustomTypeFunction { +// @GraphQLField +// @graphql.annotations.annotationTypes.GraphQLType(UUIDTypeFunction.class) +// public UUID id() { +// return UUID.randomUUID(); +// } +// } +// +// @Test +// public void customTypeFunction() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestCustomTypeFunction.class); +// assertEquals(object.getFieldDefinition("id").getType(), GraphQLString); +// } +// +// public static class TestInputArgument { +// @GraphQLField +// public String a; +// @GraphQLField +// public int b; +// +// public TestInputArgument(@GraphQLName("a") String a, @GraphQLName("b") int b) { +// this.a = a; +// this.b = b; +// } +// } +// +// public static class TestComplexInputArgument { +// +// public Collection inputs; +// +// public TestComplexInputArgument(@GraphQLName("inputs") Collection inputs) { +// this.inputs = inputs; +// } +// +// @GraphQLField +// public Collection inputs() { +// return inputs; +// } +// +// } +// +// +// public static class TestObjectInput { +// @GraphQLField +// public String test(@GraphQLName("other") int other, @GraphQLName("arg") TestInputArgument arg) { +// return arg.a; +// } +// +// @GraphQLField +// public String test2(@GraphQLName("other") int other, @GraphQLName("arg") TestComplexInputArgument arg) { +// return arg.inputs.iterator().next().a; +// } +// } +// +// public static class InputObject { +// @GraphQLField +// int a; +// +// @GraphQLField +// int b; +// } +// +// @Test +// public void inputObjectArgument() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectInput.class); +// GraphQLArgument argument = object.getFieldDefinition("test").getArgument("arg"); +// assertTrue(argument.getType() instanceof GraphQLInputObjectType); +// assertEquals(argument.getName(), "arg"); +// +// GraphQLSchema schema = newAnnotationsSchema().query(TestObjectInput.class).build(); +// 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"); +// } +// +// @Test +// public void complexInputObjectArgument() { +// GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectInput.class); +// GraphQLArgument argument = object.getFieldDefinition("test2").getArgument("arg"); +// assertTrue(argument.getType() instanceof GraphQLInputObjectType); +// assertEquals(argument.getName(), "arg"); +// +// GraphQLSchema schema = newAnnotationsSchema().query(TestObjectInput.class).build(); +// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ test2(arg: {inputs:[{ a:\"ok\", b:2 }]}, other:0) }", new TestObjectInput()); +// assertTrue(result.getErrors().isEmpty()); +// Map v = result.getData(); +// assertEquals(v.get("test2"), "ok"); +// } +// +// @Test +// public void inputObject() { +// GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); +// GraphQLInputObjectType type = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), +// new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). +// getInputObjectBuilder(InputObject.class, this.graphQLAnnotations.getContainer()).build(); +// +// assertEquals(type.getName(), DEFAULT_INPUT_PREFIX + InputObject.class.getSimpleName(), "Type name prefix did not match expected value"); +// assertEquals(type.getFields().size(), InputObject.class.getDeclaredFields().length); +// } +// +// @Test +// public void inputObjectCustomPrefixes() { +// GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); +// ProcessingElementsContainer container = this.graphQLAnnotations.getContainer(); +// container.setInputPrefix(""); +// container.setInputSuffix("Input"); +// GraphQLInputObjectType type = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), +// new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). +// getInputObjectBuilder(InputObject.class, this.graphQLAnnotations.getContainer()).build(); +// +// assertEquals(type.getName(), "" + InputObject.class.getSimpleName() + "Input", "Type name prefix did not match expected value"); +// assertEquals(type.getFields().size(), InputObject.class.getDeclaredFields().length); +// container.setInputPrefix(DEFAULT_INPUT_PREFIX); +// container.setInputSuffix(DEFAULT_INPUT_SUFFIX); +// } +// +// public static class UUIDTypeFunction implements TypeFunction { +// @Override +// 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"; +// } +// +// public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { +// return GraphQLString; +// } +// } +// +// public static class OptionalTest { +// @GraphQLField +// public Optional empty = Optional.empty(); +// @GraphQLField +// public Optional nonempty = Optional.of("test"); +// +// public OptionalTest() { +// } +// +// public OptionalTest(Optional empty, Optional nonempty) { +// this.empty = empty; +// this.nonempty = nonempty; +// } +// +// @Override +// public String toString() { +// return "OptionalTest" + +// "{empty=" + empty + +// ", nonempty=" + nonempty + +// '}'; +// } +// } +// +// @Test +// public void queryOptional() { +// GraphQLObjectType object = this.graphQLAnnotations.object(OptionalTest.class); +// GraphQLSchema schema = newSchema().query(object).build(); +// +// GraphQL graphQL = GraphQL.newGraphQL(schema).build(); +// ExecutionResult result = graphQL.execute("{empty, nonempty}", new OptionalTest()); +// assertTrue(result.getErrors().isEmpty()); +// Map v = (Map) result.getData(); +// assertNull(v.get("empty")); +// assertEquals(v.get("nonempty"), "test"); +// } +// +// @Test +// public void optionalInput() { +// GraphQLObjectType object = this.graphQLAnnotations.object(OptionalTest.class); +// GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); +// GraphQLInputObjectType inputObject = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), +// new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). +// getInputObjectBuilder(OptionalTest.class, this.graphQLAnnotations.getContainer()).build(); +// +// 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"); +// return new OptionalTest(Optional.ofNullable(input.get("empty")), Optional.ofNullable(input.get("nonempty"))); +// }).build()).build(); +// GraphQLSchema schema = newSchema().query(object).mutation(mutation).build(); +// +// GraphQL graphQL = GraphQL.newGraphQL(schema).build(); +// ExecutionResult result = graphQL.execute("mutation {test(input: {empty: \"test\"}) { empty nonempty } }", new OptionalTest()); +// assertTrue(result.getErrors().isEmpty()); +// Map v = (Map) ((Map) result.getData()).get("test"); +// assertEquals(v.get("empty"), "test"); +// assertNull(v.get("nonempty")); +// } +// +// public static class EnumTest { +// public enum E {A, B} +// +// @GraphQLField +// public E e; +// +// public EnumTest() { +// } +// +// public EnumTest(E e) { +// this.e = e; +// } +// +// @Override +// public String toString() { +// return "EnumTest{" + "e=" + e + '}'; +// } +// } +// +// @Test +// public void queryEnum() { +// GraphQLObjectType object = this.graphQLAnnotations.object(EnumTest.class); +// GraphQLSchema schema = newSchema().query(object).build(); +// GraphQL graphQL = GraphQL.newGraphQL(schema).build(); +// +// ExecutionResult result = graphQL.execute("{e}", new EnumTest(EnumTest.E.B)); +// assertTrue(result.getErrors().isEmpty()); +// Map v = (Map) result.getData(); +// assertEquals(v.get("e"), "B"); +// } +// +// public static class ParametrizedArgsTest { +// @GraphQLField +// public String first(List l) { +// return l.get(0); +// } +// } +// +// @Test +// public void parametrizedArg() { +// GraphQLObjectType object = this.graphQLAnnotations.object(ParametrizedArgsTest.class); +// GraphQLInputType t = object.getFieldDefinition("first").getArguments().get(0).getType(); +// assertTrue(t instanceof GraphQLList); +// assertEquals(((GraphQLList) t).getWrappedType(), Scalars.GraphQLString); +// } +// +// @GraphQLField +// public static class InheritGraphQLFieldTest { +// public String inheritedOn; +// +// @GraphQLField(false) +// public String forcedOff; +// +// public String on() { +// return "on"; +// } +// +// @GraphQLField(false) +// public String off() { +// return "off"; +// } +// +// } +// +// @Test +// public void inheritGraphQLField() { +// GraphQLObjectType object = this.graphQLAnnotations.object(InheritGraphQLFieldTest.class); +// assertNotNull(object.getFieldDefinition("on")); +// assertNull(object.getFieldDefinition("off")); +// assertNotNull(object.getFieldDefinition("inheritedOn")); +// assertNull(object.getFieldDefinition("forcedOff")); +// } +// +// +//} diff --git a/src/test/java/graphql/annotations/SchemaTransformerTest.java b/src/test/java/graphql/annotations/SchemaTransformerTest.java new file mode 100644 index 00000000..32ba3a64 --- /dev/null +++ b/src/test/java/graphql/annotations/SchemaTransformerTest.java @@ -0,0 +1,111 @@ +package graphql.annotations; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLInvokeDetached; +import graphql.schema.*; +import graphql.util.TraversalControl; +import graphql.util.TraverserContext; +import org.testng.annotations.Test; + +import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema; +import static graphql.util.TreeTransformerUtil.changeNode; + +public class SchemaTransformerTest { + + class A { + @GraphQLField + String x; + } + + class Query { + @GraphQLField + @GraphQLInvokeDetached + public A getA() { + return new A(); + } + } + + class Visitor implements GraphQLTypeVisitor { + @Override + public TraversalControl visitGraphQLArgument(GraphQLArgument node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLInterfaceType(GraphQLInterfaceType node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLEnumType(GraphQLEnumType node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLEnumValueDefinition(GraphQLEnumValueDefinition node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLFieldDefinition(GraphQLFieldDefinition node, TraverserContext context) { + if (node.getName().equals("x")) { + GraphQLFieldDefinition y = node.transform(builder -> builder.name("y")); + return changeNode(context, y); + } + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLDirective(GraphQLDirective node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLInputObjectField(GraphQLInputObjectField node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLInputObjectType(GraphQLInputObjectType node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLList(GraphQLList node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLNonNull(GraphQLNonNull node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLObjectType(GraphQLObjectType node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLScalarType(GraphQLScalarType node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLTypeReference(GraphQLTypeReference node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + + @Override + public TraversalControl visitGraphQLUnionType(GraphQLUnionType node, TraverserContext context) { + return TraversalControl.CONTINUE; + } + } + + @Test + public void test() { + GraphQLSchema schema = newAnnotationsSchema().query(Query.class).build(); + SchemaTransformer schemaTransformer = new SchemaTransformer(); + GraphQLSchema transformedSchema = schemaTransformer.transform(schema, new Visitor()); + System.out.println(transformedSchema.toString()); + } +} diff --git a/src/test/java/graphql/annotations/directives/DirectiveWirerTest.java b/src/test/java/graphql/annotations/directives/DirectiveWirerTest.java index 937a0d67..7c7f319d 100644 --- a/src/test/java/graphql/annotations/directives/DirectiveWirerTest.java +++ b/src/test/java/graphql/annotations/directives/DirectiveWirerTest.java @@ -1,517 +1,517 @@ -/** - * 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.directives; - -import graphql.TypeResolutionEnvironment; -import graphql.introspection.Introspection; -import graphql.schema.*; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.HashMap; - -import static graphql.Scalars.GraphQLString; -import static graphql.schema.GraphQLDirective.newDirective; -import static org.mockito.Mockito.*; - -public class DirectiveWirerTest { - - private DirectiveWirer directiveWirer; - private String parentName = "parent"; - private GraphQLCodeRegistry.Builder builder; - - @BeforeMethod - public void setUp() throws Exception { - directiveWirer = new DirectiveWirer(); - builder = mock(GraphQLCodeRegistry.Builder.class); - } - - // GraphQLFieldDefinition - - @Test - public void wireFieldDefinition_validLocations_correctMethodIsCalled() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - AnnotationsDirectiveWiring lowerWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLFieldDefinition directiveContainer = GraphQLFieldDefinition.newFieldDefinition().name("bla") - .type(GraphQLString).build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, - directiveContainer.getDirective("upperCase"), parentName, builder); - AnnotationsWiringEnvironmentImpl lowerCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, - directiveContainer.getDirective("lowerCase"), parentName, builder); - - when(upperWiring.onField(upperCaseEnv)).thenReturn(directiveContainer); - when(lowerWiring.onField(lowerCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.FIELD_DEFINITION).build(); - GraphQLDirective lowerCase = newDirective().name("lowerCase").validLocations(Introspection.DirectiveLocation.FIELD).build(); - map.put(upperCase, upperWiring); - map.put(lowerCase, lowerWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - - // Assert - - verify(upperWiring).onField(upperCaseEnv); - verify(lowerWiring).onField(lowerCaseEnv); - } - - @Test(expectedExceptions = InvalidDirectiveLocationException.class) - public void wireFieldDefinition_invalidLocations_exceptionIsThrown() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLFieldDefinition directiveContainer = GraphQLFieldDefinition.newFieldDefinition().name("bla") - .type(GraphQLString).build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, - directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onField(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ENUM).build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - } - - // GraphQLObjectType - - @Test - public void wireGraphQLObjectType_validLocations_correctMethodIsCalled() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLObjectType directiveContainer = GraphQLObjectType.newObject().name("asdf").build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, - directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onObject(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.OBJECT).build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - - // Assert - - verify(upperWiring).onObject(upperCaseEnv); - } - - @Test(expectedExceptions = InvalidDirectiveLocationException.class) - public void wireGraphQLObjectType_invalidLocations_exceptionIsThrown() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLObjectType directiveContainer = GraphQLObjectType.newObject().name("asdf00").build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, - directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onObject(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - } - - // GraphQLArgument - - @Test - public void wireGraphQLArgument_validLocations_correctMethodIsCalled() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLArgument directiveContainer = GraphQLArgument.newArgument().name("asdf").type(GraphQLString).build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, - directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onArgument(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ARGUMENT_DEFINITION).build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - - // Assert - - verify(upperWiring).onArgument(upperCaseEnv); - } - - @Test(expectedExceptions = InvalidDirectiveLocationException.class) - public void wireGraphQLArgument_invalidLocations_exceptionIsThrown() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLArgument directiveContainer = GraphQLArgument.newArgument().name("asdf0").type(GraphQLString).build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, - directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onArgument(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - } - - // GraphQLInterfaceType - - @Test - public void wireGraphQLInterfaceType_validLocations_correctMethodIsCalled() { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLInterfaceType directiveContainer = GraphQLInterfaceType.newInterface().name("asdf").build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, - directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onInterface(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.INTERFACE).build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - - // Assert - - verify(upperWiring).onInterface(upperCaseEnv); - } - - @Test(expectedExceptions = InvalidDirectiveLocationException.class) - public void wireGraphQLInterfaceType_invalidLocations_exceptionIsThrown() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLInterfaceType directiveContainer = GraphQLInterfaceType.newInterface().name("asdf").build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, - directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onInterface(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - } - - // GraphQLUnionType - - @Test - public void wireGraphQLUnionType_validLocations_correctMethodIsCalled() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLUnionType directiveContainer = GraphQLUnionType.newUnionType().name("asdf") - .possibleType(GraphQLObjectType.newObject().name("Asdfaaaa").build()).build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( - directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onUnion(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.UNION).build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - - // Assert - - verify(upperWiring).onUnion(upperCaseEnv); - } - - @Test(expectedExceptions = InvalidDirectiveLocationException.class) - public void wireGraphQLUnionType_invalidLocations_exceptionIsThrown() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLUnionType directiveContainer = GraphQLUnionType.newUnionType().name("asdf") - .possibleType(GraphQLObjectType.newObject().name("Asdfaaaa").build()).build(); - - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( - directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onUnion(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - } - - // GraphQLEnumType - - @Test - public void wireGraphQLEnumType_validLocations_correctMethodIsCalled() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLEnumType directiveContainer = GraphQLEnumType.newEnum().name("asdf").value("asdfasdf").build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( - directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onEnum(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ENUM).build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - - // Assert - - verify(upperWiring).onEnum(upperCaseEnv); - } - - @Test(expectedExceptions = InvalidDirectiveLocationException.class) - public void wireGraphQLEnumType_invalidLocations_exceptionIsThrown() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLEnumType directiveContainer = GraphQLEnumType.newEnum().name("asdf").value("asdfasdf").build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( - directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onEnum(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - } - - // GraphQLEnumValueDefinition - - @Test - public void wireGraphQLEnumValueDefinition_validLocations_correctMethodIsCalled() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLEnumValueDefinition directiveContainer = GraphQLEnumValueDefinition.newEnumValueDefinition().name("asdf").build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, - directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onEnumValue(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ENUM_VALUE).build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - - // Assert - - verify(upperWiring).onEnumValue(upperCaseEnv); - } - - @Test(expectedExceptions = InvalidDirectiveLocationException.class) - public void wireGraphQLEnumValueDefinition_invalidLocations_exceptionIsThrown() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLEnumValueDefinition directiveContainer = GraphQLEnumValueDefinition.newEnumValueDefinition().name("asdf").build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( - directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onEnumValue(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - } - - // GraphQLScalarType - - @Test - public void wireGraphQLScalarType_validLocations_correctMethodIsCalled() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLScalarType directiveContainer = GraphQLString; - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( - directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onScalar(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.SCALAR).build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - - // Assert - - verify(upperWiring).onScalar(upperCaseEnv); - } - - @Test(expectedExceptions = InvalidDirectiveLocationException.class) - public void wireGraphQLScalarType_invalidLocations_exceptionIsThrown() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLScalarType directiveContainer = GraphQLString; - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( - directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onScalar(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - } - - // GraphQLInputObjectType - - @Test - public void wireGraphQLInputObjectType_validLocations_correctMethodIsCalled() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLInputObjectType directiveContainer = GraphQLInputObjectType.newInputObject().name("asdf") - .build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( - directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onInputObjectType(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.INPUT_OBJECT).build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - - // Assert - - verify(upperWiring).onInputObjectType(upperCaseEnv); - } - - @Test(expectedExceptions = InvalidDirectiveLocationException.class) - public void wireGraphQLInputObjectType_invalidLocations_exceptionIsThrown() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLInputObjectType directiveContainer = GraphQLInputObjectType.newInputObject().name("asdf") - .build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( - directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onInputObjectType(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - } - - // GraphQLInputObjectField - - @Test - public void wireGraphQLInputObjectField_validLocations_correctMethodIsCalled() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLInputObjectField directiveContainer = GraphQLInputObjectField.newInputObjectField().name("asdf") - .type(GraphQLInputObjectType.newInputObject().name("dfdf").build()).build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( - directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onInputObjectField(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION).build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - - // Assert - - verify(upperWiring).onInputObjectField(upperCaseEnv); - } - - @Test(expectedExceptions = InvalidDirectiveLocationException.class) - public void wireGraphQLInputObjectField_invalidLocations_exceptionIsThrown() throws Exception { - // Arrange - AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); - - GraphQLInputObjectField directiveContainer = GraphQLInputObjectField.newInputObjectField().name("asdf") - .type(GraphQLInputObjectType.newInputObject().name("dfdf").build()).build(); - - AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, - directiveContainer.getDirective("upperCase"), parentName, builder); - - when(upperWiring.onInputObjectField(upperCaseEnv)).thenReturn(directiveContainer); - - HashMap map = new HashMap<>(); - GraphQLDirective upperCase = newDirective().name("upperCase").build(); - map.put(upperCase, upperWiring); - - // Act - directiveWirer.wire(directiveContainer, map, builder, parentName); - } - -} +///** +// * 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.directives; +// +//import graphql.TypeResolutionEnvironment; +//import graphql.introspection.Introspection; +//import graphql.schema.*; +//import org.testng.annotations.BeforeMethod; +//import org.testng.annotations.Test; +// +//import java.util.HashMap; +// +//import static graphql.Scalars.GraphQLString; +//import static graphql.schema.GraphQLDirective.newDirective; +//import static org.mockito.Mockito.*; +// +//public class DirectiveWirerTest { +// +// private DirectiveWirer directiveWirer; +// private String parentName = "parent"; +// private GraphQLCodeRegistry.Builder builder; +// +// @BeforeMethod +// public void setUp() throws Exception { +// directiveWirer = new DirectiveWirer(); +// builder = mock(GraphQLCodeRegistry.Builder.class); +// } +// +// // GraphQLFieldDefinition +// +// @Test +// public void wireFieldDefinition_validLocations_correctMethodIsCalled() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// AnnotationsDirectiveWiring lowerWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLFieldDefinition directiveContainer = GraphQLFieldDefinition.newFieldDefinition().name("bla") +// .type(GraphQLString).build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, +// directiveContainer.getDirective("upperCase"), parentName, builder); +// AnnotationsWiringEnvironmentImpl lowerCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, +// directiveContainer.getDirective("lowerCase"), parentName, builder); +// +// when(upperWiring.onField(upperCaseEnv)).thenReturn(directiveContainer); +// when(lowerWiring.onField(lowerCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.FIELD_DEFINITION).build(); +// GraphQLDirective lowerCase = newDirective().name("lowerCase").validLocations(Introspection.DirectiveLocation.FIELD).build(); +// map.put(upperCase, upperWiring); +// map.put(lowerCase, lowerWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// +// // Assert +// +// verify(upperWiring).onField(upperCaseEnv); +// verify(lowerWiring).onField(lowerCaseEnv); +// } +// +// @Test(expectedExceptions = InvalidDirectiveLocationException.class) +// public void wireFieldDefinition_invalidLocations_exceptionIsThrown() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLFieldDefinition directiveContainer = GraphQLFieldDefinition.newFieldDefinition().name("bla") +// .type(GraphQLString).build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, +// directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onField(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ENUM).build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// } +// +// // GraphQLObjectType +// +// @Test +// public void wireGraphQLObjectType_validLocations_correctMethodIsCalled() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLObjectType directiveContainer = GraphQLObjectType.newObject().name("asdf").build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, +// directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onObject(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.OBJECT).build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// +// // Assert +// +// verify(upperWiring).onObject(upperCaseEnv); +// } +// +// @Test(expectedExceptions = InvalidDirectiveLocationException.class) +// public void wireGraphQLObjectType_invalidLocations_exceptionIsThrown() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLObjectType directiveContainer = GraphQLObjectType.newObject().name("asdf00").build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, +// directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onObject(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// } +// +// // GraphQLArgument +// +// @Test +// public void wireGraphQLArgument_validLocations_correctMethodIsCalled() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLArgument directiveContainer = GraphQLArgument.newArgument().name("asdf").type(GraphQLString).build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, +// directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onArgument(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ARGUMENT_DEFINITION).build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// +// // Assert +// +// verify(upperWiring).onArgument(upperCaseEnv); +// } +// +// @Test(expectedExceptions = InvalidDirectiveLocationException.class) +// public void wireGraphQLArgument_invalidLocations_exceptionIsThrown() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLArgument directiveContainer = GraphQLArgument.newArgument().name("asdf0").type(GraphQLString).build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, +// directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onArgument(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// } +// +// // GraphQLInterfaceType +// +// @Test +// public void wireGraphQLInterfaceType_validLocations_correctMethodIsCalled() { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLInterfaceType directiveContainer = GraphQLInterfaceType.newInterface().name("asdf").build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, +// directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onInterface(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.INTERFACE).build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// +// // Assert +// +// verify(upperWiring).onInterface(upperCaseEnv); +// } +// +// @Test(expectedExceptions = InvalidDirectiveLocationException.class) +// public void wireGraphQLInterfaceType_invalidLocations_exceptionIsThrown() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLInterfaceType directiveContainer = GraphQLInterfaceType.newInterface().name("asdf").build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, +// directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onInterface(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// } +// +// // GraphQLUnionType +// +// @Test +// public void wireGraphQLUnionType_validLocations_correctMethodIsCalled() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLUnionType directiveContainer = GraphQLUnionType.newUnionType().name("asdf") +// .possibleType(GraphQLObjectType.newObject().name("Asdfaaaa").build()).build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( +// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onUnion(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.UNION).build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// +// // Assert +// +// verify(upperWiring).onUnion(upperCaseEnv); +// } +// +// @Test(expectedExceptions = InvalidDirectiveLocationException.class) +// public void wireGraphQLUnionType_invalidLocations_exceptionIsThrown() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLUnionType directiveContainer = GraphQLUnionType.newUnionType().name("asdf") +// .possibleType(GraphQLObjectType.newObject().name("Asdfaaaa").build()).build(); +// +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( +// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onUnion(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// } +// +// // GraphQLEnumType +// +// @Test +// public void wireGraphQLEnumType_validLocations_correctMethodIsCalled() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLEnumType directiveContainer = GraphQLEnumType.newEnum().name("asdf").value("asdfasdf").build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( +// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onEnum(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ENUM).build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// +// // Assert +// +// verify(upperWiring).onEnum(upperCaseEnv); +// } +// +// @Test(expectedExceptions = InvalidDirectiveLocationException.class) +// public void wireGraphQLEnumType_invalidLocations_exceptionIsThrown() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLEnumType directiveContainer = GraphQLEnumType.newEnum().name("asdf").value("asdfasdf").build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( +// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onEnum(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// } +// +// // GraphQLEnumValueDefinition +// +// @Test +// public void wireGraphQLEnumValueDefinition_validLocations_correctMethodIsCalled() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLEnumValueDefinition directiveContainer = GraphQLEnumValueDefinition.newEnumValueDefinition().name("asdf").build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, +// directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onEnumValue(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ENUM_VALUE).build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// +// // Assert +// +// verify(upperWiring).onEnumValue(upperCaseEnv); +// } +// +// @Test(expectedExceptions = InvalidDirectiveLocationException.class) +// public void wireGraphQLEnumValueDefinition_invalidLocations_exceptionIsThrown() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLEnumValueDefinition directiveContainer = GraphQLEnumValueDefinition.newEnumValueDefinition().name("asdf").build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( +// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onEnumValue(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// } +// +// // GraphQLScalarType +// +// @Test +// public void wireGraphQLScalarType_validLocations_correctMethodIsCalled() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLScalarType directiveContainer = GraphQLString; +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( +// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onScalar(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.SCALAR).build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// +// // Assert +// +// verify(upperWiring).onScalar(upperCaseEnv); +// } +// +// @Test(expectedExceptions = InvalidDirectiveLocationException.class) +// public void wireGraphQLScalarType_invalidLocations_exceptionIsThrown() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLScalarType directiveContainer = GraphQLString; +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( +// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onScalar(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// } +// +// // GraphQLInputObjectType +// +// @Test +// public void wireGraphQLInputObjectType_validLocations_correctMethodIsCalled() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLInputObjectType directiveContainer = GraphQLInputObjectType.newInputObject().name("asdf") +// .build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( +// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onInputObjectType(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.INPUT_OBJECT).build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// +// // Assert +// +// verify(upperWiring).onInputObjectType(upperCaseEnv); +// } +// +// @Test(expectedExceptions = InvalidDirectiveLocationException.class) +// public void wireGraphQLInputObjectType_invalidLocations_exceptionIsThrown() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLInputObjectType directiveContainer = GraphQLInputObjectType.newInputObject().name("asdf") +// .build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( +// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onInputObjectType(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// } +// +// // GraphQLInputObjectField +// +// @Test +// public void wireGraphQLInputObjectField_validLocations_correctMethodIsCalled() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLInputObjectField directiveContainer = GraphQLInputObjectField.newInputObjectField().name("asdf") +// .type(GraphQLInputObjectType.newInputObject().name("dfdf").build()).build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( +// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onInputObjectField(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION).build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// +// // Assert +// +// verify(upperWiring).onInputObjectField(upperCaseEnv); +// } +// +// @Test(expectedExceptions = InvalidDirectiveLocationException.class) +// public void wireGraphQLInputObjectField_invalidLocations_exceptionIsThrown() throws Exception { +// // Arrange +// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); +// +// GraphQLInputObjectField directiveContainer = GraphQLInputObjectField.newInputObjectField().name("asdf") +// .type(GraphQLInputObjectType.newInputObject().name("dfdf").build()).build(); +// +// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, +// directiveContainer.getDirective("upperCase"), parentName, builder); +// +// when(upperWiring.onInputObjectField(upperCaseEnv)).thenReturn(directiveContainer); +// +// HashMap map = new HashMap<>(); +// GraphQLDirective upperCase = newDirective().name("upperCase").build(); +// map.put(upperCase, upperWiring); +// +// // Act +// directiveWirer.wire(directiveContainer, map, builder, parentName); +// } +// +//} From f3e711891027d3d324ef712e41ce81fa6699135a Mon Sep 17 00:00:00 2001 From: Yarin Date: Sun, 19 Jan 2020 02:13:05 +0200 Subject: [PATCH 05/14] fixes: fix tests --- .../annotations/AnnotationsSchemaCreator.java | 8 +- .../directives/DirectiveSchemaVisitor.java | 10 +- .../TreeTransformerUtilWrapper.java | 11 + .../annotations/GraphQLObjectTest.java | 1802 ++++++++--------- .../DirectiveSchemaVisitorTest.java | 149 ++ 5 files changed, 1071 insertions(+), 909 deletions(-) create mode 100644 src/main/java/graphql/annotations/directives/TreeTransformerUtilWrapper.java create mode 100644 src/test/java/graphql/annotations/directives/DirectiveSchemaVisitorTest.java diff --git a/src/main/java/graphql/annotations/AnnotationsSchemaCreator.java b/src/main/java/graphql/annotations/AnnotationsSchemaCreator.java index 1001b5ef..5d03f01d 100644 --- a/src/main/java/graphql/annotations/AnnotationsSchemaCreator.java +++ b/src/main/java/graphql/annotations/AnnotationsSchemaCreator.java @@ -16,6 +16,7 @@ import graphql.annotations.directives.AnnotationsDirectiveWiring; import graphql.annotations.directives.DirectiveSchemaVisitor; +import graphql.annotations.directives.TreeTransformerUtilWrapper; import graphql.annotations.processor.DirectiveAndWiring; import graphql.annotations.processor.GraphQLAnnotations; import graphql.annotations.processor.typeFunctions.TypeFunction; @@ -267,9 +268,10 @@ public GraphQLSchema build() { GraphQLSchema schema = this.graphqlSchemaBuilder.build(); // wire with directives HashMap directiveWiringHashMap = transformDirectiveRegistry(this.graphQLAnnotations.getContainer().getDirectiveRegistry()); - DirectiveSchemaVisitor directiveSchemaVisitor = new DirectiveSchemaVisitor(directiveWiringHashMap, graphQLAnnotations.getContainer().getCodeRegistryBuilder()); - GraphQLSchema trasnformedSchema = this.schemaTransformer.transform(schema, directiveSchemaVisitor); - return newSchema(trasnformedSchema).codeRegistry(graphQLAnnotations.getContainer().getCodeRegistryBuilder().build()).build(); + DirectiveSchemaVisitor directiveSchemaVisitor = new DirectiveSchemaVisitor(directiveWiringHashMap, + graphQLAnnotations.getContainer().getCodeRegistryBuilder(), new TreeTransformerUtilWrapper()); + GraphQLSchema transformedSchema = this.schemaTransformer.transform(schema, directiveSchemaVisitor); + return newSchema(transformedSchema).codeRegistry(graphQLAnnotations.getContainer().getCodeRegistryBuilder().build()).build(); } private HashMap transformDirectiveRegistry(Map directiveRegistry) { diff --git a/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java b/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java index ee6ab5de..89a30b49 100644 --- a/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java +++ b/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java @@ -11,11 +11,10 @@ import java.util.List; import java.util.Map; -import static graphql.util.TreeTransformerUtil.changeNode; - public class DirectiveSchemaVisitor implements GraphQLTypeVisitor { private HashMap directiveWiringMap; private GraphQLCodeRegistry.Builder codeRegistryBuilder; + private TreeTransformerUtilWrapper transformerUtilWrapper; @FunctionalInterface interface WiringFunction { @@ -27,10 +26,12 @@ GraphQLDirectiveContainer apply(GraphQLDirective a, GraphQLDirectiveContainer b, private Map functionMap; - public DirectiveSchemaVisitor(HashMap directiveWiringMap, GraphQLCodeRegistry.Builder codeRegistryBuilder) { + public DirectiveSchemaVisitor(HashMap directiveWiringMap, GraphQLCodeRegistry.Builder codeRegistryBuilder, + TreeTransformerUtilWrapper treeTransformerUtilWrapper) { this.directiveWiringMap = directiveWiringMap; this.functionMap = createFunctionsMap(); this.codeRegistryBuilder = codeRegistryBuilder; + this.transformerUtilWrapper = treeTransformerUtilWrapper; } @Override @@ -38,7 +39,6 @@ public TraversalControl visitGraphQLArgument(GraphQLArgument node, TraverserCont return this.visitGraphQLType(GraphQLArgument.class, node, context); } - @Override public TraversalControl visitGraphQLInterfaceType(GraphQLInterfaceType node, TraverserContext context) { return this.visitGraphQLType(GraphQLInterfaceType.class, node, context); @@ -124,7 +124,7 @@ private TraversalControl visitGraphQLType(Class map, Class clazz, String functionName, diff --git a/src/main/java/graphql/annotations/directives/TreeTransformerUtilWrapper.java b/src/main/java/graphql/annotations/directives/TreeTransformerUtilWrapper.java new file mode 100644 index 00000000..ebdfd123 --- /dev/null +++ b/src/main/java/graphql/annotations/directives/TreeTransformerUtilWrapper.java @@ -0,0 +1,11 @@ +package graphql.annotations.directives; + +import graphql.util.TraversalControl; +import graphql.util.TraverserContext; +import graphql.util.TreeTransformerUtil; + +public class TreeTransformerUtilWrapper { + public TraversalControl changeNode(TraverserContext context, T changedNode) { + return TreeTransformerUtil.changeNode(context, changedNode); + } +} diff --git a/src/test/java/graphql/annotations/GraphQLObjectTest.java b/src/test/java/graphql/annotations/GraphQLObjectTest.java index 890fdcc4..d3893a7d 100644 --- a/src/test/java/graphql/annotations/GraphQLObjectTest.java +++ b/src/test/java/graphql/annotations/GraphQLObjectTest.java @@ -1,901 +1,901 @@ -///** -// * 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.ExecutionResult; -//import graphql.GraphQL; -//import graphql.Scalars; -//import graphql.annotations.annotationTypes.*; -//import graphql.annotations.annotationTypes.GraphQLNonNull; -//import graphql.annotations.processor.GraphQLAnnotations; -//import graphql.annotations.processor.ProcessingElementsContainer; -//import graphql.annotations.processor.retrievers.GraphQLFieldRetriever; -//import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; -//import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; -//import graphql.annotations.processor.searchAlgorithms.ParentalSearch; -//import graphql.annotations.processor.typeBuilders.InputObjectBuilder; -//import graphql.annotations.processor.typeFunctions.TypeFunction; -//import graphql.annotations.processor.util.CodeRegistryUtil; -//import graphql.schema.*; -//import graphql.schema.GraphQLType; -//import graphql.schema.idl.SchemaParser; -//import graphql.schema.idl.SchemaPrinter; -//import graphql.schema.idl.TypeDefinitionRegistry; -//import org.testng.annotations.BeforeMethod; -//import org.testng.annotations.Test; -// -//import java.lang.reflect.AnnotatedType; -//import java.util.*; -//import java.util.function.Supplier; -// -//import static graphql.Scalars.GraphQLString; -//import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema; -//import static graphql.annotations.processor.util.InputPropertiesUtil.DEFAULT_INPUT_PREFIX; -//import static graphql.annotations.processor.util.InputPropertiesUtil.DEFAULT_INPUT_SUFFIX; -//import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; -//import static graphql.schema.GraphQLSchema.newSchema; -//import static org.testng.Assert.*; -// -//@SuppressWarnings("unchecked") -//public class GraphQLObjectTest { -// -// private GraphQLAnnotations graphQLAnnotations; -// -// @BeforeMethod -// public void init() { -// this.graphQLAnnotations = new GraphQLAnnotations(); -// } -// -// public static class DefaultAValue implements Supplier { -// -// @Override -// public Object get() { -// return "default"; -// } -// } -// -// @GraphQLDescription("TestObject object") -// @GraphQLName("TestObject") -// public static class TestObject { -// @GraphQLField -// @GraphQLName("field0") -// @GraphQLDescription("field") -// public -// @GraphQLNonNull -// String field() { -// return "test"; -// } -// -// @GraphQLField -// 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, @GraphQLName("a") String a, @GraphQLName("b") String b) { -// return a; -// } -// -// @GraphQLField -// @Deprecated -// public String deprecated() { -// return null; -// } -// -// @GraphQLField -// @GraphQLDeprecate("Reason") -// public String deprecate() { -// return null; -// } -// -// @GraphQLField -// public String publicTest = "public"; -// -// @GraphQLField -// private String privateTest = "private"; -// -// public String getPrivateTest() { -// return privateTest; -// } -// -// public void setPrivateTest(String privateTest) { -// this.privateTest = privateTest; -// } -// -// @GraphQLNonNull -// @GraphQLField -// @GraphQLName("z_nonOptionalString") -// private String z; -// -// public String getZ() { -// return z; -// } -// -// public void setZ(String z) { -// this.z = z; -// } -// -// } -// -// private static class TestDefaults { -// } -// -// private static class TestObjectNamedArgs { -// @GraphQLField -// public String fieldWithNamedArgs(@GraphQLName("namedArg") String firstArgument) { -// return firstArgument; -// } -// } -// -// public static class TestMappedObject { -// @GraphQLField -// public String name; -// -// @GraphQLField -// public String aaa; -// } -// -// public static class TestObjectDB { -// public String aaa; -// -// private String name; -// -// public String getName() { -// return name; -// } -// -// public TestObjectDB(String name, String aaa) { -// this.name = name; -// this.aaa = aaa; -// } -// } -// -// public static class TestQuery { -// @GraphQLField -// @GraphQLDataFetcher(ObjectFetcher.class) -// public TestMappedObject object; -// } -// -// public static class ObjectFetcher implements DataFetcher { -// -// @Override -// public TestObjectDB get(DataFetchingEnvironment environment) { -// return new TestObjectDB("test", "test"); -// } -// } -// -// public static class NameTest { -// @GraphQLField -// public Boolean isCool; -// -// @GraphQLField -// @GraphQLPrettify -// public Boolean isAwesome; -// -// @GraphQLField -// @GraphQLPrettify -// @GraphQLName("yarinnn") -// public Boolean isYarin; -// -// @GraphQLField -// public String getX() { -// return "Asdf0"; -// } -// -// @GraphQLField -// @GraphQLPrettify -// public String getY() { -// return "asd"; -// } -// -// @GraphQLField -// @GraphQLPrettify -// @GraphQLName("daniel") -// public String setM() { -// return "Asdf"; -// } -// -// } -// -// @Test -// public void objectCreation_nameIsCorrect() { -// // Act -// GraphQLObjectType object = this.graphQLAnnotations.object(NameTest.class); -// -// // Assert -// assertNotNull(object.getFieldDefinition("awesome")); -// assertNotNull(object.getFieldDefinition("isCool")); -// assertNotNull(object.getFieldDefinition("yarinnn")); -// assertNotNull(object.getFieldDefinition("getX")); -// assertNotNull(object.getFieldDefinition("y")); -// assertNotNull(object.getFieldDefinition("daniel")); -// } -// -// @Test -// public void fetchTestMappedObject_assertNameIsMappedFromDBObject() { -// GraphQLSchema schema = newAnnotationsSchema().query(TestQuery.class).build(); -// -// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{object {name aaa}}"); -// assertTrue(result.getErrors().isEmpty()); -// assertEquals(((LinkedHashMap) (((LinkedHashMap) result.getData()).get("object"))).get("name"), "test"); -// assertEquals(((LinkedHashMap) (((LinkedHashMap) result.getData()).get("object"))).get("aaa"), "test"); -// } -// -// @Test -// public void namedFields() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectNamedArgs.class); -// List fields = object.getFieldDefinitions(); -// assertEquals(fields.size(), 1); -// -// List args = fields.get(0).getArguments(); -// assertEquals(args.size(), 1); -// -// GraphQLArgument arg = args.get(0); -// assertEquals(arg.getName(), "namedArg"); -// } -// -// @Test -// public void metainformation() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); -// assertEquals(object.getName(), "TestObject"); -// assertEquals(object.getDescription(), "TestObject object"); -// } -// -// @Test -// public void objectClass() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); -// assertTrue(object instanceof GraphQLObjectType); -// } -// -// @Test -// public void testSchema() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); -// String schema = new SchemaPrinter().print(object); -// assertTrue(schema.contains("type TestObject {")); -// TypeDefinitionRegistry reg = new SchemaParser().parse(schema); -// assertTrue(reg.getType("TestObject").isPresent()); -// assertEquals(new SchemaParser().parse(schema).getType("TestObject").get().getChildren().size(), 8); -// } -// -// @Test -// public void fields() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); -// List fields = object.getFieldDefinitions(); -// assertEquals(fields.size(), 8); -// -// fields.sort((o1, o2) -> o1.getName().compareTo(o2.getName())); -// -// assertEquals(fields.get(2).getName(), "field0"); -// assertEquals(fields.get(2).getDescription(), "field"); -// assertTrue(fields.get(2).getType() instanceof graphql.schema.GraphQLNonNull); -// assertEquals(((graphql.schema.GraphQLNonNull) fields.get(2).getType()).getWrappedType(), GraphQLString); -// -// assertEquals(fields.get(3).getName(), "fieldWithArgs"); -// List args = fields.get(3).getArguments(); -// assertEquals(args.size(), 2); -// assertEquals(args.get(0).getName(), "a"); -// assertTrue(args.get(0).getType() instanceof graphql.schema.GraphQLNonNull); -// assertEquals(((graphql.schema.GraphQLNonNull) args.get(0).getType()).getWrappedType(), GraphQLString); -// assertEquals(args.get(1).getName(), "b"); -// assertEquals(args.get(1).getType(), GraphQLString); -// assertEquals(args.get(1).getDescription(), "b"); -// -// assertEquals(fields.get(4).getName(), "fieldWithArgsAndEnvironment"); -// args = fields.get(4).getArguments(); -// assertEquals(args.size(), 2); -// -// assertEquals(fields.get(1).getName(), "deprecated"); -// assertTrue(fields.get(1).isDeprecated()); -// -// assertEquals(fields.get(0).getName(), "deprecate"); -// assertTrue(fields.get(0).isDeprecated()); -// assertEquals(fields.get(0).getDeprecationReason(), "Reason"); -// -// assertEquals(fields.get(5).getName(), "privateTest"); -// assertEquals(fields.get(6).getName(), "publicTest"); -// -// DataFetcher dataFetcher1 = CodeRegistryUtil.getDataFetcher(this.graphQLAnnotations.getContainer().getCodeRegistryBuilder(), "TestObject", fields.get(5)); -// DataFetcher dataFetcher2 = CodeRegistryUtil.getDataFetcher(this.graphQLAnnotations.getContainer().getCodeRegistryBuilder(), "TestObject", fields.get(6)); -// assertEquals(dataFetcher1.getClass(), PropertyDataFetcher.class); -// assertEquals(dataFetcher2.getClass(), PropertyDataFetcher.class); -// -// assertEquals(fields.get(7).getName(), "z_nonOptionalString"); -// assertTrue(fields.get(7).getType() instanceof graphql.schema.GraphQLNonNull); -// } -// -// public static class TestObjectInherited extends TestObject { -// @Override -// @GraphQLName("field1") // Test overriding field -// public String field() { -// return "inherited"; -// } -// } -// -// @Test -// public void methodInheritance() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); -// GraphQLObjectType objectInherited = this.graphQLAnnotations.object(TestObjectInherited.class); -// assertEquals(object.getFieldDefinitions().size(), objectInherited.getFieldDefinitions().size()); -// -// GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); -// GraphQLSchema schemaInherited = newAnnotationsSchema().query(TestObjectInherited.class).build(); -// -// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field0}", new TestObject()); -// assertEquals(((Map) result.getData()).get("field0"), "test"); -// GraphQL graphQL = GraphQL.newGraphQL(schemaInherited).build(); -// result = graphQL.execute("{field1}", new TestObjectInherited()); -// assertEquals(((Map) result.getData()).get("field1"), "inherited"); -// } -// -// public static class TestObjectBridgMethodParent { -// private final Type id; -// -// public TestObjectBridgMethodParent(Type id) { -// this.id = id; -// } -// -// public Type id() { -// return id; -// } -// } -// -// public static class TestObjectBridgMethod extends TestObjectBridgMethodParent { -// -// public TestObjectBridgMethod() { -// super(1L); -// } -// -// @Override -// @GraphQLField -// public Long id() { -// return super.id(); -// } -// } -// -// @Test -// public void methodInheritanceWithGenerics() { -// GraphQLSchema schema = newAnnotationsSchema().query(TestObjectBridgMethod.class).build(); -// -// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{id}", new TestObjectBridgMethod()); -// assertEquals(((Map) result.getData()).get("id"), 1L); -// } -// -// public interface Iface { -// @GraphQLField -// default String field() { -// return "field"; -// } -// } -// -// public static class IfaceImpl implements Iface { -// } -// -// @Test -// public void interfaceInheritance() { -// GraphQLObjectType object = this.graphQLAnnotations.object(IfaceImpl.class); -// assertEquals(object.getFieldDefinitions().size(), 1); -// assertEquals(object.getFieldDefinition("field").getType(), GraphQLString); -// -// } -// -// private static class TestAccessors { -// @GraphQLField -// public String getValue() { -// return "hello"; -// } -// -// @GraphQLField -// public String setAnotherValue(String s) { -// return s; -// } -// } -// -// @Test -// public void accessors() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestAccessors.class); -// List fields = object.getFieldDefinitions(); -// assertEquals(fields.size(), 2); -// fields.sort(Comparator.comparing(GraphQLFieldDefinition::getName)); -// -// assertEquals(fields.get(0).getName(), "getValue"); -// assertEquals(fields.get(1).getName(), "setAnotherValue"); -// } -// -// -// @Test -// public void defaults() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestDefaults.class); -// assertEquals(object.getName(), "TestDefaults"); -// assertNull(object.getDescription()); -// } -// -// public static class TestField { -// @GraphQLField -// @GraphQLName("field1") -// public String field = "test"; -// } -// -// public static class PrivateTestField { -// -// @GraphQLField -// @GraphQLName("field1") -// private String field = "test"; -// -// public String getField() { -// return field; -// } -// -// public void setField(String field) { -// this.field = field; -// } -// -// @GraphQLField -// private String field2 = "test"; -// -// public String field2() { -// return field2; -// } -// -// public PrivateTestField sfield2(String field2) { -// this.field2 = field2; -// return this; -// } -// -// @GraphQLField -// private boolean booleanField = true; -// -// public boolean isBooleanField() { -// return booleanField; -// } -// -// public void setBooleanField(boolean booleanField) { -// this.booleanField = booleanField; -// } -// } -// -// @Test -// public void field() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestField.class); -// List fields = object.getFieldDefinitions(); -// assertEquals(fields.size(), 1); -// assertEquals(fields.get(0).getName(), "field1"); -// } -// -// private static class OnMethodTest { -// private String value; -// -// @GraphQLField -// public String getValue() { -// return value; -// } -// } -// -// @Test -// public void onMethod() { -// GraphQLObjectType object = this.graphQLAnnotations.object(OnMethodTest.class); -// List fields = object.getFieldDefinitions(); -// assertEquals(fields.size(), 1); -// assertEquals(fields.get(0).getName(), "getValue"); -// } -// -// public static class TestFetcher implements DataFetcher { -// -// @Override -// public Object get(DataFetchingEnvironment environment) { -// return "test"; -// } -// } -// -// private static class TestDataFetcher { -// -// @GraphQLField -// @GraphQLDataFetcher(TestFetcher.class) -// public String field; -// -// @GraphQLField -// @GraphQLDataFetcher(TestFetcher.class) -// public String someField() { -// return "not test"; -// } -// -// } -// -// @Test -// public void dataFetcher() { -// GraphQLSchema schema = newAnnotationsSchema().query(TestDataFetcher.class).build(); -// -// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field someField}", new TestObject()); -// assertTrue(result.getErrors().isEmpty()); -// assertEquals(((Map) result.getData()).get("field"), "test"); -// assertEquals(((Map) result.getData()).get("someField"), "test"); -// } -// -// @Test -// public void query() { -// GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); -// -// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field0}", new TestObject()); -// assertTrue(result.getErrors().isEmpty()); -// assertEquals(((Map) result.getData()).get("field0"), "test"); -// -// result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgs(a: \"test\", b: \"passed\")}", new TestObject()); -// assertTrue(result.getErrors().isEmpty()); -// assertEquals(((Map) result.getData()).get("fieldWithArgs"), "passed"); -// -// result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgsAndEnvironment(a: \"test\", b: \"passed\")}", new TestObject()); -// assertTrue(result.getErrors().isEmpty()); -// assertEquals(((Map) result.getData()).get("fieldWithArgsAndEnvironment"), "test"); -// -// } -// -// @Test -// public void queryField() { -// GraphQLSchema schema = newAnnotationsSchema().query(TestField.class).build(); -// -// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field1}", new TestField()); -// assertTrue(result.getErrors().isEmpty()); -// assertEquals(((Map) result.getData()).get("field1"), "test"); -// } -// -// @Test -// public void queryPrivateField() { -// GraphQLSchema schema = newAnnotationsSchema().query(PrivateTestField.class).build(); -// -// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field1, field2, booleanField}", new PrivateTestField()); -// assertTrue(result.getErrors().isEmpty()); -// assertEquals(((Map) result.getData()).get("field1"), "test"); -// assertEquals(((Map) result.getData()).get("field2"), "test"); -// assertTrue(((Map) result.getData()).get("booleanField")); -// -// } -// -// @Test -// public void defaultArg() { -// GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); -// -// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgs(a: \"test\")}", new TestObject()); -// assertTrue(result.getErrors().isEmpty()); -// assertEquals(((Map) result.getData()).get("fieldWithArgs"), "default"); -// } -// -// -// public static class Class1 { -// @GraphQLField -// public Class2 class2; -// @GraphQLField -// public String value; -// } -// -// public static class Class2 { -// @GraphQLField -// public Class1 class1; -// @GraphQLField -// public String value; -// } -// -// @Test -// public void recursiveTypes() { -// GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations(); -// GraphQLObjectType object = graphQLAnnotations.getObjectHandler().getGraphQLType(Class1.class, graphQLAnnotations.getContainer()); -// GraphQLSchema schema = newSchema().query(object).build(); -// -// Class1 class1 = new Class1(); -// Class2 class2 = new Class2(); -// class1.class2 = class2; -// class2.class1 = class1; -// class2.value = "hello"; -// class1.value = "bye"; -// -// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ class2 { value } }", class1); -// assertTrue(result.getErrors().isEmpty()); -// Map data = (Map) result.getData(); -// assertEquals(((Map) data.get("class2")).get("value"), "hello"); -// -// result = GraphQL.newGraphQL(schema).build().execute("{ class2 { class1 { value } } }", class1); -// assertTrue(result.getErrors().isEmpty()); -// data = (Map) result.getData(); -// Map k1 = (Map) ((Map) data.get("class2")).get("class1"); -// assertEquals(k1.get("value"), "bye"); -// -// result = GraphQL.newGraphQL(schema).build().execute("{ class2 { class1 { class2 { value } } } }", class1); -// assertTrue(result.getErrors().isEmpty()); -// } -// -// private static class TestCustomType { -// @GraphQLField -// public UUID id() { -// return UUID.randomUUID(); -// } -// } -// -// @Test -// public void customType() { -// this.graphQLAnnotations.registerTypeFunction(new UUIDTypeFunction()); -// GraphQLObjectType object = this.graphQLAnnotations.object(TestCustomType.class); -// assertEquals(object.getFieldDefinition("id").getType(), GraphQLString); -// } -// -// private static class TestCustomTypeFunction { -// @GraphQLField -// @graphql.annotations.annotationTypes.GraphQLType(UUIDTypeFunction.class) -// public UUID id() { -// return UUID.randomUUID(); -// } -// } -// -// @Test -// public void customTypeFunction() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestCustomTypeFunction.class); -// assertEquals(object.getFieldDefinition("id").getType(), GraphQLString); -// } -// -// public static class TestInputArgument { -// @GraphQLField -// public String a; -// @GraphQLField -// public int b; -// -// public TestInputArgument(@GraphQLName("a") String a, @GraphQLName("b") int b) { -// this.a = a; -// this.b = b; -// } -// } -// -// public static class TestComplexInputArgument { -// -// public Collection inputs; -// -// public TestComplexInputArgument(@GraphQLName("inputs") Collection inputs) { -// this.inputs = inputs; -// } -// -// @GraphQLField -// public Collection inputs() { -// return inputs; -// } -// -// } -// -// -// public static class TestObjectInput { -// @GraphQLField -// public String test(@GraphQLName("other") int other, @GraphQLName("arg") TestInputArgument arg) { -// return arg.a; -// } -// -// @GraphQLField -// public String test2(@GraphQLName("other") int other, @GraphQLName("arg") TestComplexInputArgument arg) { -// return arg.inputs.iterator().next().a; -// } -// } -// -// public static class InputObject { -// @GraphQLField -// int a; -// -// @GraphQLField -// int b; -// } -// -// @Test -// public void inputObjectArgument() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectInput.class); -// GraphQLArgument argument = object.getFieldDefinition("test").getArgument("arg"); -// assertTrue(argument.getType() instanceof GraphQLInputObjectType); -// assertEquals(argument.getName(), "arg"); -// -// GraphQLSchema schema = newAnnotationsSchema().query(TestObjectInput.class).build(); -// 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"); -// } -// -// @Test -// public void complexInputObjectArgument() { -// GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectInput.class); -// GraphQLArgument argument = object.getFieldDefinition("test2").getArgument("arg"); -// assertTrue(argument.getType() instanceof GraphQLInputObjectType); -// assertEquals(argument.getName(), "arg"); -// -// GraphQLSchema schema = newAnnotationsSchema().query(TestObjectInput.class).build(); -// ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ test2(arg: {inputs:[{ a:\"ok\", b:2 }]}, other:0) }", new TestObjectInput()); -// assertTrue(result.getErrors().isEmpty()); -// Map v = result.getData(); -// assertEquals(v.get("test2"), "ok"); -// } -// -// @Test -// public void inputObject() { -// GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); -// GraphQLInputObjectType type = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), -// new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). -// getInputObjectBuilder(InputObject.class, this.graphQLAnnotations.getContainer()).build(); -// -// assertEquals(type.getName(), DEFAULT_INPUT_PREFIX + InputObject.class.getSimpleName(), "Type name prefix did not match expected value"); -// assertEquals(type.getFields().size(), InputObject.class.getDeclaredFields().length); -// } -// -// @Test -// public void inputObjectCustomPrefixes() { -// GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); -// ProcessingElementsContainer container = this.graphQLAnnotations.getContainer(); -// container.setInputPrefix(""); -// container.setInputSuffix("Input"); -// GraphQLInputObjectType type = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), -// new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). -// getInputObjectBuilder(InputObject.class, this.graphQLAnnotations.getContainer()).build(); -// -// assertEquals(type.getName(), "" + InputObject.class.getSimpleName() + "Input", "Type name prefix did not match expected value"); -// assertEquals(type.getFields().size(), InputObject.class.getDeclaredFields().length); -// container.setInputPrefix(DEFAULT_INPUT_PREFIX); -// container.setInputSuffix(DEFAULT_INPUT_SUFFIX); -// } -// -// public static class UUIDTypeFunction implements TypeFunction { -// @Override -// 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"; -// } -// -// public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { -// return GraphQLString; -// } -// } -// -// public static class OptionalTest { -// @GraphQLField -// public Optional empty = Optional.empty(); -// @GraphQLField -// public Optional nonempty = Optional.of("test"); -// -// public OptionalTest() { -// } -// -// public OptionalTest(Optional empty, Optional nonempty) { -// this.empty = empty; -// this.nonempty = nonempty; -// } -// -// @Override -// public String toString() { -// return "OptionalTest" + -// "{empty=" + empty + -// ", nonempty=" + nonempty + -// '}'; -// } -// } -// -// @Test -// public void queryOptional() { -// GraphQLObjectType object = this.graphQLAnnotations.object(OptionalTest.class); -// GraphQLSchema schema = newSchema().query(object).build(); -// -// GraphQL graphQL = GraphQL.newGraphQL(schema).build(); -// ExecutionResult result = graphQL.execute("{empty, nonempty}", new OptionalTest()); -// assertTrue(result.getErrors().isEmpty()); -// Map v = (Map) result.getData(); -// assertNull(v.get("empty")); -// assertEquals(v.get("nonempty"), "test"); -// } -// -// @Test -// public void optionalInput() { -// GraphQLObjectType object = this.graphQLAnnotations.object(OptionalTest.class); -// GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); -// GraphQLInputObjectType inputObject = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), -// new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). -// getInputObjectBuilder(OptionalTest.class, this.graphQLAnnotations.getContainer()).build(); -// -// 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"); -// return new OptionalTest(Optional.ofNullable(input.get("empty")), Optional.ofNullable(input.get("nonempty"))); -// }).build()).build(); -// GraphQLSchema schema = newSchema().query(object).mutation(mutation).build(); -// -// GraphQL graphQL = GraphQL.newGraphQL(schema).build(); -// ExecutionResult result = graphQL.execute("mutation {test(input: {empty: \"test\"}) { empty nonempty } }", new OptionalTest()); -// assertTrue(result.getErrors().isEmpty()); -// Map v = (Map) ((Map) result.getData()).get("test"); -// assertEquals(v.get("empty"), "test"); -// assertNull(v.get("nonempty")); -// } -// -// public static class EnumTest { -// public enum E {A, B} -// -// @GraphQLField -// public E e; -// -// public EnumTest() { -// } -// -// public EnumTest(E e) { -// this.e = e; -// } -// -// @Override -// public String toString() { -// return "EnumTest{" + "e=" + e + '}'; -// } -// } -// -// @Test -// public void queryEnum() { -// GraphQLObjectType object = this.graphQLAnnotations.object(EnumTest.class); -// GraphQLSchema schema = newSchema().query(object).build(); -// GraphQL graphQL = GraphQL.newGraphQL(schema).build(); -// -// ExecutionResult result = graphQL.execute("{e}", new EnumTest(EnumTest.E.B)); -// assertTrue(result.getErrors().isEmpty()); -// Map v = (Map) result.getData(); -// assertEquals(v.get("e"), "B"); -// } -// -// public static class ParametrizedArgsTest { -// @GraphQLField -// public String first(List l) { -// return l.get(0); -// } -// } -// -// @Test -// public void parametrizedArg() { -// GraphQLObjectType object = this.graphQLAnnotations.object(ParametrizedArgsTest.class); -// GraphQLInputType t = object.getFieldDefinition("first").getArguments().get(0).getType(); -// assertTrue(t instanceof GraphQLList); -// assertEquals(((GraphQLList) t).getWrappedType(), Scalars.GraphQLString); -// } -// -// @GraphQLField -// public static class InheritGraphQLFieldTest { -// public String inheritedOn; -// -// @GraphQLField(false) -// public String forcedOff; -// -// public String on() { -// return "on"; -// } -// -// @GraphQLField(false) -// public String off() { -// return "off"; -// } -// -// } -// -// @Test -// public void inheritGraphQLField() { -// GraphQLObjectType object = this.graphQLAnnotations.object(InheritGraphQLFieldTest.class); -// assertNotNull(object.getFieldDefinition("on")); -// assertNull(object.getFieldDefinition("off")); -// assertNotNull(object.getFieldDefinition("inheritedOn")); -// assertNull(object.getFieldDefinition("forcedOff")); -// } -// -// -//} +/** + * 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.ExecutionResult; +import graphql.GraphQL; +import graphql.Scalars; +import graphql.annotations.annotationTypes.*; +import graphql.annotations.annotationTypes.GraphQLNonNull; +import graphql.annotations.processor.GraphQLAnnotations; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.annotations.processor.retrievers.GraphQLFieldRetriever; +import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever; +import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch; +import graphql.annotations.processor.searchAlgorithms.ParentalSearch; +import graphql.annotations.processor.typeBuilders.InputObjectBuilder; +import graphql.annotations.processor.typeFunctions.TypeFunction; +import graphql.annotations.processor.util.CodeRegistryUtil; +import graphql.schema.*; +import graphql.schema.GraphQLType; +import graphql.schema.idl.SchemaParser; +import graphql.schema.idl.SchemaPrinter; +import graphql.schema.idl.TypeDefinitionRegistry; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.lang.reflect.AnnotatedType; +import java.util.*; +import java.util.function.Supplier; + +import static graphql.Scalars.GraphQLString; +import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema; +import static graphql.annotations.processor.util.InputPropertiesUtil.DEFAULT_INPUT_PREFIX; +import static graphql.annotations.processor.util.InputPropertiesUtil.DEFAULT_INPUT_SUFFIX; +import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; +import static graphql.schema.GraphQLSchema.newSchema; +import static org.testng.Assert.*; + +@SuppressWarnings("unchecked") +public class GraphQLObjectTest { + + private GraphQLAnnotations graphQLAnnotations; + + @BeforeMethod + public void init() { + this.graphQLAnnotations = new GraphQLAnnotations(); + } + + public static class DefaultAValue implements Supplier { + + @Override + public Object get() { + return "default"; + } + } + + @GraphQLDescription("TestObject object") + @GraphQLName("TestObject") + public static class TestObject { + @GraphQLField + @GraphQLName("field0") + @GraphQLDescription("field") + public + @GraphQLNonNull + String field() { + return "test"; + } + + @GraphQLField + 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, @GraphQLName("a") String a, @GraphQLName("b") String b) { + return a; + } + + @GraphQLField + @Deprecated + public String deprecated() { + return null; + } + + @GraphQLField + @GraphQLDeprecate("Reason") + public String deprecate() { + return null; + } + + @GraphQLField + public String publicTest = "public"; + + @GraphQLField + private String privateTest = "private"; + + public String getPrivateTest() { + return privateTest; + } + + public void setPrivateTest(String privateTest) { + this.privateTest = privateTest; + } + + @GraphQLNonNull + @GraphQLField + @GraphQLName("z_nonOptionalString") + private String z; + + public String getZ() { + return z; + } + + public void setZ(String z) { + this.z = z; + } + + } + + private static class TestDefaults { + } + + private static class TestObjectNamedArgs { + @GraphQLField + public String fieldWithNamedArgs(@GraphQLName("namedArg") String firstArgument) { + return firstArgument; + } + } + + public static class TestMappedObject { + @GraphQLField + public String name; + + @GraphQLField + public String aaa; + } + + public static class TestObjectDB { + public String aaa; + + private String name; + + public String getName() { + return name; + } + + public TestObjectDB(String name, String aaa) { + this.name = name; + this.aaa = aaa; + } + } + + public static class TestQuery { + @GraphQLField + @GraphQLDataFetcher(ObjectFetcher.class) + public TestMappedObject object; + } + + public static class ObjectFetcher implements DataFetcher { + + @Override + public TestObjectDB get(DataFetchingEnvironment environment) { + return new TestObjectDB("test", "test"); + } + } + + public static class NameTest { + @GraphQLField + public Boolean isCool; + + @GraphQLField + @GraphQLPrettify + public Boolean isAwesome; + + @GraphQLField + @GraphQLPrettify + @GraphQLName("yarinnn") + public Boolean isYarin; + + @GraphQLField + public String getX() { + return "Asdf0"; + } + + @GraphQLField + @GraphQLPrettify + public String getY() { + return "asd"; + } + + @GraphQLField + @GraphQLPrettify + @GraphQLName("daniel") + public String setM() { + return "Asdf"; + } + + } + + @Test + public void objectCreation_nameIsCorrect() { + // Act + GraphQLObjectType object = this.graphQLAnnotations.object(NameTest.class); + + // Assert + assertNotNull(object.getFieldDefinition("awesome")); + assertNotNull(object.getFieldDefinition("isCool")); + assertNotNull(object.getFieldDefinition("yarinnn")); + assertNotNull(object.getFieldDefinition("getX")); + assertNotNull(object.getFieldDefinition("y")); + assertNotNull(object.getFieldDefinition("daniel")); + } + + @Test + public void fetchTestMappedObject_assertNameIsMappedFromDBObject() { + GraphQLSchema schema = newAnnotationsSchema().query(TestQuery.class).build(); + + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{object {name aaa}}"); + assertTrue(result.getErrors().isEmpty()); + assertEquals(((LinkedHashMap) (((LinkedHashMap) result.getData()).get("object"))).get("name"), "test"); + assertEquals(((LinkedHashMap) (((LinkedHashMap) result.getData()).get("object"))).get("aaa"), "test"); + } + + @Test + public void namedFields() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectNamedArgs.class); + List fields = object.getFieldDefinitions(); + assertEquals(fields.size(), 1); + + List args = fields.get(0).getArguments(); + assertEquals(args.size(), 1); + + GraphQLArgument arg = args.get(0); + assertEquals(arg.getName(), "namedArg"); + } + + @Test + public void metainformation() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); + assertEquals(object.getName(), "TestObject"); + assertEquals(object.getDescription(), "TestObject object"); + } + + @Test + public void objectClass() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); + assertTrue(object instanceof GraphQLObjectType); + } + + @Test + public void testSchema() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); + String schema = new SchemaPrinter().print(object); + assertTrue(schema.contains("type TestObject {")); + TypeDefinitionRegistry reg = new SchemaParser().parse(schema); + assertTrue(reg.getType("TestObject").isPresent()); + assertEquals(new SchemaParser().parse(schema).getType("TestObject").get().getChildren().size(), 8); + } + + @Test + public void fields() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); + List fields = object.getFieldDefinitions(); + assertEquals(fields.size(), 8); + + fields.sort((o1, o2) -> o1.getName().compareTo(o2.getName())); + + assertEquals(fields.get(2).getName(), "field0"); + assertEquals(fields.get(2).getDescription(), "field"); + assertTrue(fields.get(2).getType() instanceof graphql.schema.GraphQLNonNull); + assertEquals(((graphql.schema.GraphQLNonNull) fields.get(2).getType()).getWrappedType(), GraphQLString); + + assertEquals(fields.get(3).getName(), "fieldWithArgs"); + List args = fields.get(3).getArguments(); + assertEquals(args.size(), 2); + assertEquals(args.get(0).getName(), "a"); + assertTrue(args.get(0).getType() instanceof graphql.schema.GraphQLNonNull); + assertEquals(((graphql.schema.GraphQLNonNull) args.get(0).getType()).getWrappedType(), GraphQLString); + assertEquals(args.get(1).getName(), "b"); + assertEquals(args.get(1).getType(), GraphQLString); + assertEquals(args.get(1).getDescription(), "b"); + + assertEquals(fields.get(4).getName(), "fieldWithArgsAndEnvironment"); + args = fields.get(4).getArguments(); + assertEquals(args.size(), 2); + + assertEquals(fields.get(1).getName(), "deprecated"); + assertTrue(fields.get(1).isDeprecated()); + + assertEquals(fields.get(0).getName(), "deprecate"); + assertTrue(fields.get(0).isDeprecated()); + assertEquals(fields.get(0).getDeprecationReason(), "Reason"); + + assertEquals(fields.get(5).getName(), "privateTest"); + assertEquals(fields.get(6).getName(), "publicTest"); + + DataFetcher dataFetcher1 = CodeRegistryUtil.getDataFetcher(this.graphQLAnnotations.getContainer().getCodeRegistryBuilder(), object, fields.get(5)); + DataFetcher dataFetcher2 = CodeRegistryUtil.getDataFetcher(this.graphQLAnnotations.getContainer().getCodeRegistryBuilder(), object, fields.get(6)); + assertEquals(dataFetcher1.getClass(), PropertyDataFetcher.class); + assertEquals(dataFetcher2.getClass(), PropertyDataFetcher.class); + + assertEquals(fields.get(7).getName(), "z_nonOptionalString"); + assertTrue(fields.get(7).getType() instanceof graphql.schema.GraphQLNonNull); + } + + public static class TestObjectInherited extends TestObject { + @Override + @GraphQLName("field1") // Test overriding field + public String field() { + return "inherited"; + } + } + + @Test + public void methodInheritance() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class); + GraphQLObjectType objectInherited = this.graphQLAnnotations.object(TestObjectInherited.class); + assertEquals(object.getFieldDefinitions().size(), objectInherited.getFieldDefinitions().size()); + + GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); + GraphQLSchema schemaInherited = newAnnotationsSchema().query(TestObjectInherited.class).build(); + + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field0}", new TestObject()); + assertEquals(((Map) result.getData()).get("field0"), "test"); + GraphQL graphQL = GraphQL.newGraphQL(schemaInherited).build(); + result = graphQL.execute("{field1}", new TestObjectInherited()); + assertEquals(((Map) result.getData()).get("field1"), "inherited"); + } + + public static class TestObjectBridgMethodParent { + private final Type id; + + public TestObjectBridgMethodParent(Type id) { + this.id = id; + } + + public Type id() { + return id; + } + } + + public static class TestObjectBridgMethod extends TestObjectBridgMethodParent { + + public TestObjectBridgMethod() { + super(1L); + } + + @Override + @GraphQLField + public Long id() { + return super.id(); + } + } + + @Test + public void methodInheritanceWithGenerics() { + GraphQLSchema schema = newAnnotationsSchema().query(TestObjectBridgMethod.class).build(); + + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{id}", new TestObjectBridgMethod()); + assertEquals(((Map) result.getData()).get("id"), 1L); + } + + public interface Iface { + @GraphQLField + default String field() { + return "field"; + } + } + + public static class IfaceImpl implements Iface { + } + + @Test + public void interfaceInheritance() { + GraphQLObjectType object = this.graphQLAnnotations.object(IfaceImpl.class); + assertEquals(object.getFieldDefinitions().size(), 1); + assertEquals(object.getFieldDefinition("field").getType(), GraphQLString); + + } + + private static class TestAccessors { + @GraphQLField + public String getValue() { + return "hello"; + } + + @GraphQLField + public String setAnotherValue(String s) { + return s; + } + } + + @Test + public void accessors() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestAccessors.class); + List fields = object.getFieldDefinitions(); + assertEquals(fields.size(), 2); + fields.sort(Comparator.comparing(GraphQLFieldDefinition::getName)); + + assertEquals(fields.get(0).getName(), "getValue"); + assertEquals(fields.get(1).getName(), "setAnotherValue"); + } + + + @Test + public void defaults() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestDefaults.class); + assertEquals(object.getName(), "TestDefaults"); + assertNull(object.getDescription()); + } + + public static class TestField { + @GraphQLField + @GraphQLName("field1") + public String field = "test"; + } + + public static class PrivateTestField { + + @GraphQLField + @GraphQLName("field1") + private String field = "test"; + + public String getField() { + return field; + } + + public void setField(String field) { + this.field = field; + } + + @GraphQLField + private String field2 = "test"; + + public String field2() { + return field2; + } + + public PrivateTestField sfield2(String field2) { + this.field2 = field2; + return this; + } + + @GraphQLField + private boolean booleanField = true; + + public boolean isBooleanField() { + return booleanField; + } + + public void setBooleanField(boolean booleanField) { + this.booleanField = booleanField; + } + } + + @Test + public void field() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestField.class); + List fields = object.getFieldDefinitions(); + assertEquals(fields.size(), 1); + assertEquals(fields.get(0).getName(), "field1"); + } + + private static class OnMethodTest { + private String value; + + @GraphQLField + public String getValue() { + return value; + } + } + + @Test + public void onMethod() { + GraphQLObjectType object = this.graphQLAnnotations.object(OnMethodTest.class); + List fields = object.getFieldDefinitions(); + assertEquals(fields.size(), 1); + assertEquals(fields.get(0).getName(), "getValue"); + } + + public static class TestFetcher implements DataFetcher { + + @Override + public Object get(DataFetchingEnvironment environment) { + return "test"; + } + } + + private static class TestDataFetcher { + + @GraphQLField + @GraphQLDataFetcher(TestFetcher.class) + public String field; + + @GraphQLField + @GraphQLDataFetcher(TestFetcher.class) + public String someField() { + return "not test"; + } + + } + + @Test + public void dataFetcher() { + GraphQLSchema schema = newAnnotationsSchema().query(TestDataFetcher.class).build(); + + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field someField}", new TestObject()); + assertTrue(result.getErrors().isEmpty()); + assertEquals(((Map) result.getData()).get("field"), "test"); + assertEquals(((Map) result.getData()).get("someField"), "test"); + } + + @Test + public void query() { + GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); + + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field0}", new TestObject()); + assertTrue(result.getErrors().isEmpty()); + assertEquals(((Map) result.getData()).get("field0"), "test"); + + result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgs(a: \"test\", b: \"passed\")}", new TestObject()); + assertTrue(result.getErrors().isEmpty()); + assertEquals(((Map) result.getData()).get("fieldWithArgs"), "passed"); + + result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgsAndEnvironment(a: \"test\", b: \"passed\")}", new TestObject()); + assertTrue(result.getErrors().isEmpty()); + assertEquals(((Map) result.getData()).get("fieldWithArgsAndEnvironment"), "test"); + + } + + @Test + public void queryField() { + GraphQLSchema schema = newAnnotationsSchema().query(TestField.class).build(); + + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field1}", new TestField()); + assertTrue(result.getErrors().isEmpty()); + assertEquals(((Map) result.getData()).get("field1"), "test"); + } + + @Test + public void queryPrivateField() { + GraphQLSchema schema = newAnnotationsSchema().query(PrivateTestField.class).build(); + + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field1, field2, booleanField}", new PrivateTestField()); + assertTrue(result.getErrors().isEmpty()); + assertEquals(((Map) result.getData()).get("field1"), "test"); + assertEquals(((Map) result.getData()).get("field2"), "test"); + assertTrue(((Map) result.getData()).get("booleanField")); + + } + + @Test + public void defaultArg() { + GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); + + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgs(a: \"test\")}", new TestObject()); + assertTrue(result.getErrors().isEmpty()); + assertEquals(((Map) result.getData()).get("fieldWithArgs"), "default"); + } + + + public static class Class1 { + @GraphQLField + public Class2 class2; + @GraphQLField + public String value; + } + + public static class Class2 { + @GraphQLField + public Class1 class1; + @GraphQLField + public String value; + } + + @Test + public void recursiveTypes() { + GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations(); + GraphQLObjectType object = graphQLAnnotations.getObjectHandler().getGraphQLType(Class1.class, graphQLAnnotations.getContainer()); + GraphQLSchema schema = newSchema().query(object).build(); + + Class1 class1 = new Class1(); + Class2 class2 = new Class2(); + class1.class2 = class2; + class2.class1 = class1; + class2.value = "hello"; + class1.value = "bye"; + + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ class2 { value } }", class1); + assertTrue(result.getErrors().isEmpty()); + Map data = (Map) result.getData(); + assertEquals(((Map) data.get("class2")).get("value"), "hello"); + + result = GraphQL.newGraphQL(schema).build().execute("{ class2 { class1 { value } } }", class1); + assertTrue(result.getErrors().isEmpty()); + data = (Map) result.getData(); + Map k1 = (Map) ((Map) data.get("class2")).get("class1"); + assertEquals(k1.get("value"), "bye"); + + result = GraphQL.newGraphQL(schema).build().execute("{ class2 { class1 { class2 { value } } } }", class1); + assertTrue(result.getErrors().isEmpty()); + } + + private static class TestCustomType { + @GraphQLField + public UUID id() { + return UUID.randomUUID(); + } + } + + @Test + public void customType() { + this.graphQLAnnotations.registerTypeFunction(new UUIDTypeFunction()); + GraphQLObjectType object = this.graphQLAnnotations.object(TestCustomType.class); + assertEquals(object.getFieldDefinition("id").getType(), GraphQLString); + } + + private static class TestCustomTypeFunction { + @GraphQLField + @graphql.annotations.annotationTypes.GraphQLType(UUIDTypeFunction.class) + public UUID id() { + return UUID.randomUUID(); + } + } + + @Test + public void customTypeFunction() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestCustomTypeFunction.class); + assertEquals(object.getFieldDefinition("id").getType(), GraphQLString); + } + + public static class TestInputArgument { + @GraphQLField + public String a; + @GraphQLField + public int b; + + public TestInputArgument(@GraphQLName("a") String a, @GraphQLName("b") int b) { + this.a = a; + this.b = b; + } + } + + public static class TestComplexInputArgument { + + public Collection inputs; + + public TestComplexInputArgument(@GraphQLName("inputs") Collection inputs) { + this.inputs = inputs; + } + + @GraphQLField + public Collection inputs() { + return inputs; + } + + } + + + public static class TestObjectInput { + @GraphQLField + public String test(@GraphQLName("other") int other, @GraphQLName("arg") TestInputArgument arg) { + return arg.a; + } + + @GraphQLField + public String test2(@GraphQLName("other") int other, @GraphQLName("arg") TestComplexInputArgument arg) { + return arg.inputs.iterator().next().a; + } + } + + public static class InputObject { + @GraphQLField + int a; + + @GraphQLField + int b; + } + + @Test + public void inputObjectArgument() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectInput.class); + GraphQLArgument argument = object.getFieldDefinition("test").getArgument("arg"); + assertTrue(argument.getType() instanceof GraphQLInputObjectType); + assertEquals(argument.getName(), "arg"); + + GraphQLSchema schema = newAnnotationsSchema().query(TestObjectInput.class).build(); + 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"); + } + + @Test + public void complexInputObjectArgument() { + GraphQLObjectType object = this.graphQLAnnotations.object(TestObjectInput.class); + GraphQLArgument argument = object.getFieldDefinition("test2").getArgument("arg"); + assertTrue(argument.getType() instanceof GraphQLInputObjectType); + assertEquals(argument.getName(), "arg"); + + GraphQLSchema schema = newAnnotationsSchema().query(TestObjectInput.class).build(); + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ test2(arg: {inputs:[{ a:\"ok\", b:2 }]}, other:0) }", new TestObjectInput()); + assertTrue(result.getErrors().isEmpty()); + Map v = result.getData(); + assertEquals(v.get("test2"), "ok"); + } + + @Test + public void inputObject() { + GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); + GraphQLInputObjectType type = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), + new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). + getInputObjectBuilder(InputObject.class, this.graphQLAnnotations.getContainer()).build(); + + assertEquals(type.getName(), DEFAULT_INPUT_PREFIX + InputObject.class.getSimpleName(), "Type name prefix did not match expected value"); + assertEquals(type.getFields().size(), InputObject.class.getDeclaredFields().length); + } + + @Test + public void inputObjectCustomPrefixes() { + GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); + ProcessingElementsContainer container = this.graphQLAnnotations.getContainer(); + container.setInputPrefix(""); + container.setInputSuffix("Input"); + GraphQLInputObjectType type = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), + new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). + getInputObjectBuilder(InputObject.class, this.graphQLAnnotations.getContainer()).build(); + + assertEquals(type.getName(), "" + InputObject.class.getSimpleName() + "Input", "Type name prefix did not match expected value"); + assertEquals(type.getFields().size(), InputObject.class.getDeclaredFields().length); + container.setInputPrefix(DEFAULT_INPUT_PREFIX); + container.setInputSuffix(DEFAULT_INPUT_SUFFIX); + } + + public static class UUIDTypeFunction implements TypeFunction { + @Override + 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"; + } + + public GraphQLType buildType(boolean inputType, Class aClass, AnnotatedType annotatedType) { + return GraphQLString; + } + } + + public static class OptionalTest { + @GraphQLField + public Optional empty = Optional.empty(); + @GraphQLField + public Optional nonempty = Optional.of("test"); + + public OptionalTest() { + } + + public OptionalTest(Optional empty, Optional nonempty) { + this.empty = empty; + this.nonempty = nonempty; + } + + @Override + public String toString() { + return "OptionalTest" + + "{empty=" + empty + + ", nonempty=" + nonempty + + '}'; + } + } + + @Test + public void queryOptional() { + GraphQLObjectType object = this.graphQLAnnotations.object(OptionalTest.class); + GraphQLSchema schema = newSchema().query(object).build(); + + GraphQL graphQL = GraphQL.newGraphQL(schema).build(); + ExecutionResult result = graphQL.execute("{empty, nonempty}", new OptionalTest()); + assertTrue(result.getErrors().isEmpty()); + Map v = (Map) result.getData(); + assertNull(v.get("empty")); + assertEquals(v.get("nonempty"), "test"); + } + + @Test + public void optionalInput() { + GraphQLObjectType object = this.graphQLAnnotations.object(OptionalTest.class); + GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); + GraphQLInputObjectType inputObject = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), + new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). + getInputObjectBuilder(OptionalTest.class, this.graphQLAnnotations.getContainer()).build(); + + 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"); + return new OptionalTest(Optional.ofNullable(input.get("empty")), Optional.ofNullable(input.get("nonempty"))); + }).build()).build(); + GraphQLSchema schema = newSchema().query(object).mutation(mutation).build(); + + GraphQL graphQL = GraphQL.newGraphQL(schema).build(); + ExecutionResult result = graphQL.execute("mutation {test(input: {empty: \"test\"}) { empty nonempty } }", new OptionalTest()); + assertTrue(result.getErrors().isEmpty()); + Map v = (Map) ((Map) result.getData()).get("test"); + assertEquals(v.get("empty"), "test"); + assertNull(v.get("nonempty")); + } + + public static class EnumTest { + public enum E {A, B} + + @GraphQLField + public E e; + + public EnumTest() { + } + + public EnumTest(E e) { + this.e = e; + } + + @Override + public String toString() { + return "EnumTest{" + "e=" + e + '}'; + } + } + + @Test + public void queryEnum() { + GraphQLObjectType object = this.graphQLAnnotations.object(EnumTest.class); + GraphQLSchema schema = newSchema().query(object).build(); + GraphQL graphQL = GraphQL.newGraphQL(schema).build(); + + ExecutionResult result = graphQL.execute("{e}", new EnumTest(EnumTest.E.B)); + assertTrue(result.getErrors().isEmpty()); + Map v = (Map) result.getData(); + assertEquals(v.get("e"), "B"); + } + + public static class ParametrizedArgsTest { + @GraphQLField + public String first(List l) { + return l.get(0); + } + } + + @Test + public void parametrizedArg() { + GraphQLObjectType object = this.graphQLAnnotations.object(ParametrizedArgsTest.class); + GraphQLInputType t = object.getFieldDefinition("first").getArguments().get(0).getType(); + assertTrue(t instanceof GraphQLList); + assertEquals(((GraphQLList) t).getWrappedType(), Scalars.GraphQLString); + } + + @GraphQLField + public static class InheritGraphQLFieldTest { + public String inheritedOn; + + @GraphQLField(false) + public String forcedOff; + + public String on() { + return "on"; + } + + @GraphQLField(false) + public String off() { + return "off"; + } + + } + + @Test + public void inheritGraphQLField() { + GraphQLObjectType object = this.graphQLAnnotations.object(InheritGraphQLFieldTest.class); + assertNotNull(object.getFieldDefinition("on")); + assertNull(object.getFieldDefinition("off")); + assertNotNull(object.getFieldDefinition("inheritedOn")); + assertNull(object.getFieldDefinition("forcedOff")); + } + + +} diff --git a/src/test/java/graphql/annotations/directives/DirectiveSchemaVisitorTest.java b/src/test/java/graphql/annotations/directives/DirectiveSchemaVisitorTest.java new file mode 100644 index 00000000..5531536b --- /dev/null +++ b/src/test/java/graphql/annotations/directives/DirectiveSchemaVisitorTest.java @@ -0,0 +1,149 @@ +package graphql.annotations.directives; + +import graphql.introspection.Introspection; +import graphql.schema.*; +import graphql.util.TraversalControl; +import graphql.util.TraverserContext; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.*; +import static org.testng.AssertJUnit.assertEquals; + +public class DirectiveSchemaVisitorTest { + private DirectiveSchemaVisitor directiveSchemaVisitor; + private GraphQLCodeRegistry.Builder codeRegistryBuilder; + private HashMap directiveWiringMap = new HashMap<>(); + private AnnotationsDirectiveWiring wiringMock; + private TreeTransformerUtilWrapper transformerUtilWrapper; + + @BeforeMethod + public void setUp() { + codeRegistryBuilder = mock(GraphQLCodeRegistry.Builder.class); + wiringMock = mock(AnnotationsDirectiveWiring.class); + transformerUtilWrapper = mock(TreeTransformerUtilWrapper.class); + directiveWiringMap.put("upper", wiringMock); + directiveWiringMap.put("suffix", wiringMock); + directiveWiringMap.put("noWiringMock", null); + directiveSchemaVisitor = new DirectiveSchemaVisitor(directiveWiringMap, codeRegistryBuilder, transformerUtilWrapper); + } + + + @Test + public void visitGraphQLArgument_hasDirectives_wiringFunctionIsCalledAndNodeChanged() { + // Arrange + GraphQLArgument argument = mock(GraphQLArgument.class); + List directivesOnType = new ArrayList<>(); + GraphQLDirective directiveMock = mock(GraphQLDirective.class); + when(directiveMock.validLocations()).thenReturn(EnumSet.of(Introspection.DirectiveLocation.ARGUMENT_DEFINITION)); + when(directiveMock.getName()).thenReturn("upper"); + directivesOnType.add(directiveMock); + TraverserContext context = mock(TraverserContext.class); + when(argument.getDirectives()).thenReturn(directivesOnType); + // Act + directiveSchemaVisitor.visitGraphQLArgument(argument, context); + + // Assert + verify(wiringMock).onArgument(any()); + verify(transformerUtilWrapper).changeNode(eq(context), any()); + } + + @Test + public void visitGraphQLArgument_noDirectives_returnsContinue() { + // Arrange + GraphQLArgument argument = mock(GraphQLArgument.class); + TraverserContext context = mock(TraverserContext.class); + when(argument.getDirectives()).thenReturn(new ArrayList<>()); + // Act + TraversalControl traversalControl = directiveSchemaVisitor.visitGraphQLArgument(argument, context); + + // Assert + verifyZeroInteractions(wiringMock); + verifyZeroInteractions(transformerUtilWrapper); + assertEquals(traversalControl, TraversalControl.CONTINUE); + } + + @Test + public void visitGraphQLArgument_noWiringFunction_changedToSameNode() { + // Arrange + GraphQLArgument argument = mock(GraphQLArgument.class); + List directivesOnType = new ArrayList<>(); + GraphQLDirective directiveMock = mock(GraphQLDirective.class); + when(directiveMock.validLocations()).thenReturn(EnumSet.of(Introspection.DirectiveLocation.ARGUMENT_DEFINITION)); + when(directiveMock.getName()).thenReturn("noWiringMock"); + directivesOnType.add(directiveMock); + TraverserContext context = mock(TraverserContext.class); + when(argument.getDirectives()).thenReturn(directivesOnType); + + // Act + directiveSchemaVisitor.visitGraphQLArgument(argument, context); + + // Assert + verifyZeroInteractions(wiringMock); + verify(transformerUtilWrapper).changeNode(eq(context), eq(argument)); + } + + //// + + @Test + public void visitGraphQLFieldDefinition_hasDirectives_wiringFunctionIsCalledAndNodeChanged() { + // Arrange + GraphQLFieldDefinition type = mock(GraphQLFieldDefinition.class); + List directivesOnType = new ArrayList<>(); + GraphQLDirective directiveMock = mock(GraphQLDirective.class); + when(directiveMock.validLocations()).thenReturn(EnumSet.of(Introspection.DirectiveLocation.FIELD_DEFINITION)); + when(directiveMock.getName()).thenReturn("upper"); + directivesOnType.add(directiveMock); + TraverserContext context = mock(TraverserContext.class); + when(type.getDirectives()).thenReturn(directivesOnType); + // Act + directiveSchemaVisitor.visitGraphQLFieldDefinition(type, context); + + // Assert + verify(wiringMock).onField(any()); + verify(transformerUtilWrapper).changeNode(eq(context), any()); + } + + @Test + public void visitGraphQLFieldDefinition_noDirectives_returnsContinue() { + // Arrange + GraphQLFieldDefinition type = mock(GraphQLFieldDefinition.class); + TraverserContext context = mock(TraverserContext.class); + when(type.getDirectives()).thenReturn(new ArrayList<>()); + // Act + TraversalControl traversalControl = directiveSchemaVisitor.visitGraphQLFieldDefinition(type, context); + + // Assert + verifyZeroInteractions(wiringMock); + verifyZeroInteractions(transformerUtilWrapper); + assertEquals(traversalControl, TraversalControl.CONTINUE); + } + + @Test + public void visitGraphQLFieldDefinition_noWiringFunction_changedToSameNode() { + // Arrange + GraphQLFieldDefinition type = mock(GraphQLFieldDefinition.class); + List directivesOnType = new ArrayList<>(); + GraphQLDirective directiveMock = mock(GraphQLDirective.class); + when(directiveMock.validLocations()).thenReturn(EnumSet.of(Introspection.DirectiveLocation.FIELD_DEFINITION)); + when(directiveMock.getName()).thenReturn("noWiringMock"); + directivesOnType.add(directiveMock); + TraverserContext context = mock(TraverserContext.class); + when(type.getDirectives()).thenReturn(directivesOnType); + + // Act + directiveSchemaVisitor.visitGraphQLFieldDefinition(type, context); + + // Assert + verifyZeroInteractions(wiringMock); + verify(transformerUtilWrapper).changeNode(eq(context), eq(type)); + } + +} From 8cf94f9ed8f00d9af2f3537a87a78c9a93c14b16 Mon Sep 17 00:00:00 2001 From: Yarin Date: Sun, 19 Jan 2020 02:14:32 +0200 Subject: [PATCH 06/14] fixes: fix license --- LICENSE | 2 -- .../annotations/AnnotationsSchemaCreator.java | 8 +++----- .../directives/DirectiveSchemaVisitor.java | 12 ++++++++++++ .../directives/TreeTransformerUtilWrapper.java | 12 ++++++++++++ .../processor/retrievers/GraphQLFieldRetriever.java | 8 +++----- .../processor/retrievers/GraphQLTypeRetriever.java | 8 +++----- .../retrievers/fieldBuilders/ArgumentBuilder.java | 8 +++----- .../annotations/processor/util/CodeRegistryUtil.java | 8 +++----- .../processor/util/GraphQLTypeNameResolver.java | 12 ++++++++++++ .../GraphQLDirectivesViaClassDefinitionTest.java | 8 +++----- .../java/graphql/annotations/GraphQLInputTest.java | 8 +++----- .../graphql/annotations/GraphQLInterfaceTest.java | 8 +++----- .../graphql/annotations/SchemaTransformerTest.java | 12 ++++++++++++ .../connection/GraphQLConnectionTest.java | 8 +++----- .../directives/DirectiveSchemaVisitorTest.java | 12 ++++++++++++ .../annotations/directives/DirectiveWirerTest.java | 12 ++++++++++++ 16 files changed, 99 insertions(+), 47 deletions(-) diff --git a/LICENSE b/LICENSE index f9f351c0..3b5b5f7e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,3 @@ -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 diff --git a/src/main/java/graphql/annotations/AnnotationsSchemaCreator.java b/src/main/java/graphql/annotations/AnnotationsSchemaCreator.java index 5d03f01d..e9fb1aa9 100644 --- a/src/main/java/graphql/annotations/AnnotationsSchemaCreator.java +++ b/src/main/java/graphql/annotations/AnnotationsSchemaCreator.java @@ -1,12 +1,10 @@ /** - * 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/directives/DirectiveSchemaVisitor.java b/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java index 89a30b49..07aba3cc 100644 --- a/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java +++ b/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java @@ -1,3 +1,15 @@ +/** + * 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.directives; import graphql.introspection.Introspection; diff --git a/src/main/java/graphql/annotations/directives/TreeTransformerUtilWrapper.java b/src/main/java/graphql/annotations/directives/TreeTransformerUtilWrapper.java index ebdfd123..6628ad95 100644 --- a/src/main/java/graphql/annotations/directives/TreeTransformerUtilWrapper.java +++ b/src/main/java/graphql/annotations/directives/TreeTransformerUtilWrapper.java @@ -1,3 +1,15 @@ +/** + * 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.directives; import graphql.util.TraversalControl; diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java index ad954b47..0fb4ba90 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java @@ -1,12 +1,10 @@ /** - * 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/GraphQLTypeRetriever.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java index 7e85f567..3bc15637 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java @@ -1,12 +1,10 @@ /** - * 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 541262c7..08e5a495 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java @@ -1,12 +1,10 @@ /** - * 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/util/CodeRegistryUtil.java b/src/main/java/graphql/annotations/processor/util/CodeRegistryUtil.java index 9c587797..77d9c29b 100644 --- a/src/main/java/graphql/annotations/processor/util/CodeRegistryUtil.java +++ b/src/main/java/graphql/annotations/processor/util/CodeRegistryUtil.java @@ -1,12 +1,10 @@ /** - * 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/util/GraphQLTypeNameResolver.java b/src/main/java/graphql/annotations/processor/util/GraphQLTypeNameResolver.java index 34f555e4..13051876 100644 --- a/src/main/java/graphql/annotations/processor/util/GraphQLTypeNameResolver.java +++ b/src/main/java/graphql/annotations/processor/util/GraphQLTypeNameResolver.java @@ -1,3 +1,15 @@ +/** + * 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.schema.*; diff --git a/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.java b/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.java index 272da2e1..30ff45ba 100644 --- a/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.java +++ b/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.java @@ -1,12 +1,10 @@ /** - * 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/GraphQLInputTest.java b/src/test/java/graphql/annotations/GraphQLInputTest.java index e7d84221..3561a7b0 100644 --- a/src/test/java/graphql/annotations/GraphQLInputTest.java +++ b/src/test/java/graphql/annotations/GraphQLInputTest.java @@ -1,12 +1,10 @@ /** - * 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/GraphQLInterfaceTest.java b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java index f69af33a..00c0ae57 100644 --- a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java +++ b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java @@ -1,12 +1,10 @@ /** - * 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/SchemaTransformerTest.java b/src/test/java/graphql/annotations/SchemaTransformerTest.java index 32ba3a64..9cb241fa 100644 --- a/src/test/java/graphql/annotations/SchemaTransformerTest.java +++ b/src/test/java/graphql/annotations/SchemaTransformerTest.java @@ -1,3 +1,15 @@ +/** + * 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.annotationTypes.GraphQLField; diff --git a/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java b/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java index 1e47182e..1d11d455 100644 --- a/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java +++ b/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java @@ -1,12 +1,10 @@ /** - * 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/directives/DirectiveSchemaVisitorTest.java b/src/test/java/graphql/annotations/directives/DirectiveSchemaVisitorTest.java index 5531536b..0c5fd39f 100644 --- a/src/test/java/graphql/annotations/directives/DirectiveSchemaVisitorTest.java +++ b/src/test/java/graphql/annotations/directives/DirectiveSchemaVisitorTest.java @@ -1,3 +1,15 @@ +/** + * 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.directives; import graphql.introspection.Introspection; diff --git a/src/test/java/graphql/annotations/directives/DirectiveWirerTest.java b/src/test/java/graphql/annotations/directives/DirectiveWirerTest.java index 7c7f319d..6c20726f 100644 --- a/src/test/java/graphql/annotations/directives/DirectiveWirerTest.java +++ b/src/test/java/graphql/annotations/directives/DirectiveWirerTest.java @@ -1,3 +1,15 @@ +/** + * 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 + */ ///** // * Copyright 2016 Yurii Rashkovskii // * From 1d889b3b284ebaa2473c5d57312e3167d8b10d84 Mon Sep 17 00:00:00 2001 From: Yarin V Date: Fri, 24 Jan 2020 17:15:30 +0200 Subject: [PATCH 07/14] Delete .travis.yml --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9bcf9994..00000000 --- a/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: java -jdk: - - oraclejdk8 From e6fd2c3ba05cb6fac49b1338f7c588f1917ed191 Mon Sep 17 00:00:00 2001 From: Yarin Date: Fri, 24 Jan 2020 17:18:59 +0200 Subject: [PATCH 08/14] remove directivewirertest --- .../directives/DirectiveWirerTest.java | 529 ------------------ 1 file changed, 529 deletions(-) delete mode 100644 src/test/java/graphql/annotations/directives/DirectiveWirerTest.java diff --git a/src/test/java/graphql/annotations/directives/DirectiveWirerTest.java b/src/test/java/graphql/annotations/directives/DirectiveWirerTest.java deleted file mode 100644 index 6c20726f..00000000 --- a/src/test/java/graphql/annotations/directives/DirectiveWirerTest.java +++ /dev/null @@ -1,529 +0,0 @@ -/** - * 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 - */ -///** -// * 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.directives; -// -//import graphql.TypeResolutionEnvironment; -//import graphql.introspection.Introspection; -//import graphql.schema.*; -//import org.testng.annotations.BeforeMethod; -//import org.testng.annotations.Test; -// -//import java.util.HashMap; -// -//import static graphql.Scalars.GraphQLString; -//import static graphql.schema.GraphQLDirective.newDirective; -//import static org.mockito.Mockito.*; -// -//public class DirectiveWirerTest { -// -// private DirectiveWirer directiveWirer; -// private String parentName = "parent"; -// private GraphQLCodeRegistry.Builder builder; -// -// @BeforeMethod -// public void setUp() throws Exception { -// directiveWirer = new DirectiveWirer(); -// builder = mock(GraphQLCodeRegistry.Builder.class); -// } -// -// // GraphQLFieldDefinition -// -// @Test -// public void wireFieldDefinition_validLocations_correctMethodIsCalled() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// AnnotationsDirectiveWiring lowerWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLFieldDefinition directiveContainer = GraphQLFieldDefinition.newFieldDefinition().name("bla") -// .type(GraphQLString).build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, -// directiveContainer.getDirective("upperCase"), parentName, builder); -// AnnotationsWiringEnvironmentImpl lowerCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, -// directiveContainer.getDirective("lowerCase"), parentName, builder); -// -// when(upperWiring.onField(upperCaseEnv)).thenReturn(directiveContainer); -// when(lowerWiring.onField(lowerCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.FIELD_DEFINITION).build(); -// GraphQLDirective lowerCase = newDirective().name("lowerCase").validLocations(Introspection.DirectiveLocation.FIELD).build(); -// map.put(upperCase, upperWiring); -// map.put(lowerCase, lowerWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// -// // Assert -// -// verify(upperWiring).onField(upperCaseEnv); -// verify(lowerWiring).onField(lowerCaseEnv); -// } -// -// @Test(expectedExceptions = InvalidDirectiveLocationException.class) -// public void wireFieldDefinition_invalidLocations_exceptionIsThrown() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLFieldDefinition directiveContainer = GraphQLFieldDefinition.newFieldDefinition().name("bla") -// .type(GraphQLString).build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, -// directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onField(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ENUM).build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// } -// -// // GraphQLObjectType -// -// @Test -// public void wireGraphQLObjectType_validLocations_correctMethodIsCalled() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLObjectType directiveContainer = GraphQLObjectType.newObject().name("asdf").build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, -// directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onObject(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.OBJECT).build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// -// // Assert -// -// verify(upperWiring).onObject(upperCaseEnv); -// } -// -// @Test(expectedExceptions = InvalidDirectiveLocationException.class) -// public void wireGraphQLObjectType_invalidLocations_exceptionIsThrown() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLObjectType directiveContainer = GraphQLObjectType.newObject().name("asdf00").build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, -// directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onObject(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// } -// -// // GraphQLArgument -// -// @Test -// public void wireGraphQLArgument_validLocations_correctMethodIsCalled() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLArgument directiveContainer = GraphQLArgument.newArgument().name("asdf").type(GraphQLString).build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, -// directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onArgument(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ARGUMENT_DEFINITION).build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// -// // Assert -// -// verify(upperWiring).onArgument(upperCaseEnv); -// } -// -// @Test(expectedExceptions = InvalidDirectiveLocationException.class) -// public void wireGraphQLArgument_invalidLocations_exceptionIsThrown() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLArgument directiveContainer = GraphQLArgument.newArgument().name("asdf0").type(GraphQLString).build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, -// directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onArgument(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// } -// -// // GraphQLInterfaceType -// -// @Test -// public void wireGraphQLInterfaceType_validLocations_correctMethodIsCalled() { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLInterfaceType directiveContainer = GraphQLInterfaceType.newInterface().name("asdf").build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, -// directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onInterface(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.INTERFACE).build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// -// // Assert -// -// verify(upperWiring).onInterface(upperCaseEnv); -// } -// -// @Test(expectedExceptions = InvalidDirectiveLocationException.class) -// public void wireGraphQLInterfaceType_invalidLocations_exceptionIsThrown() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLInterfaceType directiveContainer = GraphQLInterfaceType.newInterface().name("asdf").build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, -// directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onInterface(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// } -// -// // GraphQLUnionType -// -// @Test -// public void wireGraphQLUnionType_validLocations_correctMethodIsCalled() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLUnionType directiveContainer = GraphQLUnionType.newUnionType().name("asdf") -// .possibleType(GraphQLObjectType.newObject().name("Asdfaaaa").build()).build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( -// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onUnion(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.UNION).build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// -// // Assert -// -// verify(upperWiring).onUnion(upperCaseEnv); -// } -// -// @Test(expectedExceptions = InvalidDirectiveLocationException.class) -// public void wireGraphQLUnionType_invalidLocations_exceptionIsThrown() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLUnionType directiveContainer = GraphQLUnionType.newUnionType().name("asdf") -// .possibleType(GraphQLObjectType.newObject().name("Asdfaaaa").build()).build(); -// -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( -// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onUnion(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// } -// -// // GraphQLEnumType -// -// @Test -// public void wireGraphQLEnumType_validLocations_correctMethodIsCalled() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLEnumType directiveContainer = GraphQLEnumType.newEnum().name("asdf").value("asdfasdf").build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( -// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onEnum(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ENUM).build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// -// // Assert -// -// verify(upperWiring).onEnum(upperCaseEnv); -// } -// -// @Test(expectedExceptions = InvalidDirectiveLocationException.class) -// public void wireGraphQLEnumType_invalidLocations_exceptionIsThrown() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLEnumType directiveContainer = GraphQLEnumType.newEnum().name("asdf").value("asdfasdf").build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( -// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onEnum(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// } -// -// // GraphQLEnumValueDefinition -// -// @Test -// public void wireGraphQLEnumValueDefinition_validLocations_correctMethodIsCalled() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLEnumValueDefinition directiveContainer = GraphQLEnumValueDefinition.newEnumValueDefinition().name("asdf").build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, -// directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onEnumValue(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.ENUM_VALUE).build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// -// // Assert -// -// verify(upperWiring).onEnumValue(upperCaseEnv); -// } -// -// @Test(expectedExceptions = InvalidDirectiveLocationException.class) -// public void wireGraphQLEnumValueDefinition_invalidLocations_exceptionIsThrown() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLEnumValueDefinition directiveContainer = GraphQLEnumValueDefinition.newEnumValueDefinition().name("asdf").build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( -// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onEnumValue(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// } -// -// // GraphQLScalarType -// -// @Test -// public void wireGraphQLScalarType_validLocations_correctMethodIsCalled() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLScalarType directiveContainer = GraphQLString; -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( -// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onScalar(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.SCALAR).build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// -// // Assert -// -// verify(upperWiring).onScalar(upperCaseEnv); -// } -// -// @Test(expectedExceptions = InvalidDirectiveLocationException.class) -// public void wireGraphQLScalarType_invalidLocations_exceptionIsThrown() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLScalarType directiveContainer = GraphQLString; -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( -// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onScalar(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// } -// -// // GraphQLInputObjectType -// -// @Test -// public void wireGraphQLInputObjectType_validLocations_correctMethodIsCalled() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLInputObjectType directiveContainer = GraphQLInputObjectType.newInputObject().name("asdf") -// .build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( -// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onInputObjectType(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.INPUT_OBJECT).build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// -// // Assert -// -// verify(upperWiring).onInputObjectType(upperCaseEnv); -// } -// -// @Test(expectedExceptions = InvalidDirectiveLocationException.class) -// public void wireGraphQLInputObjectType_invalidLocations_exceptionIsThrown() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLInputObjectType directiveContainer = GraphQLInputObjectType.newInputObject().name("asdf") -// .build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( -// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onInputObjectType(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// } -// -// // GraphQLInputObjectField -// -// @Test -// public void wireGraphQLInputObjectField_validLocations_correctMethodIsCalled() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLInputObjectField directiveContainer = GraphQLInputObjectField.newInputObjectField().name("asdf") -// .type(GraphQLInputObjectType.newInputObject().name("dfdf").build()).build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl( -// directiveContainer, directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onInputObjectField(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION).build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// -// // Assert -// -// verify(upperWiring).onInputObjectField(upperCaseEnv); -// } -// -// @Test(expectedExceptions = InvalidDirectiveLocationException.class) -// public void wireGraphQLInputObjectField_invalidLocations_exceptionIsThrown() throws Exception { -// // Arrange -// AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); -// -// GraphQLInputObjectField directiveContainer = GraphQLInputObjectField.newInputObjectField().name("asdf") -// .type(GraphQLInputObjectType.newInputObject().name("dfdf").build()).build(); -// -// AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, -// directiveContainer.getDirective("upperCase"), parentName, builder); -// -// when(upperWiring.onInputObjectField(upperCaseEnv)).thenReturn(directiveContainer); -// -// HashMap map = new HashMap<>(); -// GraphQLDirective upperCase = newDirective().name("upperCase").build(); -// map.put(upperCase, upperWiring); -// -// // Act -// directiveWirer.wire(directiveContainer, map, builder, parentName); -// } -// -//} From 95b6964cb7cb84f1091e396e517f40ba5f037377 Mon Sep 17 00:00:00 2001 From: Yarin Date: Fri, 24 Jan 2020 17:28:04 +0200 Subject: [PATCH 09/14] change to throw exception --- .../annotations/directives/DirectiveSchemaVisitor.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java b/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java index 07aba3cc..eb13ecef 100644 --- a/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java +++ b/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java @@ -2,9 +2,9 @@ * 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. @@ -131,8 +131,7 @@ private TraversalControl visitGraphQLType(Class Date: Fri, 24 Jan 2020 17:30:54 +0200 Subject: [PATCH 10/14] fix license --- .../directives/DirectiveSchemaVisitor.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java b/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java index eb13ecef..9a7a7346 100644 --- a/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java +++ b/src/main/java/graphql/annotations/directives/DirectiveSchemaVisitor.java @@ -1,3 +1,15 @@ +/** + * 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 + */ /** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 27839dc5fcef2ee922753ac8e125ac458deb789d Mon Sep 17 00:00:00 2001 From: Yarin Date: Fri, 24 Jan 2020 17:33:37 +0200 Subject: [PATCH 11/14] remove unnecessary tests --- .../annotations/SchemaTransformerTest.java | 123 ------------------ 1 file changed, 123 deletions(-) delete mode 100644 src/test/java/graphql/annotations/SchemaTransformerTest.java diff --git a/src/test/java/graphql/annotations/SchemaTransformerTest.java b/src/test/java/graphql/annotations/SchemaTransformerTest.java deleted file mode 100644 index 9cb241fa..00000000 --- a/src/test/java/graphql/annotations/SchemaTransformerTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * 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.annotationTypes.GraphQLField; -import graphql.annotations.annotationTypes.GraphQLInvokeDetached; -import graphql.schema.*; -import graphql.util.TraversalControl; -import graphql.util.TraverserContext; -import org.testng.annotations.Test; - -import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema; -import static graphql.util.TreeTransformerUtil.changeNode; - -public class SchemaTransformerTest { - - class A { - @GraphQLField - String x; - } - - class Query { - @GraphQLField - @GraphQLInvokeDetached - public A getA() { - return new A(); - } - } - - class Visitor implements GraphQLTypeVisitor { - @Override - public TraversalControl visitGraphQLArgument(GraphQLArgument node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLInterfaceType(GraphQLInterfaceType node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLEnumType(GraphQLEnumType node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLEnumValueDefinition(GraphQLEnumValueDefinition node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLFieldDefinition(GraphQLFieldDefinition node, TraverserContext context) { - if (node.getName().equals("x")) { - GraphQLFieldDefinition y = node.transform(builder -> builder.name("y")); - return changeNode(context, y); - } - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLDirective(GraphQLDirective node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLInputObjectField(GraphQLInputObjectField node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLInputObjectType(GraphQLInputObjectType node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLList(GraphQLList node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLNonNull(GraphQLNonNull node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLObjectType(GraphQLObjectType node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLScalarType(GraphQLScalarType node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLTypeReference(GraphQLTypeReference node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - - @Override - public TraversalControl visitGraphQLUnionType(GraphQLUnionType node, TraverserContext context) { - return TraversalControl.CONTINUE; - } - } - - @Test - public void test() { - GraphQLSchema schema = newAnnotationsSchema().query(Query.class).build(); - SchemaTransformer schemaTransformer = new SchemaTransformer(); - GraphQLSchema transformedSchema = schemaTransformer.transform(schema, new Visitor()); - System.out.println(transformedSchema.toString()); - } -} From 2038e9cebc94c50903bca16f15bfe1a9bda319e5 Mon Sep 17 00:00:00 2001 From: Yarin Date: Fri, 24 Jan 2020 17:35:25 +0200 Subject: [PATCH 12/14] fix naming --- .../directives/AnnotationsWiringEnvironmentImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironmentImpl.java b/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironmentImpl.java index 576fba59..f4fa0830 100644 --- a/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironmentImpl.java +++ b/src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironmentImpl.java @@ -26,10 +26,10 @@ public class AnnotationsWiringEnvironmentImpl implements AnnotationsWiringEnviro private GraphQLCodeRegistry.Builder codeRegistryBuilder; public AnnotationsWiringEnvironmentImpl(GraphQLDirectiveContainer element, GraphQLDirective directive, - GraphQLSchemaElement parentELement, GraphQLCodeRegistry.Builder codeRegistryBuilder) { + GraphQLSchemaElement parentElement, GraphQLCodeRegistry.Builder codeRegistryBuilder) { this.element = element; this.directive = directive; - this.parentElement = parentELement; + this.parentElement = parentElement; this.codeRegistryBuilder = codeRegistryBuilder; } From c067d0b028f8be0478b233d11143e4ef12b38ab1 Mon Sep 17 00:00:00 2001 From: Yarin Date: Sun, 26 Jan 2020 19:45:09 +0200 Subject: [PATCH 13/14] v8.0 release --- README.md | 4 ++-- gradle.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 831b38ae..fe77eb74 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ If you would like to use a tool that creates a graphql spring boot server using ```groovy dependencies { - compile "io.github.graphql-java:graphql-java-annotations:7.2.1" + compile "io.github.graphql-java:graphql-java-annotations:8.0" } ``` @@ -47,7 +47,7 @@ dependencies { io.github.graphql-java graphql-java-annotations - 7.2.1 + 8.0 ``` diff --git a/gradle.properties b/gradle.properties index 8d880e2f..a37d79a4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,4 +5,4 @@ org.gradle.daemon=true org.gradle.parallel=true org.gradle.jvmargs=-Dfile.encoding=UTF-8 -version = 7.2.1 +version = 8.0 From 68b966f8e8eb22928d6e36470a9b0913f67f922c Mon Sep 17 00:00:00 2001 From: Yarin Date: Sun, 26 Jan 2020 19:58:30 +0200 Subject: [PATCH 14/14] logo fix --- README.md | 2 +- graphql-annotations.png | Bin 0 -> 8118 bytes polaris-iconsmalredl.png | Bin 10830 -> 0 bytes 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 graphql-annotations.png delete mode 100644 polaris-iconsmalredl.png diff --git a/README.md b/README.md index fe77eb74..541d7414 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![logo](polaris-iconsmalredl.png?raw=true) +![logo](graphql-annotations.png?raw=true) # GraphQL-Java Annotations [![Build Status](https://travis-ci.org/graphql-java/graphql-java-annotations.svg?branch=master)](https://travis-ci.org/graphql-java/graphql-java-annotations) [![Maven Central](https://img.shields.io/maven-central/v/io.github.graphql-java/graphql-java-annotations.svg?maxAge=3000)]() diff --git a/graphql-annotations.png b/graphql-annotations.png new file mode 100644 index 0000000000000000000000000000000000000000..e1512908805f887c6ebbed694259a3c9569aa0c7 GIT binary patch literal 8118 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 literal 0 HcmV?d00001 diff --git a/polaris-iconsmalredl.png b/polaris-iconsmalredl.png deleted file mode 100644 index a17b9f199f275a7a892e587dcfb42d86c67e7227..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10830 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 Y09I^n*SPrC+yDRo07*qoM6N<$g6Dd~{{R30