Skip to content

Commit 4e106d6

Browse files
authored
Merge pull request #3580 from graphql-java/coerced-oneof-variables-are-validated
This will validate @OneOf variable values when the variables are coerced
2 parents 5772848 + 6044ec4 commit 4e106d6

3 files changed

Lines changed: 211 additions & 119 deletions

File tree

src/main/java/graphql/execution/ValuesResolverConversion.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ static CoercedVariables externalValueToInternalValueForVariables(
374374
coercedValues.put(variableName, null);
375375
} else {
376376
Object coercedValue = externalValueToInternalValueImpl(
377+
variableName,
377378
inputInterceptor,
378379
fieldVisibility,
379380
variableInputType,
@@ -398,11 +399,28 @@ static CoercedVariables externalValueToInternalValueForVariables(
398399
return CoercedVariables.of(coercedValues);
399400
}
400401

402+
static Object externalValueToInternalValueImpl(
403+
InputInterceptor inputInterceptor,
404+
GraphqlFieldVisibility fieldVisibility,
405+
GraphQLInputType graphQLType,
406+
Object originalValue,
407+
GraphQLContext graphqlContext,
408+
Locale locale
409+
) throws NonNullableValueCoercedAsNullException, CoercingParseValueException {
410+
return externalValueToInternalValueImpl("externalValue",
411+
inputInterceptor,
412+
fieldVisibility,
413+
graphQLType,
414+
originalValue,
415+
graphqlContext,
416+
locale);
417+
}
418+
401419
/**
402420
* Performs validation too
403421
*/
404-
@SuppressWarnings("unchecked")
405422
static Object externalValueToInternalValueImpl(
423+
String variableName,
406424
InputInterceptor inputInterceptor,
407425
GraphqlFieldVisibility fieldVisibility,
408426
GraphQLInputType graphQLType,
@@ -412,6 +430,7 @@ static Object externalValueToInternalValueImpl(
412430
) throws NonNullableValueCoercedAsNullException, CoercingParseValueException {
413431
if (isNonNull(graphQLType)) {
414432
Object returnValue = externalValueToInternalValueImpl(
433+
variableName,
415434
inputInterceptor,
416435
fieldVisibility,
417436
unwrapOneAs(graphQLType),
@@ -458,13 +477,18 @@ static Object externalValueToInternalValueImpl(
458477
locale);
459478
} else if (graphQLType instanceof GraphQLInputObjectType) {
460479
if (value instanceof Map) {
461-
return externalValueToInternalValueForObject(
480+
GraphQLInputObjectType inputObjectType = (GraphQLInputObjectType) graphQLType;
481+
//noinspection unchecked
482+
Map<String, Object> coercedMap = externalValueToInternalValueForObject(
462483
inputInterceptor,
463484
fieldVisibility,
464-
(GraphQLInputObjectType) graphQLType,
485+
inputObjectType,
465486
(Map<String, Object>) value,
466487
graphqlContext,
467488
locale);
489+
490+
ValuesResolverOneOfValidation.validateOneOfInputTypes(inputObjectType, coercedMap, null, variableName, locale);
491+
return coercedMap;
468492
} else {
469493
throw CoercingParseValueException.newCoercingParseValueException()
470494
.message("Expected type 'Map' but was '" + value.getClass().getSimpleName() +
@@ -479,7 +503,7 @@ static Object externalValueToInternalValueImpl(
479503
/**
480504
* performs validation
481505
*/
482-
private static Object externalValueToInternalValueForObject(
506+
private static Map<String, Object> externalValueToInternalValueForObject(
483507
InputInterceptor inputInterceptor,
484508
GraphqlFieldVisibility fieldVisibility,
485509
GraphQLInputObjectType inputObjectType,

0 commit comments

Comments
 (0)