Skip to content

Commit 7662396

Browse files
committed
fix: code cleanup to reduce duplication
1 parent f605261 commit 7662396

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/GraphQLService.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,16 +1265,19 @@ std::shared_ptr<Object> Object::StitchObject(const std::shared_ptr<const Object>
12651265

12661266
if (schema && schema->supportsIntrospection())
12671267
{
1268-
resolvers.erase("__schema"sv);
1269-
resolvers.emplace("__schema"sv, [schema](ResolverParams&& params) {
1268+
constexpr auto schemaField = R"gql(__schema)gql"sv;
1269+
constexpr auto typeField = R"gql(__type)gql"sv;
1270+
1271+
resolvers.erase(schemaField);
1272+
resolvers.emplace(schemaField, [schema](ResolverParams&& params) {
12701273
return Result<Object>::convert(
12711274
std::static_pointer_cast<Object>(std::make_shared<introspection::object::Schema>(
12721275
std::make_shared<introspection::Schema>(schema))),
12731276
std::move(params));
12741277
});
12751278

1276-
resolvers.erase("__type"sv);
1277-
resolvers.emplace("__type"sv, [schema](ResolverParams&& params) {
1279+
resolvers.erase(typeField);
1280+
resolvers.emplace(typeField, [schema](ResolverParams&& params) {
12781281
auto argName = ModifiedArgument<std::string>::require("name", params.arguments);
12791282
const auto& baseType = schema->LookupType(argName);
12801283
std::shared_ptr<introspection::object::Type> result { baseType
@@ -1813,7 +1816,7 @@ std::shared_ptr<const Request> Request::stitch(const std::shared_ptr<const Reque
18131816
{
18141817
TypeMap operations;
18151818
auto schema = _schema->StitchSchema(added->_schema);
1816-
std::shared_ptr<Object> query;
1819+
std::shared_ptr<const Object> query;
18171820
auto itrOriginalQuery = _operations.find(strQuery);
18181821
auto itrAddedQuery = added->_operations.find(strQuery);
18191822

@@ -1835,47 +1838,58 @@ std::shared_ptr<const Request> Request::stitch(const std::shared_ptr<const Reque
18351838

18361839
if (query)
18371840
{
1838-
operations.emplace(strQuery, query);
1841+
operations.emplace(strQuery, std::move(query));
18391842
}
18401843

1844+
std::shared_ptr<const Object> mutation;
18411845
auto itrOriginalMutation = _operations.find(strMutation);
18421846
auto itrAddedMutation = added->_operations.find(strMutation);
18431847

18441848
if (itrOriginalMutation != _operations.end() && itrOriginalMutation->second)
18451849
{
18461850
if (itrAddedMutation != added->_operations.end() && itrAddedMutation->second)
18471851
{
1848-
operations.emplace(strMutation,
1849-
itrOriginalMutation->second->StitchObject(itrAddedMutation->second));
1852+
mutation = itrOriginalMutation->second->StitchObject(itrAddedMutation->second);
18501853
}
18511854
else
18521855
{
1853-
operations.emplace(strMutation, itrOriginalMutation->second);
1856+
mutation = itrOriginalMutation->second;
18541857
}
18551858
}
18561859
else if (itrAddedMutation != added->_operations.end() && itrAddedMutation->second)
18571860
{
1858-
operations.emplace(strMutation, itrAddedMutation->second);
1861+
mutation = itrAddedMutation->second;
1862+
}
1863+
1864+
if (mutation)
1865+
{
1866+
operations.emplace(strMutation, std::move(mutation));
18591867
}
18601868

1869+
std::shared_ptr<const Object> subscription;
18611870
auto itrOriginalSubscription = _operations.find(strSubscription);
18621871
auto itrAddedSubscription = added->_operations.find(strSubscription);
18631872

18641873
if (itrOriginalSubscription != _operations.end() && itrOriginalSubscription->second)
18651874
{
18661875
if (itrAddedSubscription != added->_operations.end() && itrAddedSubscription->second)
18671876
{
1868-
operations.emplace(strSubscription,
1869-
itrOriginalSubscription->second->StitchObject(itrAddedSubscription->second));
1877+
subscription =
1878+
itrOriginalSubscription->second->StitchObject(itrAddedSubscription->second);
18701879
}
18711880
else
18721881
{
1873-
operations.emplace(strSubscription, itrOriginalSubscription->second);
1882+
subscription = itrOriginalSubscription->second;
18741883
}
18751884
}
18761885
else if (itrAddedSubscription != added->_operations.end() && itrAddedSubscription->second)
18771886
{
1878-
operations.emplace(strSubscription, itrAddedSubscription->second);
1887+
subscription = itrAddedSubscription->second;
1888+
}
1889+
1890+
if (subscription)
1891+
{
1892+
operations.emplace(strSubscription, std::move(subscription));
18791893
}
18801894

18811895
class StitchedRequest : public Request

0 commit comments

Comments
 (0)