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 @@ -468,7 +468,7 @@ default GraphQLSchema instrumentSchema(GraphQLSchema schema, InstrumentationExec
*
* @return a non null instrumented ExecutionContext, the default is to return to the same object
*
* @deprecated use {@link #instrumentExecutionContext(ExecutionContext, InstrumentationExecutionParameters)} instead

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was pointing to the deprecated method signature

* @deprecated use {@link #instrumentExecutionContext(ExecutionContext, InstrumentationExecutionParameters, InstrumentationState)} instead
*/
@Deprecated
@DeprecatedAt("2022-07-26")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void testGson(HttpServletResponse response, Object er) throws IOExceptio
private ExecutionResult createER() {
List<GraphQLError> errors = new ArrayList<>();

errors.add(new ValidationError(ValidationErrorType.UnknownType, mkLocations(), "Test ValidationError"));
errors.add(new ValidationError(ValidationErrorType.UnknownType, mkLocations(), "Test ValidationError")); // Retain as there is no alternative constructor for ValidationError
errors.add(new MissingRootTypeException("Mutations are not supported.", null));
errors.add(new InvalidSyntaxError(mkLocations(), "Not good syntax m'kay"));
errors.add(new NonNullableFieldWasNullError(new NonNullableFieldWasNullException(mkExecutionInfo(), mkPath())));
Expand Down
7 changes: 4 additions & 3 deletions src/test/groovy/example/http/HttpMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import graphql.schema.idl.TypeDefinitionRegistry;
import org.dataloader.BatchLoader;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderFactory;
import org.dataloader.DataLoaderRegistry;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
Expand Down Expand Up @@ -46,7 +47,7 @@
import static java.util.Arrays.asList;

/**
* An very simple example of serving a qraphql schema over http.
* A very simple example of serving a graphql schema over http.
* <p>
* More info can be found here : http://graphql.org/learn/serving-over-http/
*/
Expand Down Expand Up @@ -178,7 +179,7 @@ private DataLoaderRegistry buildDataLoaderRegistry() {
CompletableFuture.supplyAsync(() ->
loadCharactersViaHTTP(keys));

DataLoader<String, Object> friendsDataLoader = new DataLoader<>(friendsBatchLoader);
DataLoader<String, Object> friendsDataLoader = DataLoaderFactory.newDataLoader(friendsBatchLoader);

DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry();
//
Expand Down Expand Up @@ -275,7 +276,7 @@ private Reader loadSchemaFile(String name) {
}

// Lots of the data happens to be maps of objects and this allows us to get back into type safety land
// with less boiler plate and casts
// with less boilerplate and casts
//
@SuppressWarnings("TypeParameterUnusedInFormals")
private <T> T asMapGet(Object mapObj, Object mapKey) {
Expand Down
58 changes: 33 additions & 25 deletions src/test/groovy/graphql/GarfieldSchema.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graphql;


import graphql.schema.GraphQLCodeRegistry;
import graphql.schema.GraphQLInterfaceType;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
Expand Down Expand Up @@ -111,23 +112,24 @@ public List<Named> getFriends() {
.field(newFieldDefinition()
.name("name")
.type(GraphQLString))
.typeResolver(new TypeResolver() {
@Override
public GraphQLObjectType getType(TypeResolutionEnvironment env) {
if (env.getObject() instanceof Dog) {
return DogType;
}
if (env.getObject() instanceof Person) {
return PersonType;
}
if (env.getObject() instanceof Cat) {
return CatType;
}
return null;
}
})
.build();

public static TypeResolver namedTypeResolver = new TypeResolver() {
@Override
public GraphQLObjectType getType(TypeResolutionEnvironment env) {
if (env.getObject() instanceof Dog) {
return DogType;
}
if (env.getObject() instanceof Person) {
return PersonType;
}
if (env.getObject() instanceof Cat) {
return CatType;
}
return null;
}
};

public static GraphQLObjectType DogType = newObject()
.name("Dog")
.field(newFieldDefinition()
Expand All @@ -154,17 +156,18 @@ public GraphQLObjectType getType(TypeResolutionEnvironment env) {
.name("Pet")
.possibleType(CatType)
.possibleType(DogType)
.typeResolver(env -> {
if (env.getObject() instanceof Cat) {
return CatType;
}
if (env.getObject() instanceof Dog) {
return DogType;
}
return null;
})
.build();

public static TypeResolver petTypeResolver = env -> {
if (env.getObject() instanceof Cat) {
return CatType;
}
if (env.getObject() instanceof Dog) {
return DogType;
}
return null;
};

public static GraphQLObjectType PersonType = newObject()
.name("Person")
.field(newFieldDefinition()
Expand All @@ -179,9 +182,14 @@ public GraphQLObjectType getType(TypeResolutionEnvironment env) {
.withInterface(NamedType)
.build();

public static GraphQLCodeRegistry codeRegistry = GraphQLCodeRegistry.newCodeRegistry()
.typeResolver("Named", namedTypeResolver)
.typeResolver("Pet", petTypeResolver)
.build();

public static GraphQLSchema GarfieldSchema = GraphQLSchema.newSchema()
.query(PersonType)
.codeRegistry(codeRegistry)
.build();


}
2 changes: 1 addition & 1 deletion src/test/groovy/graphql/NestedInputSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static GraphQLObjectType rootType() {
.argument(GraphQLArgument.newArgument()
.name("intialValue")
.type(GraphQLInt)
.defaultValue(5))
.defaultValueProgrammatic(5))
.argument(GraphQLArgument.newArgument()
.name("filter")
.type(filterType())))
Expand Down
2 changes: 1 addition & 1 deletion src/test/groovy/graphql/ScalarsQuerySchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ScalarsQuerySchema {
.field(newFieldDefinition()
.name("floatNaN")
.type(Scalars.GraphQLFloat)
.staticValue(Double.NaN))
.staticValue(Double.NaN)) // Retain for test coverage

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this one of the values we decided was not valid.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I'll include this in the NaN test tidy up. I can't see any test using this field at the moment

// Scalars with input of same type, value echoed back
.field(newFieldDefinition()
.name("floatNaNInput")
Expand Down
2 changes: 1 addition & 1 deletion src/test/groovy/graphql/StarWarsSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class StarWarsSchema {
.name("appearsIn")
.description("Which movies they appear in.")
.type(list(episodeEnum)))
.typeResolver(StarWarsData.getCharacterTypeResolver())
.comparatorRegistry(BY_NAME_REGISTRY)
.build();

Expand Down Expand Up @@ -180,6 +179,7 @@ public class StarWarsSchema {
.dataFetcher(humanCoordinates, humanDataFetcher)
.dataFetcher(droidCoordinates, droidDataFetcher)
.dataFetcher(createHumanCoordinates, createHumanDataFetcher)
.typeResolver("Character", StarWarsData.getCharacterTypeResolver())
.build();

public static GraphQLSchema starWarsSchema = GraphQLSchema.newSchema()
Expand Down
11 changes: 8 additions & 3 deletions src/test/groovy/graphql/TypeReferenceSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import graphql.schema.Coercing;
import graphql.schema.GraphQLArgument;
import graphql.schema.GraphQLCodeRegistry;
import graphql.schema.GraphQLDirective;
import graphql.schema.GraphQLEnumType;
import graphql.schema.GraphQLFieldDefinition;
Expand Down Expand Up @@ -148,7 +149,6 @@ public Boolean parseLiteral(Object input) {
.name("Pet")
.possibleType(GraphQLTypeReference.typeRef(CatType.getName()))
.possibleType(GraphQLTypeReference.typeRef(DogType.getName()))
.typeResolver(new TypeResolverProxy())
.withDirective(unionDirective)
.build();
}
Expand All @@ -171,7 +171,6 @@ public Boolean parseLiteral(Object input) {

Addressable = GraphQLInterfaceType.newInterface()
.name("Addressable")
.typeResolver(new TypeResolverProxy())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("address")
.type(GraphQLString))
Expand Down Expand Up @@ -316,6 +315,12 @@ public Boolean parseLiteral(Object input) {
.type(QueryDirectiveInput))
.build();

public static GraphQLCodeRegistry codeRegistry = GraphQLCodeRegistry.newCodeRegistry()
.typeResolver("Pet", new TypeResolverProxy())
.typeResolver("Addressable", new TypeResolverProxy())
.typeResolver("Named", GarfieldSchema.namedTypeResolver)
.build();

public static GraphQLSchema SchemaWithReferences = GraphQLSchema.newSchema()
.query(PersonService)
.additionalTypes(new HashSet<>(Arrays.asList(PersonType, PersonInputType, PetType, CatType, DogType, NamedType, HairStyle, OnOff)))
Expand All @@ -330,6 +335,6 @@ public Boolean parseLiteral(Object input) {
.additionalDirective(enumDirective)
.additionalDirective(enumValueDirective)
.additionalDirective(interfaceDirective)

.codeRegistry(codeRegistry)
.build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import graphql.ErrorType
import graphql.ExecutionResult
import graphql.GraphQLContext
import graphql.execution.instrumentation.ExecutionStrategyInstrumentationContext
import graphql.execution.instrumentation.InstrumentationState
import graphql.execution.instrumentation.SimpleInstrumentation
import graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters
import graphql.language.Field
Expand Down Expand Up @@ -267,7 +268,7 @@ class AsyncExecutionStrategyTest extends Specification {
.locale(Locale.getDefault())
.instrumentation(new SimpleInstrumentation() {
@Override
ExecutionStrategyInstrumentationContext beginExecutionStrategy(InstrumentationExecutionStrategyParameters parameters) {
ExecutionStrategyInstrumentationContext beginExecutionStrategy(InstrumentationExecutionStrategyParameters parameters, InstrumentationState state) {
return new ExecutionStrategyInstrumentationContext() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ class DataFetcherExceptionHandlerTest extends Specification {

def "integration test to prove an async custom error handle can be made"() {
DataFetcherExceptionHandler handler = new DataFetcherExceptionHandler() {
@Override
DataFetcherExceptionHandlerResult onException(DataFetcherExceptionHandlerParameters handlerParameters) {
return null
}

@Override
CompletableFuture<DataFetcherExceptionHandlerResult> handleException(DataFetcherExceptionHandlerParameters params) {
def msg = "The thing went " + params.getException().getMessage()
Expand Down Expand Up @@ -117,11 +112,6 @@ class DataFetcherExceptionHandlerTest extends Specification {

def "if an async exception handler itself throws an exception than that is handled"() {
DataFetcherExceptionHandler handler = new DataFetcherExceptionHandler() {
@Override
DataFetcherExceptionHandlerResult onException(DataFetcherExceptionHandlerParameters handlerParameters) {
return null
}

@Override
CompletableFuture<DataFetcherExceptionHandlerResult> handleException(DataFetcherExceptionHandlerParameters handlerParameters) {
throw new RuntimeException("The handler itself went BANG!")
Expand All @@ -140,11 +130,6 @@ class DataFetcherExceptionHandlerTest extends Specification {

def "multiple errors can be returned in a handler"() {
DataFetcherExceptionHandler handler = new DataFetcherExceptionHandler() {
@Override
DataFetcherExceptionHandlerResult onException(DataFetcherExceptionHandlerParameters handlerParameters) {
return null
}

@Override
CompletableFuture<DataFetcherExceptionHandlerResult> handleException(DataFetcherExceptionHandlerParameters params) {
def result = DataFetcherExceptionHandlerResult.newResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import graphql.ExecutionInput
import graphql.GraphQL
import graphql.StarWarsSchema
import graphql.execution.instrumentation.InstrumentationContext
import graphql.execution.instrumentation.InstrumentationState
import graphql.execution.instrumentation.SimpleInstrumentation
import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters
import graphql.validation.ValidationError
Expand All @@ -16,8 +17,8 @@ class ExecutionStrategyExceptionHandlingEquivalenceTest extends Specification {
class TestInstrumentation extends SimpleInstrumentation {

@Override
InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetchParameters parameters) {
throw new AbortExecutionException([new ValidationError(ValidationErrorType.UnknownType)])
InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetchParameters parameters, InstrumentationState state) {
throw new AbortExecutionException([new ValidationError(ValidationErrorType.UnknownType)]) // Retain as there is no alternative constructor for ValidationError
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/groovy/graphql/execution/ExecutionTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class ExecutionTest extends Specification {

@Override
ExecutionContext instrumentExecutionContext(ExecutionContext executionContext,
InstrumentationExecutionParameters parameters) {
InstrumentationExecutionParameters parameters,
InstrumentationState state) {

return ExecutionContextBuilder.newExecutionContextBuilder(executionContext)
.queryStrategy(queryStrategyUpdatedToDuringExecutionContextInstrument)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import graphql.schema.DataFetcher;
import org.dataloader.BatchLoader;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderFactory;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -99,7 +100,7 @@ private static List<List<Department>> getDepartmentsForShops(List<Shop> shops) {
return completedFuture(getDepartmentsForShops(shopList));
});

public DataLoader<String, List<Department>> departmentsForShopDataLoader = new DataLoader<>(departmentsForShopsBatchLoader);
public DataLoader<String, List<Department>> departmentsForShopDataLoader = DataLoaderFactory.newDataLoader(departmentsForShopsBatchLoader);

public DataFetcher<CompletableFuture<List<Department>>> departmentsForShopDataLoaderDataFetcher = environment -> {
Shop shop = environment.getSource();
Expand Down Expand Up @@ -136,7 +137,7 @@ private static List<List<Product>> getProductsForDepartments(List<Department> de
return completedFuture(getProductsForDepartments(d));
});

public DataLoader<String, List<Product>> productsForDepartmentDataLoader = new DataLoader<>(productsForDepartmentsBatchLoader);
public DataLoader<String, List<Product>> productsForDepartmentDataLoader = DataLoaderFactory.newDataLoader(productsForDepartmentsBatchLoader);

public DataFetcher<CompletableFuture<List<Product>>> productsForDepartmentDataLoaderDataFetcher = environment -> {
Department department = environment.getSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

import com.google.common.collect.ImmutableList;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
Expand All @@ -27,7 +26,7 @@ public DataLoaderCompanyProductBackend(int companyCount, int projectCount) {
mkCompany(projectCount);
}

projectsLoader = new DataLoader<>(keys -> getProjectsForCompanies(keys).thenApply(projects -> keys
projectsLoader = DataLoaderFactory.newDataLoader(keys -> getProjectsForCompanies(keys).thenApply(projects -> keys
.stream()
.map(companyId -> projects.stream()
.filter(project -> project.getCompanyId().equals(companyId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import graphql.execution.ExecutionContext
import graphql.execution.ExecutionStrategyParameters
import graphql.execution.instrumentation.ChainedInstrumentation
import graphql.execution.instrumentation.Instrumentation
import graphql.execution.instrumentation.InstrumentationState
import graphql.execution.instrumentation.SimpleInstrumentation
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters
import graphql.schema.DataFetcher
Expand Down Expand Up @@ -132,7 +133,7 @@ class DataLoaderDispatcherInstrumentationTest extends Specification {
def dlInstrumentation = new DataLoaderDispatcherInstrumentation()
def enhancingInstrumentation = new SimpleInstrumentation() {
@Override
ExecutionInput instrumentExecutionInput(ExecutionInput executionInput, InstrumentationExecutionParameters parameters) {
ExecutionInput instrumentExecutionInput(ExecutionInput executionInput, InstrumentationExecutionParameters parameters, InstrumentationState state) {
assert executionInput.getDataLoaderRegistry() == startingDataLoaderRegistry
return executionInput.transform({ builder -> builder.dataLoaderRegistry(enhancedDataLoaderRegistry) })
}
Expand Down
Loading