diff --git a/gradle.properties b/gradle.properties index fe7b7521..12dcffd0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ PROJECT_LICENSE=MIT PROJECT_LICENSE_URL=https://github.com/graphql-java-kickstart/spring-java-servlet/blob/master/LICENSE.md PROJECT_DEV_ID=oliemansm PROJECT_DEV_NAME=Michiel Oliemans -LIB_GRAPHQL_JAVA_VER=19.3 +LIB_GRAPHQL_JAVA_VER=20.0 LIB_JACKSON_VER=2.14.2 LIB_SLF4J_VER=2.0.6 LIB_LOMBOK_VER=1.18.26 diff --git a/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLQueryInvoker.java b/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLQueryInvoker.java index 06982331..b03f2ec8 100644 --- a/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLQueryInvoker.java +++ b/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLQueryInvoker.java @@ -2,7 +2,7 @@ import graphql.execution.instrumentation.ChainedInstrumentation; import graphql.execution.instrumentation.Instrumentation; -import graphql.execution.instrumentation.SimpleInstrumentation; +import graphql.execution.instrumentation.SimplePerformantInstrumentation; import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentationOptions; import graphql.execution.preparsed.NoOpPreparsedDocumentProvider; import graphql.execution.preparsed.PreparsedDocumentProvider; @@ -12,7 +12,9 @@ import java.util.List; import java.util.function.Supplier; -/** @author Andrew Potter */ +/** + * @author Andrew Potter + */ public class GraphQLQueryInvoker { private final Supplier getExecutionStrategyProvider; @@ -48,7 +50,8 @@ public static class Builder { private Supplier getExecutionStrategyProvider = DefaultExecutionStrategyProvider::new; - private Supplier getInstrumentation = () -> SimpleInstrumentation.INSTANCE; + private Supplier getInstrumentation = + () -> SimplePerformantInstrumentation.INSTANCE; private Supplier getPreparsedDocumentProvider = () -> NoOpPreparsedDocumentProvider.INSTANCE; private Supplier diff --git a/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/config/GraphQLBuilder.java b/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/config/GraphQLBuilder.java index f275b48f..aa43deaa 100644 --- a/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/config/GraphQLBuilder.java +++ b/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/config/GraphQLBuilder.java @@ -4,7 +4,7 @@ import graphql.execution.ExecutionStrategy; import graphql.execution.instrumentation.ChainedInstrumentation; import graphql.execution.instrumentation.Instrumentation; -import graphql.execution.instrumentation.SimpleInstrumentation; +import graphql.execution.instrumentation.SimplePerformantInstrumentation; import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation; import graphql.execution.preparsed.NoOpPreparsedDocumentProvider; import graphql.execution.preparsed.PreparsedDocumentProvider; @@ -20,7 +20,8 @@ public class GraphQLBuilder { () -> NoOpPreparsedDocumentProvider.INSTANCE; @Getter - private Supplier instrumentationSupplier = () -> SimpleInstrumentation.INSTANCE; + private Supplier instrumentationSupplier = + () -> SimplePerformantInstrumentation.INSTANCE; private Supplier graphQLBuilderConfigurerSupplier = () -> builder -> {}; diff --git a/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/instrumentation/ConfigurableDispatchInstrumentation.java b/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/instrumentation/ConfigurableDispatchInstrumentation.java index 4a103fa8..477071be 100644 --- a/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/instrumentation/ConfigurableDispatchInstrumentation.java +++ b/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/instrumentation/ConfigurableDispatchInstrumentation.java @@ -64,14 +64,17 @@ public InstrumentationState createState(InstrumentationCreateStateParameters par @Override public DataFetcher instrumentDataFetcher( - DataFetcher dataFetcher, InstrumentationFieldFetchParameters parameters) { - DataLoaderDispatcherInstrumentationState state = parameters.getInstrumentationState(); + DataFetcher dataFetcher, + InstrumentationFieldFetchParameters parameters, + InstrumentationState instrumentationState) { + DataLoaderDispatcherInstrumentationState state = + InstrumentationState.ofState(instrumentationState); if (state.isAggressivelyBatching()) { return dataFetcher; } // // currently only AsyncExecutionStrategy with DataLoader and hence this allows us to "dispatch" - // on every object if its not using aggressive batching for other execution strategies + // on every object if it's not using aggressive batching for other execution strategies // which allows them to work if used. return (DataFetcher) environment -> { @@ -87,12 +90,14 @@ private void doImmediatelyDispatch(DataLoaderDispatcherInstrumentationState stat @Override public InstrumentationContext beginExecuteOperation( - InstrumentationExecuteOperationParameters parameters) { + InstrumentationExecuteOperationParameters parameters, + InstrumentationState instrumentationState) { if (!isDataLoaderCompatible(parameters.getExecutionContext())) { - DataLoaderDispatcherInstrumentationState state = parameters.getInstrumentationState(); + DataLoaderDispatcherInstrumentationState state = + InstrumentationState.ofState(instrumentationState); state.setAggressivelyBatching(false); } - return new SimpleInstrumentationContext<>(); + return SimpleInstrumentationContext.noOp(); } private boolean isDataLoaderCompatible(ExecutionContext executionContext) { @@ -111,8 +116,10 @@ private boolean isDataLoaderCompatible(ExecutionContext executionContext) { @Override public ExecutionStrategyInstrumentationContext beginExecutionStrategy( - InstrumentationExecutionStrategyParameters parameters) { - DataLoaderDispatcherInstrumentationState state = parameters.getInstrumentationState(); + InstrumentationExecutionStrategyParameters parameters, + InstrumentationState instrumentationState) { + DataLoaderDispatcherInstrumentationState state = + InstrumentationState.ofState(instrumentationState); // // if there are no data loaders, there is nothing to do // @@ -134,21 +141,25 @@ public void onCompleted(ExecutionResult result, Throwable t) { @Override public InstrumentationContext beginFieldFetch( - InstrumentationFieldFetchParameters parameters) { - DataLoaderDispatcherInstrumentationState state = parameters.getInstrumentationState(); + InstrumentationFieldFetchParameters parameters, InstrumentationState instrumentationState) { + DataLoaderDispatcherInstrumentationState state = + InstrumentationState.ofState(instrumentationState); // // if there are no data loaders, there is nothing to do // if (state.hasNoDataLoaders()) { - return new SimpleInstrumentationContext<>(); + return SimpleInstrumentationContext.noOp(); } return state.getApproach().beginFieldFetch(parameters); } @Override public CompletableFuture instrumentExecutionResult( - ExecutionResult executionResult, InstrumentationExecutionParameters parameters) { - DataLoaderDispatcherInstrumentationState state = parameters.getInstrumentationState(); + ExecutionResult executionResult, + InstrumentationExecutionParameters parameters, + InstrumentationState instrumentationState) { + DataLoaderDispatcherInstrumentationState state = + InstrumentationState.ofState(instrumentationState); state.getApproach().removeTracking(parameters.getExecutionInput().getExecutionId()); if (!options.isIncludeStatistics()) { return CompletableFuture.completedFuture(executionResult); diff --git a/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/instrumentation/NoOpInstrumentationProvider.java b/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/instrumentation/NoOpInstrumentationProvider.java index 0190c731..e43d3f14 100644 --- a/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/instrumentation/NoOpInstrumentationProvider.java +++ b/graphql-java-kickstart/src/main/java/graphql/kickstart/execution/instrumentation/NoOpInstrumentationProvider.java @@ -1,13 +1,13 @@ package graphql.kickstart.execution.instrumentation; import graphql.execution.instrumentation.Instrumentation; -import graphql.execution.instrumentation.SimpleInstrumentation; +import graphql.execution.instrumentation.SimplePerformantInstrumentation; import graphql.kickstart.execution.config.InstrumentationProvider; public class NoOpInstrumentationProvider implements InstrumentationProvider { @Override public Instrumentation getInstrumentation() { - return SimpleInstrumentation.INSTANCE; + return SimplePerformantInstrumentation.INSTANCE; } } diff --git a/graphql-java-servlet/build.gradle b/graphql-java-servlet/build.gradle index 5d9eb6ec..9e741d03 100644 --- a/graphql-java-servlet/build.gradle +++ b/graphql-java-servlet/build.gradle @@ -29,7 +29,7 @@ dependencies { compileOnly 'org.osgi:org.osgi.service.metatype.annotations:1.4.1' compileOnly 'org.osgi:org.osgi.annotation:6.0.0' - testImplementation 'io.github.graphql-java:graphql-java-annotations:8.3' + testImplementation 'io.github.graphql-java:graphql-java-annotations:9.1' // Unit testing testImplementation "org.apache.groovy:groovy-all:4.0.10" diff --git a/graphql-java-servlet/src/test/groovy/graphql/kickstart/servlet/DataLoaderDispatchingSpec.groovy b/graphql-java-servlet/src/test/groovy/graphql/kickstart/servlet/DataLoaderDispatchingSpec.groovy index 58003651..89f1abe1 100644 --- a/graphql-java-servlet/src/test/groovy/graphql/kickstart/servlet/DataLoaderDispatchingSpec.groovy +++ b/graphql-java-servlet/src/test/groovy/graphql/kickstart/servlet/DataLoaderDispatchingSpec.groovy @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import graphql.ExecutionInput import graphql.execution.instrumentation.ChainedInstrumentation import graphql.execution.instrumentation.Instrumentation -import graphql.execution.instrumentation.SimpleInstrumentation +import graphql.execution.instrumentation.SimplePerformantInstrumentation import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentationOptions import graphql.kickstart.execution.context.ContextSetting import graphql.kickstart.execution.context.DefaultGraphQLContext @@ -14,7 +14,7 @@ import graphql.kickstart.servlet.context.GraphQLServletContextBuilder import graphql.schema.DataFetcher import graphql.schema.DataFetchingEnvironment import org.dataloader.BatchLoader -import org.dataloader.DataLoader +import org.dataloader.DataLoaderFactory import org.dataloader.DataLoaderRegistry import org.springframework.mock.web.MockHttpServletRequest import org.springframework.mock.web.MockHttpServletResponse @@ -59,9 +59,9 @@ class DataLoaderDispatchingSpec extends Specification { def registry() { DataLoaderRegistry registry = new DataLoaderRegistry() - registry.register("A", DataLoader.newDataLoader(batchLoaderWithCounter(fetchCounterA))) - registry.register("B", DataLoader.newDataLoader(batchLoaderWithCounter(fetchCounterB))) - registry.register("C", DataLoader.newDataLoader(batchLoaderWithCounter(fetchCounterC))) + registry.register("A", DataLoaderFactory.newDataLoader(batchLoaderWithCounter(fetchCounterA))) + registry.register("B", DataLoaderFactory.newDataLoader(batchLoaderWithCounter(fetchCounterB))) + registry.register("C", DataLoaderFactory.newDataLoader(batchLoaderWithCounter(fetchCounterC))) registry } @@ -120,7 +120,7 @@ class DataLoaderDispatchingSpec extends Specification { mapper.readValue(response.getContentAsByteArray(), List) } - Instrumentation simpleInstrumentation = new SimpleInstrumentation() + Instrumentation simpleInstrumentation = new SimplePerformantInstrumentation() ChainedInstrumentation chainedInstrumentation = new ChainedInstrumentation(Collections.singletonList(simpleInstrumentation)) def simpleSupplier = { simpleInstrumentation } def chainedSupplier = { chainedInstrumentation } diff --git a/graphql-java-servlet/src/test/groovy/graphql/kickstart/servlet/OsgiGraphQLHttpServletSpec.groovy b/graphql-java-servlet/src/test/groovy/graphql/kickstart/servlet/OsgiGraphQLHttpServletSpec.groovy index 7556946a..ea4ed23d 100644 --- a/graphql-java-servlet/src/test/groovy/graphql/kickstart/servlet/OsgiGraphQLHttpServletSpec.groovy +++ b/graphql-java-servlet/src/test/groovy/graphql/kickstart/servlet/OsgiGraphQLHttpServletSpec.groovy @@ -5,7 +5,7 @@ import graphql.annotations.annotationTypes.GraphQLField import graphql.annotations.annotationTypes.GraphQLName import graphql.annotations.processor.GraphQLAnnotations import graphql.execution.instrumentation.InstrumentationState -import graphql.execution.instrumentation.SimpleInstrumentation +import graphql.execution.instrumentation.SimplePerformantInstrumentation import graphql.execution.instrumentation.parameters.InstrumentationCreateStateParameters import graphql.kickstart.execution.GraphQLRequest import graphql.kickstart.execution.config.ExecutionStrategyProvider @@ -349,7 +349,7 @@ class OsgiGraphQLHttpServletSpec extends Specification { def "instrumentation provider is bound and unbound"() { setup: def servlet = new OsgiGraphQLHttpServlet() - def instrumentation = new SimpleInstrumentation() + def instrumentation = new SimplePerformantInstrumentation() def instrumentationProvider = Mock(InstrumentationProvider) instrumentationProvider.getInstrumentation() >> instrumentation def request = GraphQLRequest.createIntrospectionRequest()