Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:21.5"
compile "io.github.graphql-java:graphql-java-annotations:24.3"
}
```

Expand All @@ -47,7 +47,7 @@ dependencies {
<dependency>
<groupId>io.github.graphql-java</groupId>
<artifactId>graphql-java-annotations</artifactId>
<version>21.5</version>
<version>24.3</version>
</dependency>
```

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ gradle.projectsEvaluated {

dependencies {
implementation 'javax.validation:validation-api:1.1.0.Final'
implementation 'com.graphql-java:graphql-java:21.5'
implementation 'com.graphql-java:graphql-java-extended-scalars:21.0'
implementation 'com.graphql-java:graphql-java:24.3'
implementation 'com.graphql-java:graphql-java-extended-scalars:24.0'
implementation 'javax.xml.bind:jaxb-api:2.3.1'

// OSGi
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 = 21.5
version = 24.3
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import graphql.annotations.processor.ProcessingElementsContainer;
import graphql.annotations.processor.exceptions.GraphQLAnnotationsException;
import graphql.annotations.processor.util.DirectiveJavaAnnotationUtil;
import graphql.schema.GraphQLAppliedDirective;
import graphql.schema.GraphQLAppliedDirectiveArgument;
import graphql.schema.GraphQLArgument;
import graphql.schema.GraphQLDirective;
import graphql.schema.GraphQLScalarType;
Expand Down Expand Up @@ -135,7 +137,7 @@ private void transformArgument(Annotation annotation, GraphQLDirective.Builder d
Object value;
if ( graphQLArgument.getType() instanceof GraphQLScalarType )
{
value = ((GraphQLScalarType) graphQLArgument.getType()).getCoercing().parseValue(argumentValue);
value = ((GraphQLScalarType) graphQLArgument.getType()).getCoercing().serialize(argumentValue);
}
else
{
Expand All @@ -161,8 +163,8 @@ private void transformArgument(String[] argumentValues, GraphQLDirective.Builder
if (graphQLArgument.getType() instanceof GraphQLScalarType) {

try {
Object value = ((GraphQLScalarType) graphQLArgument.getType()).getCoercing().parseValue(argumentValue);
builder.value( value );
Object value = ((GraphQLScalarType) graphQLArgument.getType()).getCoercing().serialize(argumentValue);
builder.value(value);
} catch (Exception e) {
throw new GraphQLAnnotationsException(COULD_NOT_PARSE_ARGUMENT_VALUE_TO_ARGUMENT_TYPE, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public static void wrapDataFetcher(GraphQLFieldDefinition fieldDefinition, Annot
* @return the data fetcher
*/
public static DataFetcher getDataFetcher(GraphQLCodeRegistry.Builder codeRegistryBuilder, GraphQLSchemaElement parentElement, GraphQLFieldDefinition fieldDefinition) {
return codeRegistryBuilder.getDataFetcher((GraphQLFieldsContainer) parentElement, fieldDefinition);
return codeRegistryBuilder.getDataFetcher(FieldCoordinates.coordinates((GraphQLFieldsContainer) parentElement, fieldDefinition), fieldDefinition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,34 @@

import java.util.HashMap;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

public class EnhancedExecutionStrategy extends AsyncSerialExecutionStrategy {

private static final String CLIENT_MUTATION_ID = "clientMutationId";

@Override
protected CompletableFuture<ExecutionResult> resolveField(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {
GraphQLObjectType parentType = (GraphQLObjectType) parameters.getExecutionStepInfo().getUnwrappedNonNullType();
GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, parameters.getField().getSingleField());
if (fieldDef == null) return null;
protected FieldValueInfo completeValue(ExecutionContext executionContext, ExecutionStrategyParameters parameters) throws NonNullableFieldWasNullException {
graphql.schema.GraphQLType fieldType = parameters.getExecutionStepInfo().getType();

if (fieldDef.getName().contentEquals(CLIENT_MUTATION_ID)) {
if (parameters.getExecutionStepInfo().getFieldDefinition().getName().contentEquals(CLIENT_MUTATION_ID)) {
Field field = (Field) executionContext.getOperationDefinition().getSelectionSet().getSelections().get(0);
Argument argument = field.getArguments().get(0);

Object clientMutationId;
if (argument.getValue() instanceof VariableReference) {
VariableReference ref = (VariableReference) argument.getValue();
HashMap mutationInputVariables = (HashMap) executionContext.getVariables().get(ref.getName());
HashMap mutationInputVariables = (HashMap) executionContext.getCoercedVariables().get(ref.getName());
clientMutationId = mutationInputVariables.get(CLIENT_MUTATION_ID);
} else {
ObjectValue value = (ObjectValue) field.getArguments().get(0).getValue();
StringValue clientMutationIdVal = (StringValue) value.getObjectFields().stream()
.filter(f -> f.getName().contentEquals(CLIENT_MUTATION_ID))
.findFirst().get().getValue();
.filter(f -> f.getName().contentEquals(CLIENT_MUTATION_ID))
.findFirst().get().getValue();
clientMutationId = clientMutationIdVal.getValue();
}

ExecutionStepInfo fieldTypeInfo = ExecutionStepInfo.newExecutionStepInfo().type(fieldDef.getType()).parentInfo(parameters.getExecutionStepInfo()).build();
ExecutionStrategyParameters newParameters = ExecutionStrategyParameters.newParameters()
.fields(parameters.getFields())
.nonNullFieldValidator(parameters.getNonNullFieldValidator())
.executionStepInfo(fieldTypeInfo)
.source(clientMutationId)
.build();


return completeValue(executionContext, newParameters).getFieldValue();
} else {
return super.resolveField(executionContext, parameters);
return super.completeValue(executionContext, withSource(parameters, clientMutationId));
}
}

@Override
protected FieldValueInfo completeValue(ExecutionContext executionContext, ExecutionStrategyParameters parameters) throws NonNullableFieldWasNullException {
graphql.schema.GraphQLType fieldType = parameters.getExecutionStepInfo().getType();
Object result = parameters.getSource();
if (result instanceof Enum && fieldType instanceof GraphQLEnumType) {
Object value = ((GraphQLEnumType) fieldType).parseValue(((Enum) result).name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ public void queryWithArrayWithinAnArray() {
}

private Object getQueryResultAtIndex(ExecutionResult result, String queryName, int index) {
return ((ArrayList) (((LinkedHashMap) result.getData()).get(queryName))).get(index);
return ((List) (((LinkedHashMap) result.getData()).get(queryName))).get(index);
}

private Object getQueryResultAtCell(ExecutionResult result, String queryName, int rowIndex, int columnIndex) {
return (((ArrayList) (getQueryResultAtIndex(result, queryName, rowIndex))).get(columnIndex));
return (((List) (getQueryResultAtIndex(result, queryName, rowIndex))).get(columnIndex));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import graphql.annotations.processor.DirectiveAndWiring;
import graphql.annotations.processor.ProcessingElementsContainer;
import graphql.annotations.processor.exceptions.GraphQLAnnotationsException;
import graphql.introspection.Introspection;
import graphql.schema.GraphQLDirective;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -67,8 +68,8 @@ public void getDirectiveWiringMap_noDirectivesInRegistry_throwAGraphQLAnnotation
public void getDirectiveWiringMap_wiringClassIsPrivate_throwAGraphQLAnnotationsException() throws Exception {
// Arrange
DirectiveWiringMapRetriever directiveWiringMapRetriever = new DirectiveWiringMapRetriever();
GraphQLDirective upperCase = newDirective().name("upperCase").build();
GraphQLDirective lowerCase = newDirective().name("lowerCase").build();
GraphQLDirective upperCase = newDirective().name("upperCase").validLocation(Introspection.DirectiveLocation.FIELD).build();
GraphQLDirective lowerCase = newDirective().name("lowerCase").validLocation(Introspection.DirectiveLocation.FIELD).build();
ProcessingElementsContainer container = new ProcessingElementsContainer();
container.getDirectiveRegistry().put("upperCase", new DirectiveAndWiring(upperCase, ThirdWiringClass.class));
container.getDirectiveRegistry().put("lowerCase", new DirectiveAndWiring(lowerCase, SecondWiringClass.class));
Expand All @@ -87,8 +88,8 @@ public void getDirectiveWiringMap_wiringClassIsPrivate_throwAGraphQLAnnotationsE
public void getDirectiveWiringMap_directivesAreInRegistry_returnCorrectMap() throws Exception {
// Arrange
DirectiveWiringMapRetriever directiveWiringMapRetriever = new DirectiveWiringMapRetriever();
GraphQLDirective upperCase = newDirective().name("upperCase").build();
GraphQLDirective lowerCase = newDirective().name("lowerCase").build();
GraphQLDirective upperCase = newDirective().name("upperCase").validLocation(Introspection.DirectiveLocation.FIELD).build();
GraphQLDirective lowerCase = newDirective().name("lowerCase").validLocation(Introspection.DirectiveLocation.FIELD).build();
ProcessingElementsContainer container = new ProcessingElementsContainer();
container.getDirectiveRegistry().put("upperCase", new DirectiveAndWiring(upperCase, WiringClass.class));
container.getDirectiveRegistry().put("lowerCase", new DirectiveAndWiring(lowerCase, SecondWiringClass.class));
Expand Down
Loading
Loading