X Tutup
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
22 changes: 22 additions & 0 deletions src/main/java/graphql/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public static <T> T assertNotNullWithNPE(T object, Supplier<String> msg) {
throw new NullPointerException(msg.get());
}

public static <T> T assertNotNullWithNPE(T object, String constantMsg) {
if (object != null) {
return object;
}
throw new NullPointerException(constantMsg);
}

@Contract("null -> fail")
public static <T> T assertNotNull(@Nullable T object) {
if (object != null) {
Expand Down Expand Up @@ -78,6 +85,14 @@ public static <T> void assertNull(@Nullable T object, Supplier<String> msg) {
throwAssert(msg.get());
}

@Contract("!null,_ -> fail")
public static <T> void assertNull(@Nullable T object, String constantMsg) {
if (object == null) {
return;
}
throwAssert(constantMsg);
}

@Contract("!null -> fail")
public static <T> void assertNull(@Nullable Object object) {
if (object == null) {
Expand Down Expand Up @@ -116,6 +131,13 @@ public static <T> Collection<T> assertNotEmpty(Collection<T> collection, Supplie
return collection;
}

public static <T> Collection<T> assertNotEmpty(Collection<T> collection, String constantMsg) {
if (collection == null || collection.isEmpty()) {
throwAssert(constantMsg);
}
return collection;
}

public static void assertTrue(boolean condition, Supplier<String> msg) {
if (condition) {
return;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/graphql/DirectivesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ public static boolean isAllNonRepeatable(List<GraphQLDirective> directives) {

@Deprecated(since = "2022-02-24") // use GraphQLAppliedDirectives eventually
public static List<GraphQLDirective> add(List<GraphQLDirective> targetList, GraphQLDirective newDirective) {
assertNotNull(targetList, () -> "directive list can't be null");
assertNotNull(newDirective, () -> "directive can't be null");
assertNotNull(targetList, "directive list can't be null");
assertNotNull(newDirective, "directive can't be null");
targetList.add(newDirective);
return targetList;
}

@Deprecated(since = "2022-02-24") // use GraphQLAppliedDirectives eventually
public static List<GraphQLDirective> addAll(List<GraphQLDirective> targetList, List<GraphQLDirective> newDirectives) {
assertNotNull(targetList, () -> "directive list can't be null");
assertNotNull(newDirectives, () -> "directive list can't be null");
assertNotNull(targetList, "directive list can't be null");
assertNotNull(newDirectives, "directive list can't be null");
targetList.addAll(newDirectives);
return targetList;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/graphql/ExecutionInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static String assertQuery(Builder builder) {
return PERSISTED_QUERY_MARKER;
}

return assertNotNull(builder.query, () -> "query can't be null");
return assertNotNull(builder.query, "query can't be null");
}

/**
Expand Down Expand Up @@ -432,13 +432,13 @@ public Builder root(Object root) {
* @return this builder
*/
public Builder variables(Map<String, Object> rawVariables) {
assertNotNull(rawVariables, () -> "variables map can't be null");
assertNotNull(rawVariables, "variables map can't be null");
this.rawVariables = RawVariables.of(rawVariables);
return this;
}

public Builder extensions(Map<String, Object> extensions) {
this.extensions = assertNotNull(extensions, () -> "extensions map can't be null");
this.extensions = assertNotNull(extensions, "extensions map can't be null");
return this;
}

Expand Down
32 changes: 16 additions & 16 deletions src/main/java/graphql/GraphQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ public static GraphQLUnusualConfiguration.GraphQLContextConfiguration unusualCon


private GraphQL(Builder builder) {
this.graphQLSchema = assertNotNull(builder.graphQLSchema, () -> "graphQLSchema must be non null");
this.queryStrategy = assertNotNull(builder.queryExecutionStrategy, () -> "queryStrategy must not be null");
this.mutationStrategy = assertNotNull(builder.mutationExecutionStrategy, () -> "mutationStrategy must not be null");
this.subscriptionStrategy = assertNotNull(builder.subscriptionExecutionStrategy, () -> "subscriptionStrategy must not be null");
this.idProvider = assertNotNull(builder.idProvider, () -> "idProvider must be non null");
this.instrumentation = assertNotNull(builder.instrumentation, () -> "instrumentation must not be null");
this.preparsedDocumentProvider = assertNotNull(builder.preparsedDocumentProvider, () -> "preparsedDocumentProvider must be non null");
this.valueUnboxer = assertNotNull(builder.valueUnboxer, () -> "valueUnboxer must not be null");
this.graphQLSchema = assertNotNull(builder.graphQLSchema, "graphQLSchema must be non null");
this.queryStrategy = assertNotNull(builder.queryExecutionStrategy, "queryStrategy must not be null");
this.mutationStrategy = assertNotNull(builder.mutationExecutionStrategy, "mutationStrategy must not be null");
this.subscriptionStrategy = assertNotNull(builder.subscriptionExecutionStrategy, "subscriptionStrategy must not be null");
this.idProvider = assertNotNull(builder.idProvider, "idProvider must be non null");
this.instrumentation = assertNotNull(builder.instrumentation, "instrumentation must not be null");
this.preparsedDocumentProvider = assertNotNull(builder.preparsedDocumentProvider, "preparsedDocumentProvider must be non null");
this.valueUnboxer = assertNotNull(builder.valueUnboxer, "valueUnboxer must not be null");
this.doNotAutomaticallyDispatchDataLoader = builder.doNotAutomaticallyDispatchDataLoader;
}

Expand Down Expand Up @@ -288,22 +288,22 @@ public Builder(GraphQLSchema graphQLSchema) {
}

public Builder schema(GraphQLSchema graphQLSchema) {
this.graphQLSchema = assertNotNull(graphQLSchema, () -> "GraphQLSchema must be non null");
this.graphQLSchema = assertNotNull(graphQLSchema, "GraphQLSchema must be non null");
return this;
}

public Builder queryExecutionStrategy(ExecutionStrategy executionStrategy) {
this.queryExecutionStrategy = assertNotNull(executionStrategy, () -> "Query ExecutionStrategy must be non null");
this.queryExecutionStrategy = assertNotNull(executionStrategy, "Query ExecutionStrategy must be non null");
return this;
}

public Builder mutationExecutionStrategy(ExecutionStrategy executionStrategy) {
this.mutationExecutionStrategy = assertNotNull(executionStrategy, () -> "Mutation ExecutionStrategy must be non null");
this.mutationExecutionStrategy = assertNotNull(executionStrategy, "Mutation ExecutionStrategy must be non null");
return this;
}

public Builder subscriptionExecutionStrategy(ExecutionStrategy executionStrategy) {
this.subscriptionExecutionStrategy = assertNotNull(executionStrategy, () -> "Subscription ExecutionStrategy must be non null");
this.subscriptionExecutionStrategy = assertNotNull(executionStrategy, "Subscription ExecutionStrategy must be non null");
return this;
}

Expand All @@ -316,22 +316,22 @@ public Builder subscriptionExecutionStrategy(ExecutionStrategy executionStrategy
* @return this builder
*/
public Builder defaultDataFetcherExceptionHandler(DataFetcherExceptionHandler dataFetcherExceptionHandler) {
this.defaultExceptionHandler = assertNotNull(dataFetcherExceptionHandler, () -> "The DataFetcherExceptionHandler must be non null");
this.defaultExceptionHandler = assertNotNull(dataFetcherExceptionHandler, "The DataFetcherExceptionHandler must be non null");
return this;
}

public Builder instrumentation(Instrumentation instrumentation) {
this.instrumentation = assertNotNull(instrumentation, () -> "Instrumentation must be non null");
this.instrumentation = assertNotNull(instrumentation, "Instrumentation must be non null");
return this;
}

public Builder preparsedDocumentProvider(PreparsedDocumentProvider preparsedDocumentProvider) {
this.preparsedDocumentProvider = assertNotNull(preparsedDocumentProvider, () -> "PreparsedDocumentProvider must be non null");
this.preparsedDocumentProvider = assertNotNull(preparsedDocumentProvider, "PreparsedDocumentProvider must be non null");
return this;
}

public Builder executionIdProvider(ExecutionIdProvider executionIdProvider) {
this.idProvider = assertNotNull(executionIdProvider, () -> "ExecutionIdProvider must be non null");
this.idProvider = assertNotNull(executionIdProvider, "ExecutionIdProvider must be non null");
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/graphql/GraphqlErrorBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public B extensions(@Nullable Map<String, Object> extensions) {
* @return a newly built GraphqlError
*/
public GraphQLError build() {
assertNotNull(message, () -> "You must provide error message");
assertNotNull(message, "You must provide error message");
return new GraphqlErrorImpl(message, locations, errorType, path, extensions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public MaxQueryComplexityInstrumentation(int maxComplexity, FieldComplexityCalcu
public MaxQueryComplexityInstrumentation(int maxComplexity, FieldComplexityCalculator fieldComplexityCalculator,
Function<QueryComplexityInfo, Boolean> maxQueryComplexityExceededFunction) {
this.maxComplexity = maxComplexity;
this.fieldComplexityCalculator = assertNotNull(fieldComplexityCalculator, () -> "calculator can't be null");
this.fieldComplexityCalculator = assertNotNull(fieldComplexityCalculator, "calculator can't be null");
this.maxQueryComplexityExceededFunction = maxQueryComplexityExceededFunction;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/graphql/analysis/QueryComplexityCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public class QueryComplexityCalculator {
private final CoercedVariables variables;

public QueryComplexityCalculator(Builder builder) {
this.fieldComplexityCalculator = assertNotNull(builder.fieldComplexityCalculator, () -> "fieldComplexityCalculator can't be null");
this.schema = assertNotNull(builder.schema, () -> "schema can't be null");
this.document = assertNotNull(builder.document, () -> "document can't be null");
this.variables = assertNotNull(builder.variables, () -> "variables can't be null");
this.fieldComplexityCalculator = assertNotNull(builder.fieldComplexityCalculator, "fieldComplexityCalculator can't be null");
this.schema = assertNotNull(builder.schema, "schema can't be null");
this.document = assertNotNull(builder.document, "document can't be null");
this.variables = assertNotNull(builder.variables, "variables can't be null");
this.operationName = builder.operationName;
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/graphql/analysis/QueryTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ private QueryTransformer(GraphQLSchema schema,
Map<String, FragmentDefinition> fragmentsByName,
Map<String, Object> variables,
QueryTraversalOptions options) {
this.schema = assertNotNull(schema, () -> "schema can't be null");
this.variables = assertNotNull(variables, () -> "variables can't be null");
this.root = assertNotNull(root, () -> "root can't be null");
this.schema = assertNotNull(schema, "schema can't be null");
this.variables = assertNotNull(variables, "variables can't be null");
this.root = assertNotNull(root, "root can't be null");
this.rootParentType = assertNotNull(rootParentType);
this.fragmentsByName = assertNotNull(fragmentsByName, () -> "fragmentsByName can't be null");
this.options = assertNotNull(options, () -> "options can't be null");
this.fragmentsByName = assertNotNull(fragmentsByName, "fragmentsByName can't be null");
this.options = assertNotNull(options, "options can't be null");
}

/**
Expand Down Expand Up @@ -177,7 +177,7 @@ public Builder fragmentsByName(Map<String, FragmentDefinition> fragmentsByName)
* @return this builder
*/
public Builder options(QueryTraversalOptions options) {
this.options = assertNotNull(options, () -> "options can't be null");
this.options = assertNotNull(options, "options can't be null");
return this;
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/graphql/analysis/QueryTraverser.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static class Builder {
* @return this builder
*/
public Builder schema(GraphQLSchema schema) {
this.schema = assertNotNull(schema, () -> "schema can't be null");
this.schema = assertNotNull(schema, "schema can't be null");
return this;
}

Expand All @@ -264,7 +264,7 @@ public Builder operationName(String operationName) {
* @return this builder
*/
public Builder document(Document document) {
this.document = assertNotNull(document, () -> "document can't be null");
this.document = assertNotNull(document, "document can't be null");
return this;
}

Expand All @@ -276,7 +276,7 @@ public Builder document(Document document) {
* @return this builder
*/
public Builder variables(Map<String, Object> variables) {
assertNotNull(variables, () -> "variables can't be null");
assertNotNull(variables, "variables can't be null");
this.rawVariables = RawVariables.of(variables);
return this;
}
Expand All @@ -289,7 +289,7 @@ public Builder variables(Map<String, Object> variables) {
* @return this builder
*/
public Builder coercedVariables(CoercedVariables coercedVariables) {
assertNotNull(coercedVariables, () -> "coercedVariables can't be null");
assertNotNull(coercedVariables, "coercedVariables can't be null");
this.coercedVariables = coercedVariables;
return this;
}
Expand All @@ -303,7 +303,7 @@ public Builder coercedVariables(CoercedVariables coercedVariables) {
* @return this builder
*/
public Builder root(Node root) {
this.root = assertNotNull(root, () -> "root can't be null");
this.root = assertNotNull(root, "root can't be null");
return this;
}

Expand All @@ -315,7 +315,7 @@ public Builder root(Node root) {
* @return this builder
*/
public Builder rootParentType(GraphQLCompositeType rootParentType) {
this.rootParentType = assertNotNull(rootParentType, () -> "rootParentType can't be null");
this.rootParentType = assertNotNull(rootParentType, "rootParentType can't be null");
return this;
}

Expand All @@ -327,7 +327,7 @@ public Builder rootParentType(GraphQLCompositeType rootParentType) {
* @return this builder
*/
public Builder fragmentsByName(Map<String, FragmentDefinition> fragmentsByName) {
this.fragmentsByName = assertNotNull(fragmentsByName, () -> "fragmentsByName can't be null");
this.fragmentsByName = assertNotNull(fragmentsByName, "fragmentsByName can't be null");
return this;
}

Expand All @@ -338,7 +338,7 @@ public Builder fragmentsByName(Map<String, FragmentDefinition> fragmentsByName)
* @return this builder
*/
public Builder options(QueryTraversalOptions options) {
this.options = assertNotNull(options, () -> "options can't be null");
this.options = assertNotNull(options, "options can't be null");
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/graphql/analysis/values/ValueTraverser.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private static Object visitPreOrderImpl(Object coercedValue, GraphQLInputType st

private static Object visitObjectValue(Object coercedValue, GraphQLInputObjectType inputObjectType, InputElements containingElements, ValueVisitor visitor) {
if (coercedValue != null) {
assertTrue(coercedValue instanceof Map, () -> "A input object type MUST have an Map<String,Object> value");
assertTrue(coercedValue instanceof Map, "A input object type MUST have an Map<String,Object> value");
}
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) coercedValue;
Expand Down Expand Up @@ -265,7 +265,7 @@ private static Object visitObjectValue(Object coercedValue, GraphQLInputObjectTy

private static Object visitListValue(Object coercedValue, GraphQLList listInputType, InputElements containingElements, ValueVisitor visitor) {
if (coercedValue != null) {
assertTrue(coercedValue instanceof List, () -> "A list type MUST have an List value");
assertTrue(coercedValue instanceof List, "A list type MUST have an List value");
}
@SuppressWarnings("unchecked")
List<Object> list = (List<Object>) coercedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public ExecutionContextBuilder propagapropagateErrorsOnNonNullContractFailureeEr

public ExecutionContext build() {
// preconditions
assertNotNull(executionId, () -> "You must provide a query identifier");
assertNotNull(executionId, "You must provide a query identifier");
return new ExecutionContext(this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/graphql/execution/ExecutionId.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static ExecutionId from(String id) {
private final String id;

private ExecutionId(String id) {
Assert.assertNotNull(id, () -> "You must provided a non null id");
Assert.assertNotNull(id, "You must provided a non null id");
this.id = id;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/graphql/execution/ExecutionStepInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private ExecutionStepInfo(Builder builder) {
this.field = builder.field;
this.path = builder.path;
this.parent = builder.parentInfo;
this.type = assertNotNull(builder.type, () -> "you must provide a graphql type");
this.type = assertNotNull(builder.type, "you must provide a graphql type");
this.arguments = builder.arguments;
this.fieldContainer = builder.fieldContainer;
}
Expand All @@ -88,7 +88,7 @@ private ExecutionStepInfo(GraphQLOutputType type,
GraphQLFieldDefinition fieldDefinition,
GraphQLObjectType fieldContainer,
Supplier<ImmutableMapWithNullValues<String, Object>> arguments) {
this.type = assertNotNull(type, () -> "you must provide a graphql type");
this.type = assertNotNull(type, "you must provide a graphql type");
this.path = path;
this.parent = parent;
this.field = field;
Expand Down Expand Up @@ -223,7 +223,7 @@ public boolean hasParent() {
* @return a new type info with the same
*/
public ExecutionStepInfo changeTypeWithPreservedNonNull(GraphQLOutputType newType) {
assertTrue(!GraphQLTypeUtil.isNonNull(newType), () -> "newType can't be non null");
assertTrue(!GraphQLTypeUtil.isNonNull(newType), "newType can't be non null");
if (isNonNullType()) {
return transform(GraphQLNonNull.nonNull(newType));
} else {
Expand Down
Loading
Loading
X Tutup