Skip to content

Commit 39b486d

Browse files
committed
Fix shared_ptr<RequestState> handling
1 parent 4d69e0f commit 39b486d

File tree

10 files changed

+250
-246
lines changed

10 files changed

+250
-246
lines changed

GraphQLService.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ Object::Object(TypeNames&& typeNames, ResolverMap&& resolvers)
347347
{
348348
}
349349

350-
std::future<response::Value> Object::resolve(const std::shared_ptr<RequestState>& state, const peg::ast_node& selection, const FragmentMap& fragments, const response::Value& variables) const
350+
std::future<response::Value> Object::resolve(std::shared_ptr<RequestState> state, const peg::ast_node& selection, const FragmentMap& fragments, const response::Value& variables) const
351351
{
352352
std::queue<std::future<response::Value>> selections;
353353

@@ -389,11 +389,11 @@ std::future<response::Value> Object::resolve(const std::shared_ptr<RequestState>
389389
}, std::move(selections));
390390
}
391391

392-
void Object::beginSelectionSet(const std::shared_ptr<RequestState>&) const
392+
void Object::beginSelectionSet(std::shared_ptr<RequestState>) const
393393
{
394394
}
395395

396-
void Object::endSelectionSet(const std::shared_ptr<RequestState>&) const
396+
void Object::endSelectionSet(std::shared_ptr<RequestState>) const
397397
{
398398
}
399399

@@ -424,7 +424,7 @@ std::future<response::Value> Request::resolve(std::shared_ptr<RequestState> stat
424424
return operationVisitor.getValue();
425425
}
426426

427-
SelectionVisitor::SelectionVisitor(const std::shared_ptr<RequestState>& state, const FragmentMap& fragments, const response::Value& variables, const TypeNames& typeNames, const ResolverMap& resolvers)
427+
SelectionVisitor::SelectionVisitor(std::shared_ptr<RequestState> state, const FragmentMap& fragments, const response::Value& variables, const TypeNames& typeNames, const ResolverMap& resolvers)
428428
: _state(state)
429429
, _fragments(fragments)
430430
, _variables(variables)
@@ -879,7 +879,7 @@ void FragmentDefinitionVisitor::visit(const peg::ast_node& fragmentDefinition)
879879
_fragments.insert({ fragmentDefinition.children.front()->content(), Fragment(fragmentDefinition) });
880880
}
881881

882-
OperationDefinitionVisitor::OperationDefinitionVisitor(const std::shared_ptr<RequestState>& state, const TypeMap& operations, const std::string& operationName, const response::Value& variables, const FragmentMap& fragments)
882+
OperationDefinitionVisitor::OperationDefinitionVisitor(std::shared_ptr<RequestState> state, const TypeMap& operations, const std::string& operationName, const response::Value& variables, const FragmentMap& fragments)
883883
: _state(state)
884884
, _operations(operations)
885885
, _operationName(operationName)
@@ -999,10 +999,8 @@ void OperationDefinitionVisitor::visit(const peg::ast_node& operationDefinition)
999999
throw schema_exception({ error.str() });
10001000
}
10011001

1002-
auto operationObject = itr->second;
1003-
10041002
_result = std::async(std::launch::deferred,
1005-
[this, &operationDefinition, operationObject]()
1003+
[this, &operationDefinition](std::shared_ptr<RequestState> state, std::shared_ptr<Object> operationObject)
10061004
{
10071005
response::Value operationVariables(response::Type::Map);
10081006

@@ -1045,12 +1043,12 @@ void OperationDefinitionVisitor::visit(const peg::ast_node& operationDefinition)
10451043
});
10461044

10471045
response::Value document(response::Type::Map);
1048-
auto data = operationObject->resolve(_state, *operationDefinition.children.back(), _fragments, operationVariables);
1046+
auto data = operationObject->resolve(state, *operationDefinition.children.back(), _fragments, operationVariables);
10491047

10501048
document.emplace_back("data", data.get());
10511049

