Skip to content

Commit bd485ef

Browse files
committed
Fix #63
1 parent cedb2d2 commit bd485ef

File tree

9 files changed

+42
-38
lines changed

9 files changed

+42
-38
lines changed

include/graphqlservice/GraphQLService.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ namespace graphql::service {
2929
class schema_exception : public std::exception
3030
{
3131
public:
32-
schema_exception(std::vector<std::string>&& messages);
32+
schema_exception() = delete;
33+
schema_exception(const schema_exception&) = delete;
34+
explicit schema_exception(schema_exception&&) = default;
35+
36+
explicit schema_exception(std::vector<std::string>&& messages);
3337

3438
const char* what() const noexcept override;
3539

samples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ add_custom_target(update_samples ALL
3939
DEPENDS
4040
unified/TodaySchema.cpp
4141
separate/today_schema_files
42-
${SEPARATE_SCHEMA_CPP}
42+
${SEPARATE_SCHEMA_CPP}
4343
)
4444

4545
if(GRAPHQL_BUILD_TESTS)

samples/introspection/IntrospectionSchema.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ introspection::TypeKind ModifiedArgument<introspection::TypeKind>::convert(const
2929
{
3030
if (!value.maybe_enum())
3131
{
32-
throw service::schema_exception({ "not a valid __TypeKind value" });
32+
throw service::schema_exception { { "not a valid __TypeKind value" } };
3333
}
3434

3535
auto itr = std::find(s_namesTypeKind.cbegin(), s_namesTypeKind.cend(), value.get<const response::StringType&>());
3636

3737
if (itr == s_namesTypeKind.cend())
3838
{
39-
throw service::schema_exception({ "not a valid __TypeKind value" });
39+
throw service::schema_exception { { "not a valid __TypeKind value" } };
4040
}
4141

4242
return static_cast<introspection::TypeKind>(itr - s_namesTypeKind.cbegin());
@@ -82,14 +82,14 @@ introspection::DirectiveLocation ModifiedArgument<introspection::DirectiveLocati
8282
{
8383
if (!value.maybe_enum())
8484
{
85-
throw service::schema_exception({ "not a valid __DirectiveLocation value" });
85+
throw service::schema_exception { { "not a valid __DirectiveLocation value" } };
8686
}
8787

8888
auto itr = std::find(s_namesDirectiveLocation.cbegin(), s_namesDirectiveLocation.cend(), value.get<const response::StringType&>());
8989

9090
if (itr == s_namesDirectiveLocation.cend())
9191
{
92-
throw service::schema_exception({ "not a valid __DirectiveLocation value" });
92+
throw service::schema_exception { { "not a valid __DirectiveLocation value" } };
9393
}
9494

9595
return static_cast<introspection::DirectiveLocation>(itr - s_namesDirectiveLocation.cbegin());

samples/separate/TodaySchema.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ today::TaskState ModifiedArgument<today::TaskState>::convert(const response::Val
2727
{
2828
if (!value.maybe_enum())
2929
{
30-
throw service::schema_exception({ "not a valid TaskState value" });
30+
throw service::schema_exception { { "not a valid TaskState value" } };
3131
}
3232

3333
auto itr = std::find(s_namesTaskState.cbegin(), s_namesTaskState.cend(), value.get<const response::StringType&>());
3434

3535
if (itr == s_namesTaskState.cend())
3636
{
37-
throw service::schema_exception({ "not a valid TaskState value" });
37+
throw service::schema_exception { { "not a valid TaskState value" } };
3838
}
3939

4040
return static_cast<today::TaskState>(itr - s_namesTaskState.cbegin());

samples/today/SeparateToday.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ struct EdgeConstraints
236236
std::ostringstream error;
237237

238238
error << "Invalid argument: first value: " << *first;
239-
throw service::schema_exception({ error.str() });
239+
throw service::schema_exception { { error.str() } };
240240
}
241241

242242
if (itrLast - itrFirst > *first)
@@ -252,7 +252,7 @@ struct EdgeConstraints
252252
std::ostringstream error;
253253

254254
error << "Invalid argument: last value: " << *last;
255-
throw service::schema_exception({ error.str() });
255+
throw service::schema_exception { { error.str() } };
256256
}
257257

258258
if (itrLast - itrFirst > *last)

samples/today/UnifiedToday.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ struct EdgeConstraints
236236
std::ostringstream error;
237237

238238
error << "Invalid argument: first value: " << *first;
239-
throw service::schema_exception({ error.str() });
239+
throw service::schema_exception { { error.str() } };
240240
}
241241

242242
if (itrLast - itrFirst > *first)
@@ -252,7 +252,7 @@ struct EdgeConstraints
252252
std::ostringstream error;
253253

254254
error << "Invalid argument: last value: " << *last;
255-
throw service::schema_exception({ error.str() });
255+
throw service::schema_exception { { error.str() } };
256256
}
257257

258258
if (itrLast - itrFirst > *last)

samples/unified/TodaySchema.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ today::TaskState ModifiedArgument<today::TaskState>::convert(const response::Val
2727
{
2828
if (!value.maybe_enum())
2929
{
30-
throw service::schema_exception({ "not a valid TaskState value" });
30+
throw service::schema_exception { { "not a valid TaskState value" } };
3131
}
3232

3333
auto itr = std::find(s_namesTaskState.cbegin(), s_namesTaskState.cend(), value.get<const response::StringType&>());
3434

3535
if (itr == s_namesTaskState.cend())
3636
{
37-
throw service::schema_exception({ "not a valid TaskState value" });
37+
throw service::schema_exception { { "not a valid TaskState value" } };
3838
}
3939

4040
return static_cast<today::TaskState>(itr - s_namesTaskState.cbegin());

src/GraphQLService.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void ValueVisitor::visitVariable(const peg::ast_node & variable)
143143
<< " line: " << position.line
144144
<< " column: " << position.byte_in_line;
145145

146-
throw schema_exception({ error.str() });
146+
throw schema_exception { { error.str() } };
147147
}
148148

149149
_value = response::Value(itr->second);
@@ -304,7 +304,7 @@ bool DirectiveVisitor::shouldSkip() const
304304

305305
error << "Invalid arguments to directive: " << entry.second;
306306

307-
throw schema_exception({ error.str() });
307+
throw schema_exception { { error.str() } };
308308
}
309309

310310
bool argumentTrue = false;
@@ -322,7 +322,7 @@ bool DirectiveVisitor::shouldSkip() const
322322
error << "Invalid argument to directive: " << entry.second
323323
<< " name: " << argument.first;
324324

325-
throw schema_exception({ error.str() });
325+
throw schema_exception { { error.str() } };
326326
}
327327

328328
argumentTrue = argument.second.get<response::BooleanType>();
@@ -344,7 +344,7 @@ bool DirectiveVisitor::shouldSkip() const
344344
error << "Missing argument to directive: " << entry.second
345345
<< " name: if";
346346

347-
throw schema_exception({ error.str() });
347+
throw schema_exception { { error.str() } };
348348
}
349349
}
350350

