diff --git a/build.gradle b/build.gradle index 537f2edc..d31201c8 100644 --- a/build.gradle +++ b/build.gradle @@ -54,9 +54,9 @@ gradle.projectsEvaluated { dependencies { compile 'javax.validation:validation-api:1.1.0.Final' - compile 'com.graphql-java:graphql-java:17.4' - compile 'com.graphql-java:graphql-java-extended-scalars:17.0' - + compile 'com.graphql-java:graphql-java:20.4' + compile 'com.graphql-java:graphql-java-extended-scalars:20.2' + compile 'javax.xml.bind:jaxb-api:2.3.1' // OSGi compileOnly 'org.osgi:org.osgi.core:6.0.0' diff --git a/gradle.properties b/gradle.properties index 966851e1..6169225c 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 = 9.1 +version = 20.3 diff --git a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DirectivesBuilder.java b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DirectivesBuilder.java index 0082f5f5..f17810af 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DirectivesBuilder.java +++ b/src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DirectivesBuilder.java @@ -14,6 +14,14 @@ */ package graphql.annotations.processor.retrievers.fieldBuilders; +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + import graphql.annotations.annotationTypes.directives.activation.GraphQLDirectives; import graphql.annotations.processor.ProcessingElementsContainer; import graphql.annotations.processor.exceptions.GraphQLAnnotationsException; @@ -23,14 +31,6 @@ import graphql.schema.GraphQLScalarType; import graphql.schema.GraphQLType; -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - import static graphql.schema.GraphQLDirective.newDirective; @@ -133,13 +133,15 @@ private void transformArgument(Annotation annotation, GraphQLDirective.Builder d methods[finalI].setAccessible(true); Object argumentValue = methods[finalI].invoke(annotation); Object value; - if (graphQLArgument.getType() instanceof GraphQLScalarType) { + if ( graphQLArgument.getType() instanceof GraphQLScalarType ) + { value = ((GraphQLScalarType) graphQLArgument.getType()).getCoercing().parseValue(argumentValue); } - else{ + else + { value = argumentValue; } - builder.value(value); + builder.value( value ); } catch (Exception e) { throw new GraphQLAnnotationsException(COULD_NOT_PARSE_ARGUMENT_VALUE_TO_ARGUMENT_TYPE, e); } @@ -160,7 +162,7 @@ private void transformArgument(String[] argumentValues, GraphQLDirective.Builder try { Object value = ((GraphQLScalarType) graphQLArgument.getType()).getCoercing().parseValue(argumentValue); - builder.value(value); + builder.value( value ); } catch (Exception e) { throw new GraphQLAnnotationsException(COULD_NOT_PARSE_ARGUMENT_VALUE_TO_ARGUMENT_TYPE, e); } diff --git a/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java b/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java index 233a58df..3b172424 100644 --- a/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java +++ b/src/test/java/graphql/annotations/GraphQLDataFetcherTest.java @@ -22,12 +22,14 @@ import graphql.annotations.processor.GraphQLAnnotations; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; +import graphql.schema.GraphQLFieldDefinition; import graphql.schema.GraphQLSchema; import graphql.schema.PropertyDataFetcher; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.util.HashMap; +import java.util.function.Supplier; import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema; import static org.testng.Assert.*; @@ -161,8 +163,10 @@ public SampleMultiArgDataFetcher(String target, String flip) { } @Override - public Object get(DataFetchingEnvironment environment) { - final Object result = super.get(environment); + public Object get( final GraphQLFieldDefinition fieldDefinition, final Object source, final Supplier supplier ) + throws Exception + { + final Object result = super.get( fieldDefinition, source, supplier ); if (flip) { return !(Boolean) result; } else { diff --git a/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.java b/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.java index f3117194..710c75a2 100644 --- a/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.java +++ b/src/test/java/graphql/annotations/GraphQLDirectivesViaClassDefinitionTest.java @@ -225,7 +225,7 @@ public void queryNameWithFalse_directivesProvidedToRegistry_wiringIsActivated() this.graphQLAnnotations.getContainer().getDirectiveRegistry().put(upperCase.getName(), new DirectiveAndWiring(upperCase, UpperWiring.class)); GraphQLObjectType object = this.graphQLAnnotations.object(Query.class); GraphQLCodeRegistry codeRegistry = graphQLAnnotations.getContainer().getCodeRegistryBuilder().build(); - GraphQLSchema schema = newSchema().query(object).codeRegistry(codeRegistry).build(); + GraphQLSchema schema = newSchema().query(object).codeRegistry(codeRegistry).additionalDirective( upperCase ).build(); ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("query { nameWithFalse }"); assertTrue(result.getErrors().isEmpty()); diff --git a/src/test/java/graphql/annotations/GraphQLExtensionsTest.java b/src/test/java/graphql/annotations/GraphQLExtensionsTest.java index 6f2f663f..db7e5d0e 100644 --- a/src/test/java/graphql/annotations/GraphQLExtensionsTest.java +++ b/src/test/java/graphql/annotations/GraphQLExtensionsTest.java @@ -117,7 +117,8 @@ public void fields() { public void values() { GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).typeExtension(TestObjectExtension.class).build(); - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field field2 field3 field4 field5}", new GraphQLExtensionsTest.TestObject()); + ExecutionResult result = GraphQL.newGraphQL( schema ).build().execute( + GraphQLHelper.createExecutionInput( "{field field2 field3 field4 field5}", new GraphQLExtensionsTest.TestObject() ) ); Map data = result.getData(); assertEquals(data.get("field"), "test"); assertEquals(data.get("field2"), "test test2"); diff --git a/src/test/java/graphql/annotations/GraphQLFragmentTest.java b/src/test/java/graphql/annotations/GraphQLFragmentTest.java index df8c901e..b127bff4 100644 --- a/src/test/java/graphql/annotations/GraphQLFragmentTest.java +++ b/src/test/java/graphql/annotations/GraphQLFragmentTest.java @@ -65,7 +65,7 @@ public void testInterfaceInlineFragment() throws Exception { GraphQL graphQL2 = GraphQL.newGraphQL(schema).build(); // When - ExecutionResult graphQLResult = graphQL2.execute("{getItems { ... on MyObject {getA, getMy {getB}} ... on MyObject2 {getA, getB} }}", new RootObject()); + ExecutionResult graphQLResult = graphQL2.execute(GraphQLHelper.createExecutionInput("{getItems { ... on MyObject {getA, getMy {getB}} ... on MyObject2 {getA, getB} }}", new RootObject())); Set resultMap = ((Map) graphQLResult.getData()).entrySet(); // Then diff --git a/src/test/java/graphql/annotations/GraphQLHelper.java b/src/test/java/graphql/annotations/GraphQLHelper.java new file mode 100644 index 00000000..ededb29b --- /dev/null +++ b/src/test/java/graphql/annotations/GraphQLHelper.java @@ -0,0 +1,37 @@ +/** + * 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 java.util.Map; + +import graphql.ExecutionInput; + +public class GraphQLHelper +{ + public static ExecutionInput createExecutionInput( String query, Object context, Map variables ) + { + ExecutionInput.Builder builder = ExecutionInput.newExecutionInput().query( query ).root( context ); + if ( variables != null ) + { + builder.variables( variables ); + } + return builder.build(); + } + + public static ExecutionInput createExecutionInput( String query, Object context ) + { + return createExecutionInput( query, context, null ); + } +} diff --git a/src/test/java/graphql/annotations/GraphQLInputTest.java b/src/test/java/graphql/annotations/GraphQLInputTest.java index 3561a7b0..3a129208 100644 --- a/src/test/java/graphql/annotations/GraphQLInputTest.java +++ b/src/test/java/graphql/annotations/GraphQLInputTest.java @@ -186,7 +186,7 @@ public void query() { .additionalType(TestObject.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ object { value(input:{key:\"test\"}) } }", new Query()); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ object { value(input:{key:\"test\"}) } }", new Query())); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map>) result.getData()).get("object").get("value"), "testa"); } @@ -196,7 +196,7 @@ public void queryMultipleDefinitions() { GraphQLSchema schema = newAnnotationsSchema().query(QueryMultipleDefinitions.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ something(code: {firstField:\"a\",secondField:\"b\"}) somethingElse(code: {firstField:\"c\",secondField:\"d\"}) }", new QueryMultipleDefinitions()); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ something(code: {firstField:\"a\",secondField:\"b\"}) somethingElse(code: {firstField:\"c\",secondField:\"d\"}) }", new QueryMultipleDefinitions())); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map) result.getData()).get("something"), "ab"); assertEquals(((Map) result.getData()).get("somethingElse"), "cd"); @@ -207,11 +207,11 @@ public void queryWithRecursion() { GraphQLSchema schema = newAnnotationsSchema().query(QueryRecursion.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ object { value(input:{key:\"test\"}) } }", new QueryRecursion()); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ object { value(input:{key:\"test\"}) } }", new QueryRecursion())); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map>) result.getData()).get("object").get("value"), "testa"); - result = graphQL.execute("{ object { value(input:{rec:{key:\"test\"}}) } }", new QueryRecursion()); + result = graphQL.execute(GraphQLHelper.createExecutionInput("{ object { value(input:{rec:{key:\"test\"}}) } }", new QueryRecursion())); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map>) result.getData()).get("object").get("value"), "rectesta"); } @@ -221,7 +221,7 @@ public void queryWithList() { GraphQLSchema schema = newAnnotationsSchema().query(QueryList.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ object { value(input:[[[{key:\"test\", complex:[{subKey:\"subtest\"},{subKey:\"subtest2\"}]}]]]) } }", new QueryList()); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ object { value(input:[[[{key:\"test\", complex:[{subKey:\"subtest\"},{subKey:\"subtest2\"}]}]]]) } }", new QueryList())); assertEquals(((Map>) result.getData()).get("object").get("value"), "test-subtest"); } @@ -230,7 +230,7 @@ public void queryWithInterface() { GraphQLSchema schema = newAnnotationsSchema().query(QueryIface.class).additionalType(TestObject.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ iface { value(input:{key:\"test\"}) } }", new QueryIface()); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ iface { value(input:{key:\"test\"}) } }", new QueryIface())); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map>) result.getData()).get("iface").get("value"), "testa"); } diff --git a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java index 00c0ae57..4dba806d 100644 --- a/src/test/java/graphql/annotations/GraphQLInterfaceTest.java +++ b/src/test/java/graphql/annotations/GraphQLInterfaceTest.java @@ -170,7 +170,7 @@ public void queryUnion() { GraphQLSchema schema = newAnnotationsSchema().query(UnionQuery.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ union { ... on TestObject1 { value } } }", new UnionQuery(new TestObject1())); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ union { ... on TestObject1 { value } } }", new UnionQuery(new TestObject1()))); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map>) result.getData()).get("union").get("value"), "a"); } diff --git a/src/test/java/graphql/annotations/GraphQLObjectTest.java b/src/test/java/graphql/annotations/GraphQLObjectTest.java index 246d3473..0f6f84de 100644 --- a/src/test/java/graphql/annotations/GraphQLObjectTest.java +++ b/src/test/java/graphql/annotations/GraphQLObjectTest.java @@ -333,10 +333,10 @@ public void methodInheritance() { GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); GraphQLSchema schemaInherited = newAnnotationsSchema().query(TestObjectInherited.class).build(); - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field0}", new TestObject()); + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{field0}", new TestObject())); assertEquals(((Map) result.getData()).get("field0"), "test"); GraphQL graphQL = GraphQL.newGraphQL(schemaInherited).build(); - result = graphQL.execute("{field1}", new TestObjectInherited()); + result = graphQL.execute(GraphQLHelper.createExecutionInput("{field1}", new TestObjectInherited())); assertEquals(((Map) result.getData()).get("field1"), "inherited"); } @@ -369,7 +369,7 @@ public String id() { public void methodInheritanceWithGenerics() { GraphQLSchema schema = newAnnotationsSchema().query(TestObjectBridgMethod.class).build(); - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{id}", new TestObjectBridgMethod()); + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{id}", new TestObjectBridgMethod())); assertEquals(((Map) result.getData()).get("id"), "1"); } @@ -517,7 +517,7 @@ public String someField() { public void dataFetcher() { GraphQLSchema schema = newAnnotationsSchema().query(TestDataFetcher.class).build(); - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field someField}", new TestObject()); + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{field someField}", new TestObject())); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map) result.getData()).get("field"), "test"); assertEquals(((Map) result.getData()).get("someField"), "test"); @@ -527,15 +527,15 @@ public void dataFetcher() { public void query() { GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field0}", new TestObject()); + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{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()); + result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{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()); + result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{fieldWithArgsAndEnvironment(a: \"test\", b: \"passed\")}", new TestObject())); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map) result.getData()).get("fieldWithArgsAndEnvironment"), "test"); @@ -545,7 +545,7 @@ public void query() { public void queryField() { GraphQLSchema schema = newAnnotationsSchema().query(TestField.class).build(); - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field1}", new TestField()); + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{field1}", new TestField())); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map) result.getData()).get("field1"), "test"); } @@ -554,7 +554,7 @@ public void queryField() { public void queryPrivateField() { GraphQLSchema schema = newAnnotationsSchema().query(PrivateTestField.class).build(); - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field1, field2, booleanField}", new PrivateTestField()); + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{field1, field2, booleanField}", new PrivateTestField())); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map) result.getData()).get("field1"), "test"); assertEquals(((Map) result.getData()).get("field2"), "test"); @@ -566,7 +566,7 @@ public void queryPrivateField() { public void defaultArg() { GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).build(); - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{fieldWithArgs(a: \"test\")}", new TestObject()); + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{fieldWithArgs(a: \"test\")}", new TestObject())); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map) result.getData()).get("fieldWithArgs"), "default"); } @@ -599,18 +599,18 @@ public void recursiveTypes() { class2.value = "hello"; class1.value = "bye"; - ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ class2 { value } }", class1); + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput( "{ 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); + result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{ 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); + result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{ class2 { class1 { class2 { value } } } }", class1)); assertTrue(result.getErrors().isEmpty()); } @@ -698,7 +698,8 @@ public void inputObjectArgument() { 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()); + ExecutionResult result = GraphQL.newGraphQL( schema ).build().execute( + GraphQLHelper.createExecutionInput( "{ test( other:0,arg: { a:\"ok\", b:2 }) }", new TestObjectInput() ) ); assertTrue(result.getErrors().isEmpty()); Map v = (Map) result.getData(); assertEquals(v.get("test"), "ok"); @@ -712,7 +713,7 @@ public void complexInputObjectArgument() { 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()); + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute(GraphQLHelper.createExecutionInput("{ test2(arg: {inputs:[{ a:\"ok\", b:2 }]}, other:0) }", new TestObjectInput())); assertTrue(result.getErrors().isEmpty()); Map v = result.getData(); assertEquals(v.get("test2"), "ok"); @@ -795,7 +796,7 @@ public void queryOptional() { GraphQLSchema schema = newSchema().query(object).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{empty, nonempty}", new OptionalTest()); + ExecutionResult result = graphQL.execute( GraphQLHelper.createExecutionInput( "{empty, nonempty}", new OptionalTest() ) ); assertTrue(result.getErrors().isEmpty()); Map v = (Map) result.getData(); assertNull(v.get("empty")); @@ -818,7 +819,7 @@ public void optionalInput() { 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()); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput( "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"); @@ -850,7 +851,7 @@ public void queryEnum() { GraphQLSchema schema = newSchema().query(object).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{e}", new EnumTest(EnumTest.E.B)); + ExecutionResult result = graphQL.execute( GraphQLHelper.createExecutionInput( "{e}", new EnumTest( EnumTest.E.B ) ) ); assertTrue(result.getErrors().isEmpty()); Map v = (Map) result.getData(); assertEquals(v.get("e"), "B"); diff --git a/src/test/java/graphql/annotations/RelayTest.java b/src/test/java/graphql/annotations/RelayTest.java index 85874ab8..0d7a2057 100644 --- a/src/test/java/graphql/annotations/RelayTest.java +++ b/src/test/java/graphql/annotations/RelayTest.java @@ -133,7 +133,9 @@ public void noArgMutation() { GraphQL graphQL = GraphQL.newGraphQL(schema).queryExecutionStrategy(new EnhancedExecutionStrategy()).build(); - ExecutionResult result = graphQL.execute("mutation { doSomething(input: {clientMutationId: \"1\"}) { getI clientMutationId } }", new TestObject()); + ExecutionResult result = graphQL.execute( + GraphQLHelper.createExecutionInput( "mutation { doSomething(input: {clientMutationId: \"1\"}) { getI clientMutationId } }", + new TestObject() ) ); assertEquals(result.getErrors().size(), 0); @@ -155,7 +157,9 @@ public void interfaceReturningMutation() { GraphQL graphQL = GraphQL.newGraphQL(schema).queryExecutionStrategy(new EnhancedExecutionStrategy()).build(); - ExecutionResult result = graphQL.execute("mutation { doSomethingI(input: {clientMutationId: \"1\"}) { getI clientMutationId } }", new TestObject()); + ExecutionResult result = graphQL.execute( + GraphQLHelper.createExecutionInput( "mutation { doSomethingI(input: {clientMutationId: \"1\"}) { getI clientMutationId } }", + new TestObject() ) ); assertEquals(result.getErrors().size(), 0); @@ -194,7 +198,8 @@ public void argMutation() { GraphQL graphQL = GraphQL.newGraphQL(schema).queryExecutionStrategy(new EnhancedExecutionStrategy()).build(); - ExecutionResult result = graphQL.execute("mutation { doSomethingElse(input: {a: 0, b: 1, clientMutationId: \"1\"}) { getI clientMutationId } }", new TestObject()); + ExecutionResult result = graphQL.execute( GraphQLHelper.createExecutionInput( + "mutation { doSomethingElse(input: {a: 0, b: 1, clientMutationId: \"1\"}) { getI clientMutationId } }", new TestObject() ) ); assertEquals(result.getErrors().size(), 0); @@ -237,7 +242,10 @@ public void argVariableMutation() { inputVariables.put("b", 1); inputVariables.put("clientMutationId", "1"); variables.put("input", inputVariables); - ExecutionResult result = graphQL.execute("mutation VariableMutation($input:DoSomethingElseInput!) { doSomethingElse(input: $input) { getI clientMutationId } }", new TestObject(), variables); + + ExecutionResult result = graphQL.execute( GraphQLHelper.createExecutionInput( + "mutation VariableMutation($input:DoSomethingElseInput!) { doSomethingElse(input: $input) { getI clientMutationId } }", + new TestObject(), variables ) ); assertEquals(result.getErrors().size(), 0); diff --git a/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java b/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java index ec1ebd57..fe6ce274 100644 --- a/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java +++ b/src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java @@ -14,6 +14,7 @@ import graphql.ExecutionResult; import graphql.GraphQL; +import graphql.annotations.GraphQLHelper; import graphql.annotations.annotationTypes.GraphQLField; import graphql.annotations.annotationTypes.GraphQLName; import graphql.annotations.annotationTypes.GraphQLNonNull; @@ -135,8 +136,9 @@ public void fieldList() { GraphQLSchema schema = newSchema().query(object).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ objs(first: 1) { edges { cursor node { id, val } } } }", - new TestListField(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world")))); + ExecutionResult result = graphQL.execute( + GraphQLHelper.createExecutionInput( "{ objs(first: 1) { edges { cursor node { id, val } } } }", + new TestListField(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world"))))); } @Test @@ -144,8 +146,8 @@ public void methodList() { GraphQLSchema schema = newAnnotationsSchema().query(TestConnections.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ getObjs(first: 1) { edges { cursor node { id, val } } } }", - new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world")))); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ getObjs(first: 1) { edges { cursor node { id, val } } } }", + new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world"))))); assertTrue(result.getErrors().isEmpty()); @@ -186,8 +188,8 @@ public void methodStream() { GraphQLSchema schema = newAnnotationsSchema().query(TestConnections.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ getObjStream(first: 1) { edges { cursor node { id, val } } } }", - new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world")))); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ getObjStream(first: 1) { edges { cursor node { id, val } } } }", + new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world"))))); assertTrue(result.getErrors().isEmpty()); @@ -199,8 +201,8 @@ public void methodNonNull() { GraphQLSchema schema = newAnnotationsSchema().query(TestConnections.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ getNonNullObjs(first: 1) { edges { cursor node { id, val } } } }", - new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world")))); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ getNonNullObjs(first: 1) { edges { cursor node { id, val } } } }", + new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world"))))); assertTrue(result.getErrors().isEmpty()); @@ -212,8 +214,8 @@ public void methodDoubleNonNull() { GraphQLSchema schema = newAnnotationsSchema().query(TestConnections.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ getDoubleNonNullObjs(first: 1) { edges { cursor node { id, val } } } }", - new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world")))); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ getDoubleNonNullObjs(first: 1) { edges { cursor node { id, val } } } }", + new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world"))))); assertTrue(result.getErrors().isEmpty()); @@ -225,8 +227,8 @@ public void methodNull() { GraphQLSchema schema = newAnnotationsSchema().query(TestConnections.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ getNullObj(first: 1) { edges { cursor node { id, val } } } }", - new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world")))); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ getNullObj(first: 1) { edges { cursor node { id, val } } } }", + new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world"))))); assertTrue(result.getErrors().isEmpty()); @@ -240,8 +242,8 @@ public void emptyListData() { GraphQLSchema schema = newAnnotationsSchema().query(TestConnections.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ getObjStreamWithParam(first: 1, filter:\"hel\") { edges { cursor node { id, val } } } }", - new TestConnections(emptyList())); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ getObjStreamWithParam(first: 1, filter:\"hel\") { edges { cursor node { id, val } } } }", + new TestConnections(emptyList()))); assertTrue(result.getErrors().isEmpty()); Map>>>> data = result.getData(); @@ -255,8 +257,8 @@ public void methodListWithParam() { GraphQLSchema schema = newAnnotationsSchema().query(TestConnections.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ getObjStreamWithParam(first: 2, filter:\"hel\") { edges { cursor node { id, val } } } }", - new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world"), new Obj("4", "hello world"), new Obj("5", "hello again")))); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ getObjStreamWithParam(first: 2, filter:\"hel\") { edges { cursor node { id, val } } } }", + new TestConnections(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world"), new Obj("4", "hello world"), new Obj("5", "hello again"))))); assertTrue(result.getErrors().isEmpty()); @@ -306,8 +308,8 @@ public void customConnection() { GraphQLSchema schema = newAnnotationsSchema().query(TestCustomConnection.class).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); - ExecutionResult result = graphQL.execute("{ getObjs(first: 1) { edges { cursor node { id, val } } } }", - new TestCustomConnection(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world")))); + ExecutionResult result = graphQL.execute(GraphQLHelper.createExecutionInput("{ getObjs(first: 1) { edges { cursor node { id, val } } } }", + new TestCustomConnection(Arrays.asList(new Obj("1", "test"), new Obj("2", "hello"), new Obj("3", "world"))))); assertTrue(result.getErrors().isEmpty()); Map data = result.getData();