10521050
return document;
1053-
});
1051+
}, _state, itr->second);
10541052
}
10551053
catch (const schema_exception& ex)
10561054
{

Introspection.cpp

Lines changed: 47 additions & 47 deletions
Large diffs are not rendered by default.

SchemaGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ std::string Generator::getFieldDeclaration(const OutputField& outputField) const
14621462

14631463
fieldName[0] = std::toupper(fieldName[0]);
14641464
output << R"cpp( virtual std::future<)cpp" << getOutputCppType(outputField)
1465-
<< R"cpp(> get)cpp" << fieldName << R"cpp((const std::shared_ptr<service::RequestState>& state)cpp";
1465+
<< R"cpp(> get)cpp" << fieldName << R"cpp((std::shared_ptr<service::RequestState> state)cpp";
14661466

14671467
for (const auto& argument : outputField.arguments)
14681468
{

Today.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void Query::loadAppointments() const
4848
}
4949
}
5050

51-
std::shared_ptr<Appointment> Query::findAppointment(const std::shared_ptr<service::RequestState>& state, const std::vector<uint8_t>& id) const
51+
std::shared_ptr<Appointment> Query::findAppointment(std::shared_ptr<service::RequestState> state, const std::vector<uint8_t>& id) const
5252
{
5353
loadAppointments();
5454

@@ -74,7 +74,7 @@ void Query::loadTasks() const
7474
}
7575
}
7676

77-
std::shared_ptr<Task> Query::findTask(const std::shared_ptr<service::RequestState>& state, const std::vector<uint8_t>& id) const
77+
std::shared_ptr<Task> Query::findTask(std::shared_ptr<service::RequestState> state, const std::vector<uint8_t>& id) const
7878
{
7979
loadTasks();
8080

@@ -100,7 +100,7 @@ void Query::loadUnreadCounts() const
100100
}
101101
}
102102

103-
std::shared_ptr<Folder> Query::findUnreadCount(const std::shared_ptr<service::RequestState>& state, const std::vector<uint8_t>& id) const
103+
std::shared_ptr<Folder> Query::findUnreadCount(std::shared_ptr<service::RequestState> state, const std::vector<uint8_t>& id) const
104104
{
105105
loadUnreadCounts();
106106

@@ -117,7 +117,7 @@ std::shared_ptr<Folder> Query::findUnreadCount(const std::shared_ptr<service::Re
117117
return nullptr;
118118
}
119119

120-
std::future<std::shared_ptr<service::Object>> Query::getNode(const std::shared_ptr<service::RequestState>& state, std::vector<uint8_t>&& id) const
120+
std::future<std::shared_ptr<service::Object>> Query::getNode(std::shared_ptr<service::RequestState> state, std::vector<uint8_t>&& id) const
121121
{
122122
std::promise<std::shared_ptr<service::Object>> promise;
123123
auto appointment = findAppointment(state, id);
@@ -154,7 +154,7 @@ struct EdgeConstraints
154154
using vec_type = std::vector<std::shared_ptr<_Object>>;
155155
using itr_type = typename vec_type::const_iterator;
156156

157-
EdgeConstraints(const std::shared_ptr<service::RequestState>& state, const vec_type& objects)
157+
EdgeConstraints(std::shared_ptr<service::RequestState> state, const vec_type& objects)
158158
: _state(state)
159159
, _objects(objects)
160160
{
@@ -242,58 +242,58 @@ struct EdgeConstraints
242242
const vec_type& _objects;
243243
};
244244

245-
std::future<std::shared_ptr<object::AppointmentConnection>> Query::getAppointments(const std::shared_ptr<service::RequestState>& state, std::unique_ptr<int>&& first, std::unique_ptr<response::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<response::Value>&& before) const
245+
std::future<std::shared_ptr<object::AppointmentConnection>> Query::getAppointments(std::shared_ptr<service::RequestState> state, std::unique_ptr<int>&& first, std::unique_ptr<response::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<response::Value>&& before) const
246246
{
247247
auto spThis = shared_from_this();
248248
return std::async(std::launch::async,
249-
[this, spThis](const std::shared_ptr<service::RequestState>& requestIdWrapped, std::unique_ptr<int>&& firstWrapped, std::unique_ptr<response::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<response::Value>&& beforeWrapped)
249+
[this, spThis](std::shared_ptr<service::RequestState> stateWrapped, std::unique_ptr<int>&& firstWrapped, std::unique_ptr<response::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<response::Value>&& beforeWrapped)
250250
{
251251
loadAppointments();
252252

253-
EdgeConstraints<Appointment, AppointmentConnection> constraints(requestIdWrapped, _appointments);
253+
EdgeConstraints<Appointment, AppointmentConnection> constraints(stateWrapped, _appointments);
254254
auto connection = constraints(firstWrapped.get(), afterWrapped.get(), lastWrapped.get(), beforeWrapped.get());
255255

256256
return std::static_pointer_cast<object::AppointmentConnection>(connection);
257-
}, state, std::move(first), std::move(after), std::move(last), std::move(before));
257+
}, std::move(state), std::move(first), std::move(after), std::move(last), std::move(before));
258258
}
259259

