Skip to content

Commit b456137

Browse files
authored
Merge pull request #124 from wravery/master
Add a default template argument to ModifiedArgument<T>::find<...>
2 parents 997e6f9 + 590bf51 commit b456137

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

include/graphqlservice/GraphQLService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ struct ModifiedArgument
423423
}
424424

425425
// Wrap require with modifiers in a try/catch block.
426-
template <TypeModifier Modifier, TypeModifier... Other>
426+
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
427427
static std::pair<typename ArgumentTraits<Type, Modifier, Other...>::type, bool> find(
428428
const std::string& name, const response::Value& arguments) noexcept
429429
{

test/ArgumentTests.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,43 @@ TEST(ArgumentsCase, ScalarArgumentString)
291291
ASSERT_EQ(response::Type::String, actual.type()) << "should parse the object";
292292
ASSERT_EQ("foobar", actual.get<response::StringType>()) << "should match the value";
293293
}
294+
295+
TEST(ArgumentsCase, FindArgumentNoTemplateArguments)
296+
{
297+
response::Value response(response::Type::Map);
298+
response.emplace_back("scalar", response::Value("foobar"));
299+
std::pair<response::Value, bool> actual { {}, false };
300+
301+
try
302+
{
303+
actual = service::ModifiedArgument<response::Value>::find("scalar", response);
304+
}
305+
catch (service::schema_exception& ex)
306+
{
307+
FAIL() << response::toJSON(ex.getErrors());
308+
}
309+
310+
ASSERT_TRUE(actual.second) << "should find the argument";
311+
ASSERT_EQ(response::Type::String, actual.first.type()) << "should parse the object";
312+
ASSERT_EQ("foobar", actual.first.get<response::StringType>()) << "should match the value";
313+
}
314+
315+
TEST(ArgumentsCase, FindArgumentEmptyTemplateArgs)
316+
{
317+
response::Value response(response::Type::Map);
318+
response.emplace_back("scalar", response::Value("foobar"));
319+
std::pair<response::Value, bool> actual { {}, false };
320+
321+
try
322+
{
323+
actual = service::ModifiedArgument<response::Value>::find<>("scalar", response);
324+
}
325+
catch (service::schema_exception& ex)
326+
{
327+
FAIL() << response::toJSON(ex.getErrors());
328+
}
329+
330+
ASSERT_TRUE(actual.second) << "should find the argument";
331+
ASSERT_EQ(response::Type::String, actual.first.type()) << "should parse the object";
332+
ASSERT_EQ("foobar", actual.first.get<response::StringType>()) << "should match the value";
333+
}

0 commit comments

Comments
 (0)