@@ -399,7 +399,7 @@ uint8_t Base64::verifyFromBase64(char ch)
399399

400400
if (result > 63)
401401
{
402-
throw schema_exception({ "invalid character in base64 encoded string" });
402+
throw schema_exception { { "invalid character in base64 encoded string" } };
403403
}
404404

405405
return result;
@@ -446,7 +446,7 @@ std::vector<uint8_t> Base64::fromBase64(const char* encoded, size_t count)
446446
{
447447
if (tail & 0x3)
448448
{
449-
throw schema_exception({ "invalid padding at the end of a base64 encoded string" });
449+
throw schema_exception { { "invalid padding at the end of a base64 encoded string" } };
450450
}
451451

452452
result.emplace_back(static_cast<uint8_t>((segment & 0xFF00) >> 8));
@@ -459,7 +459,7 @@ std::vector<uint8_t> Base64::fromBase64(const char* encoded, size_t count)
459459
{
460460
if (segment & 0xFF)
461461
{
462-
throw schema_exception({ "invalid padding at the end of a base64 encoded string" });
462+
throw schema_exception { { "invalid padding at the end of a base64 encoded string" } };
463463
}
464464

465465
result.emplace_back(static_cast<uint8_t>((segment & 0xFF00) >> 8));
@@ -474,7 +474,7 @@ std::vector<uint8_t> Base64::fromBase64(const char* encoded, size_t count)
474474
|| (count > 1 && padding != encoded[1])
475475
|| count > 2)
476476
{
477-
throw schema_exception({ "invalid padding at the end of a base64 encoded string" });
477+
throw schema_exception { { "invalid padding at the end of a base64 encoded string" } };
478478
}
479479

480480
return result;
@@ -486,7 +486,7 @@ char Base64::verifyToBase64(uint8_t i)
486486

487487
if (result == padding)
488488
{
489-
throw schema_exception({ "invalid 6-bit value" });
489+
throw schema_exception { { "invalid 6-bit value" } };
490490
}
491491

492492
return result;
@@ -548,7 +548,7 @@ response::IntType ModifiedArgument<response::IntType>::convert(const response::V
548548
{
549549
if (value.type() != response::Type::Int)
550550
{
551-
throw schema_exception({ "not an integer" });
551+
throw schema_exception { { "not an integer" } };
552552
}
553553

554554
return value.get<response::IntType>();
@@ -559,7 +559,7 @@ response::FloatType ModifiedArgument<response::FloatType>::convert(const respons
559559
{
560560
if (value.type() != response::Type::Float)
561561
{
562-
throw schema_exception({ "not a float" });
562+
throw schema_exception { { "not a float" } };
563563
}
564564

565565
return value.get<response::FloatType>();
@@ -570,7 +570,7 @@ response::StringType ModifiedArgument<response::StringType>::convert(const respo
570570
{
571571
if (value.type() != response::Type::String)
572572
{
573-
throw schema_exception({ "not a string" });
573+
throw schema_exception { { "not a string" } };
574574
}
575575

576576
return value.get<const response::StringType&>();
@@ -581,7 +581,7 @@ response::BooleanType ModifiedArgument<response::BooleanType>::convert(const res
581581
{
582582
if (value.type() != response::Type::Boolean)
583583
{
584-
throw schema_exception({ "not a boolean" });
584+
throw schema_exception { { "not a boolean" } };
585585
}
586586

587587
return value.get<response::BooleanType>();
@@ -592,7 +592,7 @@ response::Value ModifiedArgument<response::Value>::convert(const response::Value
592592
{
593593
if (value.type() != response::Type::Map)
594594
{
595-
throw schema_exception({ "not an object" });
595+
throw schema_exception { { "not an object" } };
596596
}
597597

598598
return response::Value(value);
@@ -603,7 +603,7 @@ response::IdType ModifiedArgument<response::IdType>::convert(const response::Val
603603
{
604604
if (value.type() != response::Type::String)
605605
{
606-
throw schema_exception({ "not a string" });
606+
throw schema_exception { { "not a string" } };
607607
}
608608

609609
const auto& encoded = value.get<const response::StringType&>();
@@ -806,7 +806,7 @@ void SelectionVisitor::visitField(const peg::ast_node & field)
806806
<< " line: " << position.line
807807
<< " column: " << position.byte_in_line;
808808

809-
throw schema_exception({ error.str() });
809+
throw schema_exception { { error.str() } };
810810
}
811811

812812
DirectiveVisitor directiveVisitor(_variables);
@@ -889,7 +889,7 @@ void SelectionVisitor::visitFragmentSpread(const peg::ast_node & fragmentSpread)
889889
<< " line: " << position.line
890890
<< " column: " << position.byte_in_line;
891891

892-
throw schema_exception({ error.str() });
892+
throw schema_exception { { error.str() } };
893893
}
894894

895895
bool skip = (_typeNames.count(itr->second.getType()) == 0);
@@ -1431,7 +1431,7 @@ void SubscriptionDefinitionVisitor::visitFragmentSpread(const peg::ast_node & fr
14311431
<< " line: " << position.line
14321432
<< " column: " << position.byte_in_line;
14331433

1434-
throw schema_exception({ error.str() });
1434+
throw schema_exception { { error.str() } };
14351435
}
14361436

14371437
bool skip = !_subscriptionObject->matchesType(itr->second.getType());
@@ -1615,7 +1615,7 @@ std::future<response::Value> Request::resolve(std::launch launch, const std::sha
16151615
message << " name: " << operationName;
16161616
}
16171617

1618-
throw schema_exception({ message.str() });
1618+
throw schema_exception { { message.str() } };
16191619
}
16201620
else if (operationDefinition.first == strSubscription)
16211621
{
@@ -1628,7 +1628,7 @@ std::future<response::Value> Request::resolve(std::launch launch, const std::sha
16281628
message << " name: " << operationName;
16291629
}
16301630

1631-
throw schema_exception({ message.str() });
1631+
throw schema_exception { { message.str() } };
16321632
}
16331633

16341634
OperationDefinitionVisitor operationVisitor(state, _operations, std::move(variables), std::move(fragments));
@@ -1674,7 +1674,7 @@ SubscriptionKey Request::subscribe(SubscriptionParams && params, SubscriptionCal
16741674
message << " name: " << params.operationName;
16751675
}
16761676

1677-
throw schema_exception({ message.str() });
1677+
throw schema_exception { { message.str() } };
16781678
}
16791679
else if (operationDefinition.first != strSubscription)
16801680
{
@@ -1687,7 +1687,7 @@ SubscriptionKey Request::subscribe(SubscriptionParams && params, SubscriptionCal
16871687
message << " name: " << params.operationName;
16881688
}
16891689

1690-
throw schema_exception({ message.str() });
1690+
throw schema_exception { { message.str() } };
16911691
}
16921692

16931693
auto itr = _operations.find(std::string{ strSubscription });

src/SchemaGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ template <>
19161916
{
19171917
if (!value.maybe_enum())
19181918
{
1919-
throw service::schema_exception({ "not a valid )cpp" << enumType.type << R"cpp( value" });
1919+
throw service::schema_exception { { "not a valid )cpp" << enumType.type << R"cpp( value" } };
19201920
}
19211921
19221922
auto itr = std::find(s_names)cpp" << enumType.cppType
@@ -1926,7 +1926,7 @@ template <>
19261926
if (itr == s_names)cpp" << enumType.cppType
19271927
<< R"cpp(.cend())
19281928
{
1929-
throw service::schema_exception({ "not a valid )cpp" << enumType.type << R"cpp( value" });
1929+
throw service::schema_exception { { "not a valid )cpp" << enumType.type << R"cpp( value" } };
19301930
}
19311931
19321932
return static_cast<)cpp" << _schemaNamespace << R"cpp(::)cpp" << enumType.cppType

0 commit comments

Comments
 (0)