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
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public interface PersistedQueryCache {
* If its present in cache then it must return a PreparsedDocumentEntry where {@link graphql.execution.preparsed.PreparsedDocumentEntry#getDocument()}
* is already parsed and validated. This will be passed onto the graphql engine as is.
* <p>
* If its a valid query id but its no present in cache, (cache miss) then you need to call back the "onCacheMiss" function with associated query text.
* This will be compiled and validated by the graphql engine and the a PreparsedDocumentEntry will be passed back ready for you to cache it.
* If it's a valid query id but its no present in cache, (cache miss) then you need to call back the "onCacheMiss" function with associated query text.
* This will be compiled and validated by the graphql engine and the PreparsedDocumentEntry will be passed back ready for you to cache it.
* <p>
* If its not a valid query id then throw a {@link graphql.execution.preparsed.persisted.PersistedQueryNotFound} to indicate this.
* If it's not a valid query id then throw a {@link graphql.execution.preparsed.persisted.PersistedQueryNotFound} to indicate this.
*
* @param persistedQueryId the persisted query id
* @param executionInput the original execution input
* @param onCacheMiss the call back should it be a valid query id but its not currently not in the cache
* @param onCacheMiss the call back should it be a valid query id but it's not currently in the cache
* @return a parsed and validated PreparsedDocumentEntry where {@link graphql.execution.preparsed.PreparsedDocumentEntry#getDocument()} is set
* @throws graphql.execution.preparsed.persisted.PersistedQueryNotFound if the query id is not know at all and you have no query text
*
Expand All @@ -42,14 +42,14 @@ public interface PersistedQueryCache {
* If its present in cache then it must return a PreparsedDocumentEntry where {@link graphql.execution.preparsed.PreparsedDocumentEntry#getDocument()}
* is already parsed and validated. This will be passed onto the graphql engine as is.
* <p>
* If its a valid query id but its no present in cache, (cache miss) then you need to call back the "onCacheMiss" function with associated query text.
* This will be compiled and validated by the graphql engine and the a PreparsedDocumentEntry will be passed back ready for you to cache it.
* If it's a valid query id but its no present in cache, (cache miss) then you need to call back the "onCacheMiss" function with associated query text.
* This will be compiled and validated by the graphql engine and the PreparsedDocumentEntry will be passed back ready for you to cache it.
* <p>
* If its not a valid query id then throw a {@link graphql.execution.preparsed.persisted.PersistedQueryNotFound} to indicate this.
* If it's not a valid query id then throw a {@link graphql.execution.preparsed.persisted.PersistedQueryNotFound} to indicate this.
*
* @param persistedQueryId the persisted query id
* @param executionInput the original execution input
* @param onCacheMiss the call back should it be a valid query id but its not currently not in the cache
* @param onCacheMiss the call back should it be a valid query id but it's not currently in the cache
* @return a promise to parsed and validated {@link PreparsedDocumentEntry} where {@link graphql.execution.preparsed.PreparsedDocumentEntry#getDocument()} is set
* @throws graphql.execution.preparsed.persisted.PersistedQueryNotFound if the query id is not know at all and you have no query text
*/
Expand Down
62 changes: 19 additions & 43 deletions src/test/java/benchmark/TwitterBenchmark.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,34 @@
package benchmark;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import com.github.javafaker.Code;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.execution.ExecutionStepInfo;
import graphql.execution.instrumentation.tracing.TracingInstrumentation;
import graphql.execution.preparsed.PreparsedDocumentEntry;
import graphql.execution.preparsed.PreparsedDocumentProvider;
import graphql.execution.preparsed.persisted.InMemoryPersistedQueryCache;
import graphql.execution.preparsed.persisted.PersistedQueryCache;
import graphql.execution.preparsed.persisted.PersistedQuerySupport;
import graphql.parser.ParserOptions;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetcherFactory;
import graphql.schema.DataFetcherFactoryEnvironment;
import graphql.schema.DataFetchingEnvironment;
import graphql.schema.FieldCoordinates;
import graphql.schema.GraphQLCodeRegistry;
import graphql.schema.GraphQLFieldDefinition;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
import graphql.schema.GraphQLTypeReference;
import graphql.schema.idl.RuntimeWiring;
import graphql.schema.idl.SchemaGenerator;
import graphql.schema.idl.SchemaGeneratorHelper;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import static graphql.Scalars.GraphQLString;
import static graphql.schema.idl.TypeRuntimeWiring.newTypeWiring;

@Warmup(iterations = 8, time = 10)
@Measurement(iterations = 25, time = 10)
Expand Down Expand Up @@ -94,6 +73,8 @@ public static String mkQuery() {
}

private static GraphQL buildGraphQL() {
ParserOptions.setDefaultOperationParserOptions(ParserOptions.newParserOptions().maxTokens(100_000).build());

List<GraphQLFieldDefinition> leafFields = new ArrayList<>(BREADTH);
for (int i = 1; i <= BREADTH; i++) {
leafFields.add(
Expand All @@ -116,12 +97,7 @@ private static GraphQL buildGraphQL() {
DataFetcher<Object> simpleFetcher = env -> env.getField().getName();
GraphQLCodeRegistry codeReg = GraphQLCodeRegistry.newCodeRegistry()
.defaultDataFetcher(
new DataFetcherFactory<Object>() {
@Override
public DataFetcher<Object> get(DataFetcherFactoryEnvironment environment) {
return simpleFetcher;
}
}
environment -> simpleFetcher
)
.build();

Expand Down Expand Up @@ -156,6 +132,6 @@ protected Optional<Object> getPersistedQueryId(ExecutionInput executionInput) {

public static void main(String[] args) {
ExecutionResult result = execute();
int i = 0;
System.out.println(result);
}
}