Skip to content

Commit 4a7c77d

Browse files
committed
Distinguish between null and non-null default values
1 parent 52d8175 commit 4a7c77d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

include/Validation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using ValidateType = response::Value;
1616
struct ValidateArgument
1717
{
1818
bool defaultValue = false;
19+
bool nonNullDefaultValue = false;
1920
ValidateType type;
2021
};
2122

src/Validation.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ void ValidateExecutableVisitor::visitOperationDefinition(const peg::ast_node& op
928928
}
929929

930930
variableArgument.defaultValue = true;
931+
variableArgument.nonNullDefaultValue = argument.value != nullptr;
931932
}
932933
}
933934

@@ -1068,6 +1069,8 @@ ValidateTypeFieldArguments ValidateExecutableVisitor::getArguments(response::Lis
10681069

10691070
argument.defaultValue = (itrDefaultValue != members.end()
10701071
&& itrDefaultValue->second.type() == response::Type::String);
1072+
argument.nonNullDefaultValue = argument.defaultValue
1073+
&& itrDefaultValue->second.get<response::StringType>() != R"gql(null)gql";
10711074
argument.type = std::move(itrType->second);
10721075

10731076
result[itrName->second.release<response::StringType>()] = std::move(argument);
@@ -1159,7 +1162,7 @@ bool ValidateExecutableVisitor::validateInputValue(bool hasNonNullDefaultValue,
11591162

11601163
_referencedVariables.insert(variable.name);
11611164

1162-
return validateVariableType(hasNonNullDefaultValue || itrVariable->second.defaultValue, itrVariable->second.type, argument.position, type);
1165+
return validateVariableType(hasNonNullDefaultValue || itrVariable->second.nonNullDefaultValue, itrVariable->second.type, argument.position, type);
11631166
}
11641167
else
11651168
{
@@ -1299,7 +1302,7 @@ bool ValidateExecutableVisitor::validateInputValue(bool hasNonNullDefaultValue,
12991302
if (entry.second.value
13001303
|| !itrField->second.defaultValue)
13011304
{
1302-
if (!validateInputValue(itrField->second.defaultValue, entry.second, itrField->second.type))
1305+
if (!validateInputValue(itrField->second.nonNullDefaultValue, entry.second, itrField->second.type))
13031306
{
13041307
// Error messages are added in the recursive call, so just bubble up the result.
13051308
return false;
@@ -2210,7 +2213,7 @@ void ValidateExecutableVisitor::visitField(const peg::ast_node& field)
22102213
&& itrArgument->second.value)
22112214
{
22122215
// The value was not null.
2213-
if (!validateInputValue(argument.second.defaultValue, itrArgument->second, argument.second.type))
2216+
if (!validateInputValue(argument.second.nonNullDefaultValue, itrArgument->second, argument.second.type))
22142217
{
22152218
// http://spec.graphql.org/June2018/#sec-Values-of-Correct-Type
22162219
std::ostringstream message;
@@ -2588,7 +2591,7 @@ void ValidateExecutableVisitor::visitDirectives(introspection::DirectiveLocation
25882591
&& itrArgument->second.value)
25892592
{
25902593
// The value was not null.
2591-
if (!validateInputValue(argument.second.defaultValue, itrArgument->second, argument.second.type))
2594+
if (!validateInputValue(argument.second.nonNullDefaultValue, itrArgument->second, argument.second.type))
25922595
{
25932596
// http://spec.graphql.org/June2018/#sec-Values-of-Correct-Type
25942597
std::ostringstream message;

0 commit comments

Comments
 (0)