Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This will validate @oneOf variable values when the variables are coerced #3580

Merged
merged 2 commits into from
Jun 4, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/main/java/graphql/execution/ValuesResolverConversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ static CoercedVariables externalValueToInternalValueForVariables(
coercedValues.put(variableName, null);
} else {
Object coercedValue = externalValueToInternalValueImpl(
variableName,
inputInterceptor,
fieldVisibility,
variableInputType,
Expand All @@ -398,11 +399,28 @@ static CoercedVariables externalValueToInternalValueForVariables(
return CoercedVariables.of(coercedValues);
}

static Object externalValueToInternalValueImpl(
InputInterceptor inputInterceptor,
GraphqlFieldVisibility fieldVisibility,
GraphQLInputType graphQLType,
Object originalValue,
GraphQLContext graphqlContext,
Locale locale
) throws NonNullableValueCoercedAsNullException, CoercingParseValueException {
return externalValueToInternalValueImpl("externalValue",
inputInterceptor,
fieldVisibility,
graphQLType,
originalValue,
graphqlContext,
locale);
}

/**
* Performs validation too
*/
@SuppressWarnings("unchecked")
static Object externalValueToInternalValueImpl(
String variableName,
Copy link
Member Author

Choose a reason for hiding this comment

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

needed to add a variable name for error message reasons

InputInterceptor inputInterceptor,
GraphqlFieldVisibility fieldVisibility,
GraphQLInputType graphQLType,
Expand All @@ -412,6 +430,7 @@ static Object externalValueToInternalValueImpl(
) throws NonNullableValueCoercedAsNullException, CoercingParseValueException {
if (isNonNull(graphQLType)) {
Object returnValue = externalValueToInternalValueImpl(
variableName,
inputInterceptor,
fieldVisibility,
unwrapOneAs(graphQLType),
Expand Down Expand Up @@ -458,13 +477,18 @@ static Object externalValueToInternalValueImpl(
locale);
} else if (graphQLType instanceof GraphQLInputObjectType) {
if (value instanceof Map) {
return externalValueToInternalValueForObject(
GraphQLInputObjectType inputObjectType = (GraphQLInputObjectType) graphQLType;
//noinspection unchecked
Map<String, Object> coercedMap = externalValueToInternalValueForObject(
inputInterceptor,
fieldVisibility,
(GraphQLInputObjectType) graphQLType,
inputObjectType,
(Map<String, Object>) value,
graphqlContext,
locale);

ValuesResolverOneOfValidation.validateOneOfInputTypes(inputObjectType, coercedMap, null, variableName, locale);
return coercedMap;
} else {
throw CoercingParseValueException.newCoercingParseValueException()
.message("Expected type 'Map' but was '" + value.getClass().getSimpleName() +
Expand All @@ -479,7 +503,7 @@ static Object externalValueToInternalValueImpl(
/**
* performs validation
*/
private static Object externalValueToInternalValueForObject(
private static Map<String, Object> externalValueToInternalValueForObject(
InputInterceptor inputInterceptor,
GraphqlFieldVisibility fieldVisibility,
GraphQLInputObjectType inputObjectType,
Expand Down