260-
std::future<std::shared_ptr<object::TaskConnection>> Query::getTasks(const std::shared_ptr<service::RequestState>& state, std::unique_ptr<int>&& first, std::unique_ptr<response::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<response::Value>&& before) const
260+
std::future<std::shared_ptr<object::TaskConnection>> Query::getTasks(std::shared_ptr<service::RequestState> state, std::unique_ptr<int>&& first, std::unique_ptr<response::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<response::Value>&& before) const
261261
{
262262
auto spThis = shared_from_this();
263263
return std::async(std::launch::async,
264-
[this, spThis](const std::shared_ptr<service::RequestState>& requestIdWrapped, std::unique_ptr<int>&& firstWrapped, std::unique_ptr<response::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<response::Value>&& beforeWrapped)
264+
[this, spThis](std::shared_ptr<service::RequestState> stateWrapped, std::unique_ptr<int>&& firstWrapped, std::unique_ptr<response::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<response::Value>&& beforeWrapped)
265265
{
266266
loadTasks();
267267

268-
EdgeConstraints<Task, TaskConnection> constraints(requestIdWrapped, _tasks);
268+
EdgeConstraints<Task, TaskConnection> constraints(stateWrapped, _tasks);
269269
auto connection = constraints(firstWrapped.get(), afterWrapped.get(), lastWrapped.get(), beforeWrapped.get());
270270

271271
return std::static_pointer_cast<object::TaskConnection>(connection);
272-
}, state, std::move(first), std::move(after), std::move(last), std::move(before));
272+
}, std::move(state), std::move(first), std::move(after), std::move(last), std::move(before));
273273
}
274274

275-
std::future<std::shared_ptr<object::FolderConnection>> Query::getUnreadCounts(const std::shared_ptr<service::RequestState>& state, std::unique_ptr<int>&& first, std::unique_ptr<response::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<response::Value>&& before) const
275+
std::future<std::shared_ptr<object::FolderConnection>> Query::getUnreadCounts(std::shared_ptr<service::RequestState> state, std::unique_ptr<int>&& first, std::unique_ptr<response::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<response::Value>&& before) const
276276
{
277277
auto spThis = shared_from_this();
278278
return std::async(std::launch::async,
279-
[this, spThis](const std::shared_ptr<service::RequestState>& requestIdWrapped, std::unique_ptr<int>&& firstWrapped, std::unique_ptr<response::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<response::Value>&& beforeWrapped)
279+
[this, spThis](std::shared_ptr<service::RequestState> stateWrapped, std::unique_ptr<int>&& firstWrapped, std::unique_ptr<response::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<response::Value>&& beforeWrapped)
280280
{
281281
loadUnreadCounts();
282282

283-
EdgeConstraints<Folder, FolderConnection> constraints(requestIdWrapped, _unreadCounts);
283+
EdgeConstraints<Folder, FolderConnection> constraints(stateWrapped, _unreadCounts);
284284
auto connection = constraints(firstWrapped.get(), afterWrapped.get(), lastWrapped.get(), beforeWrapped.get());
285285

286286
return std::static_pointer_cast<object::FolderConnection>(connection);
287-
}, state, std::move(first), std::move(after), std::move(last), std::move(before));
287+
}, std::move(state), std::move(first), std::move(after), std::move(last), std::move(before));
288288
}
289289

