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
7 changes: 0 additions & 7 deletions src/main/java/graphql/GraphQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import graphql.execution.preparsed.NoOpPreparsedDocumentProvider;
import graphql.execution.preparsed.PreparsedDocumentEntry;
import graphql.execution.preparsed.PreparsedDocumentProvider;
import graphql.introspection.GoodFaithIntrospection;
import graphql.language.Document;
import graphql.schema.GraphQLSchema;
import graphql.validation.GoodFaithIntrospectionExceeded;
Expand Down Expand Up @@ -611,12 +610,6 @@ private List<ValidationError> validate(ExecutionInput executionInput, Document d
Locale locale = executionInput.getLocale();
QueryComplexityLimits limits = executionInput.getGraphQLContext().get(QueryComplexityLimits.KEY);

// Good Faith Introspection: disable the rule if good faith is off
if (!GoodFaithIntrospection.isEnabled(executionInput.getGraphQLContext())) {
Predicate<OperationValidationRule> existing = validationRulePredicate;
validationRulePredicate = rule -> rule != OperationValidationRule.GOOD_FAITH_INTROSPECTION && existing.test(rule);
}

List<ValidationError> validationErrors = ParseAndValidate.validate(graphQLSchema, document, validationRulePredicate, locale, limits);

validationCtx.onCompleted(validationErrors, null);
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/graphql/GraphQLUnusualConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import graphql.execution.ResponseMapFactory;
import graphql.execution.incremental.IncrementalExecutionContextKeys;
import graphql.introspection.GoodFaithIntrospection;
import graphql.parser.ParserOptions;
import graphql.schema.PropertyDataFetcherHelper;

Expand Down Expand Up @@ -37,14 +36,6 @@ public PropertyDataFetcherConfig propertyDataFetching() {
return new PropertyDataFetcherConfig(this);
}

/**
* @return an element that allows you to control JVM wide configuration
* of {@link graphql.introspection.GoodFaithIntrospection}
*/
public GoodFaithIntrospectionConfig goodFaithIntrospection() {
return new GoodFaithIntrospectionConfig(this);
}

private static class BaseConfig {
protected final GraphQLUnusualConfiguration configuration;

Expand Down Expand Up @@ -208,31 +199,6 @@ public boolean setUseNegativeCache(boolean flag) {
}
}

public static class GoodFaithIntrospectionConfig extends BaseConfig {
private GoodFaithIntrospectionConfig(GraphQLUnusualConfiguration configuration) {
super(configuration);
}

/**
* @return true if good faith introspection is enabled
*/
public boolean isEnabledJvmWide() {
return GoodFaithIntrospection.isEnabledJvmWide();
}

/**
* This allows you to disable good faith introspection, which is on by default.
*
* @param enabled the desired state
*
* @return the previous state
*/
public GoodFaithIntrospectionConfig enabledJvmWide(boolean enabled) {
GoodFaithIntrospection.enabledJvmWide(enabled);
return this;
}
}

/*
* ===============================================
* Per GraphqlContext code down here
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/graphql/ParseAndValidate.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ public class ParseAndValidate {
* for execution.
*
* @param graphQLSchema the schema to validate against
* @param executionInput the execution input containing the query
* @param executionInput the execution input containing the query and request-specific complexity limits
*
* @return a result object that indicates how this operation went
*/
public static ParseAndValidateResult parseAndValidate(@NonNull GraphQLSchema graphQLSchema, @NonNull ExecutionInput executionInput) {
ParseAndValidateResult result = parse(executionInput);
if (!result.isFailure()) {
List<ValidationError> errors = validate(graphQLSchema, assertNotNull(result.getDocument(), "Parse result document cannot be null when parse succeeded"), executionInput.getLocale());
QueryComplexityLimits limits = executionInput.getGraphQLContext().get(QueryComplexityLimits.KEY);
List<ValidationError> errors = validate(graphQLSchema, assertNotNull(result.getDocument(), "Parse result document cannot be null when parse succeeded"),
rule -> true, executionInput.getLocale(), limits);
return result.transform(builder -> builder.validationErrors(errors));
}
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package graphql.introspection;

import graphql.ErrorClassification;
import graphql.GraphQLError;
import graphql.PublicApi;
import graphql.language.SourceLocation;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

import java.util.List;

/**
* Error returned when an operation exceeds the introspection protections configured through
* {@link graphql.validation.QueryComplexityLimits}. Its classification is {@code BadFaithIntrospection}.
*/
@PublicApi
@NullMarked
public class BadFaithIntrospectionError implements GraphQLError {
private final String message;

/**
* @param fieldCoordinate the restricted coordinate selected more than once
* @return an error identifying the repeated coordinate
*/
public static BadFaithIntrospectionError tooManyFields(String fieldCoordinate) {
return new BadFaithIntrospectionError(String.format("This request is not asking for introspection in good faith - %s is present too often!", fieldCoordinate));
}

/**
* @param message the exceeded merged-field or depth limit
* @return an error describing the exceeded introspection limit
*/
public static BadFaithIntrospectionError tooBigOperation(String message) {
return new BadFaithIntrospectionError(String.format("This request is not asking for introspection in good faith - the query is too big: %s", message));
}

private BadFaithIntrospectionError(String message) {
this.message = message;
}

@Override
public String getMessage() {
return message;
}

@Override
public ErrorClassification getErrorType() {
return ErrorClassification.errorClassification("BadFaithIntrospection");
}

@Override
public @Nullable List<SourceLocation> getLocations() {
return null;
}

@Override
public String toString() {
return "BadFaithIntrospectionError{" +
"message='" + message + '\'' +
'}';
}
}
153 changes: 0 additions & 153 deletions src/main/java/graphql/introspection/GoodFaithIntrospection.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package graphql.validation;

import graphql.Internal;
import graphql.introspection.GoodFaithIntrospection;
import graphql.introspection.BadFaithIntrospectionError;
import org.jspecify.annotations.NullMarked;

/**
* Exception thrown when a good-faith introspection check fails during validation.
* This exception is NOT caught by the Validator — it propagates up to GraphQL.parseAndValidate()
* where it is converted to a {@link GoodFaithIntrospection.BadFaithIntrospectionError}.
* where it is converted to a {@link BadFaithIntrospectionError}.
*/
@Internal
@NullMarked
Expand All @@ -30,11 +30,11 @@ public static GoodFaithIntrospectionExceeded tooBigOperation(String message) {
return new GoodFaithIntrospectionExceeded(true, message);
}

public GoodFaithIntrospection.BadFaithIntrospectionError toBadFaithError() {
public BadFaithIntrospectionError toBadFaithError() {
if (tooBig) {
return GoodFaithIntrospection.BadFaithIntrospectionError.tooBigOperation(detail);
return BadFaithIntrospectionError.tooBigOperation(detail);
}
return GoodFaithIntrospection.BadFaithIntrospectionError.tooManyFields(detail);
return BadFaithIntrospectionError.tooManyFields(detail);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package graphql.validation;

import graphql.Internal;
import graphql.introspection.GoodFaithIntrospection;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

Expand Down Expand Up @@ -30,8 +29,8 @@ public final class MergedFieldComplexityCounts {

public MergedFieldComplexityCounts(QueryComplexityLimits limits, boolean introspection) {
this.introspection = introspection;
maxMergedFieldCount = introspection ? Math.min(limits.getMaxMergedFieldCount(), GoodFaithIntrospection.GOOD_FAITH_MAX_MERGED_FIELD_COUNT) : limits.getMaxMergedFieldCount();
maxDepth = introspection ? Math.min(limits.getMaxDepth(), GoodFaithIntrospection.GOOD_FAITH_MAX_DEPTH_COUNT) : limits.getMaxDepth();
maxMergedFieldCount = introspection ? Math.min(limits.getMaxMergedFieldCount(), limits.getMaxIntrospectionMergedFieldCount()) : limits.getMaxMergedFieldCount();
maxDepth = introspection ? Math.min(limits.getMaxDepth(), limits.getMaxIntrospectionDepth()) : limits.getMaxDepth();
}

public void enterField(@Nullable String coordinate) {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/graphql/validation/OperationValidationRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,4 @@ public enum OperationValidationRule {

/** Defer directive must not be used in subscription operations. Requires operation context. */
DEFER_DIRECTIVE_ON_VALID_OPERATION,

/** Good faith introspection check. */
GOOD_FAITH_INTROSPECTION,
}
4 changes: 2 additions & 2 deletions src/main/java/graphql/validation/OperationValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ private void checkOperationDefinition(OperationDefinition operationDefinition) {
fieldOccurrences = 0;

if (generalMergedLimitsEnabled || isRuleEnabled(OperationValidationRule.OVERLAPPING_FIELDS_CAN_BE_MERGED)
|| isRuleEnabled(OperationValidationRule.GOOD_FAITH_INTROSPECTION)) {
|| complexityLimits.isIntrospectionLimitsEnabled()) {
validateOverlappingFieldsCanBeMerged(operationDefinition);
}
if (isRuleEnabled(OperationValidationRule.LONE_ANONYMOUS_OPERATION)) {
Expand Down Expand Up @@ -1361,7 +1361,7 @@ private void overlappingFieldsImpl(SelectionSet selectionSet, @Nullable GraphQLO
Map<String, Set<FieldAndType>> fieldMap = new LinkedHashMap<>(selectionSet.getSelections().size());
Set<String> visitedFragments = new LinkedHashSet<>();
overlappingFields_collectFields(fieldMap, selectionSet, graphQLOutputType, visitedFragments);
if (isRuleEnabled(OperationValidationRule.GOOD_FAITH_INTROSPECTION) && containsIntrospection(fieldMap, graphQLOutputType)) {
if (complexityLimits.isIntrospectionLimitsEnabled() && containsIntrospection(fieldMap, graphQLOutputType)) {
introspectionQueryDetected = true;
}
if (generalMergedLimitsEnabled || introspectionQueryDetected) {
Expand Down
Loading
Loading