Skip to content

Commit

Permalink
Merge pull request #291 from anatol-sialitski/master
Browse files Browse the repository at this point in the history
Bump version graphql-java from 17.2 to 20.3
  • Loading branch information
sergehuber authored Aug 17, 2023
2 parents 9090887 + 69e340e commit 44ab83c
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 68 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;


Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/graphql/annotations/GraphQLDataFetcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/graphql/annotations/GraphQLExtensionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> data = result.getData();
assertEquals(data.get("field"), "test");
assertEquals(data.get("field2"), "test test2");
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/graphql/annotations/GraphQLFragmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/graphql/annotations/GraphQLHelper.java
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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 );
}
}
12 changes: 6 additions & 6 deletions src/test/java/graphql/annotations/GraphQLInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Map<String, String>>) result.getData()).get("object").get("value"), "testa");
}
Expand All @@ -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<String, String>) result.getData()).get("something"), "ab");
assertEquals(((Map<String, String>) result.getData()).get("somethingElse"), "cd");
Expand All @@ -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<String, Map<String, String>>) 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<String, Map<String, String>>) result.getData()).get("object").get("value"), "rectesta");
}
Expand All @@ -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<String, Map<String, String>>) result.getData()).get("object").get("value"), "test-subtest");
}

Expand All @@ -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<String, Map<String, String>>) result.getData()).get("iface").get("value"), "testa");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Map<String, String>>) result.getData()).get("union").get("value"), "a");
}
Expand Down
Loading

0 comments on commit 44ab83c

Please sign in to comment.