Skip to content

Commit 0d5137c

Browse files
committed
Use shared_ptr<const ...> in more places
1 parent 92e9b6a commit 0d5137c

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

include/graphqlservice/GraphQLService.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ struct ModifiedResult
826826
typename std::conditional_t<std::is_base_of_v<Object, U>, std::shared_ptr<U>, U>;
827827

828828
using future_type = typename std::conditional_t<std::is_base_of_v<Object, U>,
829-
AwaitableObject<std::shared_ptr<Object>>, AwaitableScalar<type>>;
829+
AwaitableObject<std::shared_ptr<const Object>>, AwaitableScalar<type>>;
830830
};
831831

832832
// Convert a single value of the specified type to JSON.
@@ -849,7 +849,7 @@ struct ModifiedResult
849849
co_await params.launch;
850850

851851
auto awaitedResult = co_await ModifiedResult<Object>::convert(
852-
std::static_pointer_cast<Object>(co_await result),
852+
std::static_pointer_cast<const Object>(co_await result),
853853
std::move(params));
854854

855855
co_return std::move(awaitedResult);
@@ -1155,7 +1155,7 @@ GRAPHQLSERVICE_EXPORT AwaitableResolver ModifiedResult<response::Value>::convert
11551155
AwaitableScalar<response::Value> result, ResolverParams params);
11561156
template <>
11571157
GRAPHQLSERVICE_EXPORT AwaitableResolver ModifiedResult<Object>::convert(
1158-
AwaitableObject<std::shared_ptr<Object>> result, ResolverParams params);
1158+
AwaitableObject<std::shared_ptr<const Object>> result, ResolverParams params);
11591159

11601160
// Export all of the scalar value validation methods
11611161
template <>
@@ -1260,10 +1260,10 @@ struct RequestDeliverParams
12601260
await_async launch {};
12611261

12621262
// Optional override for the default Subscription operation object.
1263-
std::shared_ptr<Object> subscriptionObject {};
1263+
std::shared_ptr<const Object> subscriptionObject {};
12641264
};
12651265

1266-
using TypeMap = internal::string_view_map<std::shared_ptr<Object>>;
1266+
using TypeMap = internal::string_view_map<std::shared_ptr<const Object>>;
12671267

12681268
// State which is captured and kept alive until all pending futures have been resolved for an
12691269
// operation. Note: SelectionSet is the other parameter that gets passed to the top level Object,
@@ -1328,14 +1328,14 @@ class Request : public std::enable_shared_from_this<Request>
13281328
private:
13291329
SubscriptionKey addSubscription(RequestSubscribeParams&& params);
13301330
void removeSubscription(SubscriptionKey key);
1331-
std::vector<std::shared_ptr<SubscriptionData>> collectRegistrations(
1331+
std::vector<std::shared_ptr<const SubscriptionData>> collectRegistrations(
13321332
std::string_view field, RequestDeliverFilter&& filter) const noexcept;
13331333

13341334
const TypeMap _operations;
13351335
mutable std::mutex _validationMutex {};
13361336
const std::unique_ptr<ValidateExecutableVisitor> _validation;
13371337
mutable std::mutex _subscriptionMutex {};
1338-
internal::sorted_map<SubscriptionKey, std::shared_ptr<SubscriptionData>> _subscriptions;
1338+
internal::sorted_map<SubscriptionKey, std::shared_ptr<const SubscriptionData>> _subscriptions;
13391339
internal::sorted_map<SubscriptionName, internal::sorted_set<SubscriptionKey>> _listeners;
13401340
SubscriptionKey _nextKey = 0;
13411341
};

src/GraphQLService.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ void requireSubFields(const ResolverParams& params)
695695