290-
std::future<std::vector<std::shared_ptr<object::Appointment>>> Query::getAppointmentsById(const std::shared_ptr<service::RequestState>& state, std::vector<std::vector<uint8_t>>&& ids) const
290+
std::future<std::vector<std::shared_ptr<object::Appointment>>> Query::getAppointmentsById(std::shared_ptr<service::RequestState> state, std::vector<std::vector<uint8_t>>&& ids) const
291291
{
292292
std::promise<std::vector<std::shared_ptr<object::Appointment>>> promise;
293293
std::vector<std::shared_ptr<object::Appointment>> result(ids.size());
294294

295295
std::transform(ids.cbegin(), ids.cend(), result.begin(),
296-
[this, state](const std::vector<uint8_t>& id)
296+
[this, &state](const std::vector<uint8_t>& id)
297297
{
298298
return std::static_pointer_cast<object::Appointment>(findAppointment(state, id));
299299
});
@@ -302,13 +302,13 @@ std::future<std::vector<std::shared_ptr<object::Appointment>>> Query::getAppoint
302302
return promise.get_future();
303303
}
304304

305-
std::future<std::vector<std::shared_ptr<object::Task>>> Query::getTasksById(const std::shared_ptr<service::RequestState>& state, std::vector<std::vector<uint8_t>>&& ids) const
305+
std::future<std::vector<std::shared_ptr<object::Task>>> Query::getTasksById(std::shared_ptr<service::RequestState> state, std::vector<std::vector<uint8_t>>&& ids) const
306306
{
307307
std::promise<std::vector<std::shared_ptr<object::Task>>> promise;
308308
std::vector<std::shared_ptr<object::Task>> result(ids.size());
309309

310310
std::transform(ids.cbegin(), ids.cend(), result.begin(),
311-
[this, state](const std::vector<uint8_t>& id)
311+
[this, &state](const std::vector<uint8_t>& id)
312312
{
313313
return std::static_pointer_cast<object::Task>(findTask(state, id));
314314
});
@@ -317,13 +317,13 @@ std::future<std::vector<std::shared_ptr<object::Task>>> Query::getTasksById(cons
317317
return promise.get_future();
318318
}
319319

320-
std::future<std::vector<std::shared_ptr<object::Folder>>> Query::getUnreadCountsById(const std::shared_ptr<service::RequestState>& state, std::vector<std::vector<uint8_t>>&& ids) const
320+
std::future<std::vector<std::shared_ptr<object::Folder>>> Query::getUnreadCountsById(std::shared_ptr<service::RequestState> state, std::vector<std::vector<uint8_t>>&& ids) const
321321
{
322322
std::promise<std::vector<std::shared_ptr<object::Folder>>> promise;
323323
std::vector<std::shared_ptr<object::Folder>> result(ids.size());
324324

325325
std::transform(ids.cbegin(), ids.cend(), result.begin(),
326-
[this, state](const std::vector<uint8_t>& id)
326+
[this, &state](const std::vector<uint8_t>& id)
327327
{
328328
return std::static_pointer_cast<object::Folder>(findUnreadCount(state, id));
329329
});
@@ -337,7 +337,7 @@ Mutation::Mutation(completeTaskMutation&& mutateCompleteTask)
337337
{
338338
}
339339

340-
std::future<std::shared_ptr<object::CompleteTaskPayload>> Mutation::getCompleteTask(const std::shared_ptr<service::RequestState>& state, CompleteTaskInput&& input) const
340+
std::future<std::shared_ptr<object::CompleteTaskPayload>> Mutation::getCompleteTask(std::shared_ptr<service::RequestState> state, CompleteTaskInput&& input) const
341341
{
342342
std::promise<std::shared_ptr<object::CompleteTaskPayload>> promise;
343343

0 commit comments

Comments
 (0)