696696
template <>
697697
AwaitableResolver ModifiedResult<Object>::convert(
698-
AwaitableObject<std::shared_ptr<Object>> result, ResolverParams params)
698+
AwaitableObject<std::shared_ptr<const Object>> result, ResolverParams params)
699699
{
700700
requireSubFields(params);
701701

@@ -1378,7 +1378,7 @@ class SubscriptionDefinitionVisitor
13781378
{
13791379
public:
13801380
SubscriptionDefinitionVisitor(RequestSubscribeParams&& params, FragmentMap&& fragments,
1381-
const std::shared_ptr<Object>& subscriptionObject);
1381+
const std::shared_ptr<const Object>& subscriptionObject);
13821382

13831383
const peg::ast_node& getRoot() const;
13841384
std::shared_ptr<SubscriptionData> getRegistration();
@@ -1392,15 +1392,15 @@ class SubscriptionDefinitionVisitor
13921392

13931393
RequestSubscribeParams _params;
13941394
FragmentMap _fragments;
1395-
const std::shared_ptr<Object>& _subscriptionObject;
1395+
const std::shared_ptr<const Object>& _subscriptionObject;
13961396
SubscriptionName _field;
13971397
response::Value _arguments;
13981398
Directives _fieldDirectives;
13991399
std::shared_ptr<SubscriptionData> _result;
14001400
};
14011401

14021402
SubscriptionDefinitionVisitor::SubscriptionDefinitionVisitor(RequestSubscribeParams&& params,
1403-
FragmentMap&& fragments, const std::shared_ptr<Object>& subscriptionObject)
1403+
FragmentMap&& fragments, const std::shared_ptr<const Object>& subscriptionObject)
14041404
: _params(std::move(params))
14051405
, _fragments(std::move(fragments))
14061406
, _subscriptionObject(subscriptionObject)
@@ -1748,6 +1748,7 @@ response::AwaitableValue Request::resolve(RequestResolveParams params) const
17481748
AwaitableSubscribe Request::subscribe(RequestSubscribeParams params)
17491749
{
17501750
const auto spThis = shared_from_this();
1751+
const auto launch = std::move(params.launch);
17511752
std::unique_lock lock { spThis->_subscriptionMutex };
17521753
const auto key = spThis->addSubscription(std::move(params));
17531754
const auto itrOperation = spThis->_operations.find(strSubscription);
@@ -1764,14 +1765,14 @@ AwaitableSubscribe Request::subscribe(RequestSubscribeParams params)
17641765
std::make_shared<FragmentSpreadDirectiveStack>(),
17651766
std::make_shared<FragmentSpreadDirectiveStack>(),
17661767
{},
1767-
params.launch,
1768+
launch,
17681769
};
17691770

17701771
lock.unlock();
17711772

17721773
try
17731774
{
1774-
co_await params.launch;
1775+
co_await launch;
17751776
co_await operation->resolve(selectionSetParams,
17761777
registration->selection,
17771778
registration->data->fragments,
@@ -1997,10 +1998,10 @@ void Request::removeSubscription(SubscriptionKey key)
19971998
}
19981999
}
19992000

2000-
std::vector<std::shared_ptr<SubscriptionData>> Request::collectRegistrations(
2001+
std::vector<std::shared_ptr<const SubscriptionData>> Request::collectRegistrations(
20012002
std::string_view field, RequestDeliverFilter&& filter) const noexcept
20022003
{
2003-
std::vector<std::shared_ptr<SubscriptionData>> registrations;
2004+
std::vector<std::shared_ptr<const SubscriptionData>> registrations;
20042005
const std::lock_guard lock { _subscriptionMutex };
20052006
const auto itrListeners = _listeners.find(field);
20062007

@@ -2016,7 +2017,7 @@ std::vector<std::shared_ptr<SubscriptionData>> Request::collectRegistrations(
20162017
[this](const auto& key) noexcept {
20172018
const auto itr = _subscriptions.find(key);
20182019

2019-
return itr == _subscriptions.end() ? std::shared_ptr<SubscriptionData> {}
2020+
return itr == _subscriptions.end() ? std::shared_ptr<const SubscriptionData> {}
20202021
: itr->second;
20212022
});
20222023
}

0 commit comments

Comments
 (0)