Skip to content

Commit 818dff1

Browse files
committed
Flow directives from the operations, fragments, and fields
1 parent 2afe417 commit 818dff1

File tree

11 files changed

+799
-569
lines changed

11 files changed

+799
-569
lines changed

GraphQLService.cpp

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

Introspection.cpp

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

SchemaGenerator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,12 +1503,12 @@ std::string Generator::getFieldDeclaration(const OutputField& outputField) const
15031503

15041504
fieldName[0] = std::toupper(fieldName[0]);
15051505
output << R"cpp( virtual std::future<)cpp" << getOutputCppType(outputField)
1506-
<< R"cpp(> get)cpp" << fieldName << R"cpp((const std::shared_ptr<service::RequestState>& state)cpp";
1506+
<< R"cpp(> get)cpp" << fieldName << R"cpp((const service::FieldParams& params)cpp";
15071507

15081508
for (const auto& argument : outputField.arguments)
15091509
{
15101510
output << R"cpp(, )cpp" << getInputCppType(argument)
1511-
<< R"cpp(&& )cpp" << argument.name;
1511+
<< R"cpp(&& )cpp" << argument.name << "Arg";
15121512
}
15131513

15141514
output << R"cpp() const = 0;
@@ -1940,7 +1940,7 @@ std::future<response::Value> )cpp" << objectType.type
19401940
}
19411941
}
19421942

1943-
sourceFile << R"cpp( auto result = get)cpp" << fieldName << R"cpp((params.state)cpp";
1943+
sourceFile << R"cpp( auto result = get)cpp" << fieldName << R"cpp((service::FieldParams(params, std::move(params.fieldDirectives)))cpp";
19441944

19451945
if (!outputField.arguments.empty())
19461946
{

Today.cpp

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ void Query::loadAppointments(const std::shared_ptr<service::RequestState>& state
5656
}
5757
}
5858

59-
std::shared_ptr<Appointment> Query::findAppointment(const std::shared_ptr<service::RequestState>& state, const std::vector<uint8_t>& id) const
59+
std::shared_ptr<Appointment> Query::findAppointment(const service::FieldParams& params, const std::vector<uint8_t>& id) const
6060
{
61-
loadAppointments(state);
61+
loadAppointments(params.state);
6262

6363
for (const auto& appointment : _appointments)
6464
{
65-
auto appointmentId = appointment->getId(state).get();
65+
auto appointmentId = appointment->getId(params).get();
6666

6767
if (appointmentId == id)
6868
{
@@ -90,13 +90,13 @@ void Query::loadTasks(const std::shared_ptr<service::RequestState>& state) const
9090
}
9191
}
9292

93-
std::shared_ptr<Task> Query::findTask(const std::shared_ptr<service::RequestState>& state, const std::vector<uint8_t>& id) const
93+
std::shared_ptr<Task> Query::findTask(const service::FieldParams& params, const std::vector<uint8_t>& id) const
9494
{
95-
loadTasks(state);
95+
loadTasks(params.state);
9696

9797
for (const auto& task : _tasks)
9898
{
99-
auto taskId = task->getId(state).get();
99+
auto taskId = task->getId(params).get();
100100

101101
if (taskId == id)
102102
{
@@ -124,13 +124,13 @@ void Query::loadUnreadCounts(const std::shared_ptr<service::RequestState>& state
124124
}
125125
}
126126

127-
std::shared_ptr<Folder> Query::findUnreadCount(const std::shared_ptr<service::RequestState>& state, const std::vector<uint8_t>& id) const
127+
std::shared_ptr<Folder> Query::findUnreadCount(const service::FieldParams& params, const std::vector<uint8_t>& id) const
128128
{
129-
loadUnreadCounts(state);
129+
loadUnreadCounts(params.state);
130130

131131
for (const auto& folder : _unreadCounts)
132132
{
133-
auto folderId = folder->getId(state).get();
133+
auto folderId = folder->getId(params).get();
134134

135135
if (folderId == id)
136136
{
@@ -141,26 +141,26 @@ std::shared_ptr<Folder> Query::findUnreadCount(const std::shared_ptr<service::Re
141141
return nullptr;
142142
}
143143

144-
std::future<std::shared_ptr<service::Object>> Query::getNode(const std::shared_ptr<service::RequestState>& state, std::vector<uint8_t>&& id) const
144+
std::future<std::shared_ptr<service::Object>> Query::getNode(const service::FieldParams& params, std::vector<uint8_t>&& id) const
145145
{
146146
std::promise<std::shared_ptr<service::Object>> promise;
147-
auto appointment = findAppointment(state, id);
147+
auto appointment = findAppointment(params, id);
148148

149149
if (appointment)
150150
{
151151
promise.set_value(appointment);
152152
return promise.get_future();
153153
}
154154

155-
auto task = findTask(state, id);
155+
auto task = findTask(params, id);
156156

157157
if (task)
158158
{
159159
promise.set_value(task);
160160
return promise.get_future();
161161
}
162162

163-
auto folder = findUnreadCount(state, id);
163+
auto folder = findUnreadCount(params, id);
164164

165165
if (folder)
166166
{
@@ -189,14 +189,24 @@ struct EdgeConstraints
189189
auto itrFirst = _objects.cbegin();
190190
auto itrLast = _objects.cend();
191191

192+
const response::Value unusedDirectives;
193+
const service::SelectionSetParams selectionSetParams {
194+
_state,
195+
unusedDirectives,
196+
unusedDirectives,
197+
unusedDirectives,
198+
unusedDirectives,
199+
};
200+
const service::FieldParams fieldParams(selectionSetParams, {});
201+
192202
if (after)
193203
{
194204
const auto& encoded = after->get<const response::StringType&>();
195205
auto afterId = service::Base64::fromBase64(encoded.c_str(), encoded.size());
196206
auto itrAfter = std::find_if(itrFirst, itrLast,
197-
[this, &afterId](const std::shared_ptr<_Object>& entry)
207+
[this, &fieldParams, &afterId](const std::shared_ptr<_Object>& entry)
198208
{
199-
return entry->getId(_state).get() == afterId;
209+
return entry->getId(fieldParams).get() == afterId;
200210
});
201211

202212
if (itrAfter != itrLast)
@@ -210,9 +220,9 @@ struct EdgeConstraints
210220
const auto& encoded = before->get<const response::StringType&>();
211221
auto beforeId = service::Base64::fromBase64(encoded.c_str(), encoded.size());
212222
auto itrBefore = std::find_if(itrFirst, itrLast,
213-
[this, &beforeId](const std::shared_ptr<_Object>& entry)
223+
[this, &fieldParams, &beforeId](const std::shared_ptr<_Object>& entry)
214224
{
215-
return entry->getId(_state).get() == beforeId;
225+
return entry->getId(fieldParams).get() == beforeId;
216226
});
217227

218228
if (itrBefore != itrLast)
@@ -262,94 +272,97 @@ struct EdgeConstraints
262272
}
263273

264274
private:
265-
std::shared_ptr<service::RequestState> _state;
275+
const std::shared_ptr<service::RequestState>& _state;
266276
const vec_type& _objects;
267277
};
268278

269-
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
279+
std::future<std::shared_ptr<object::AppointmentConnection>> Query::getAppointments(const service::FieldParams& params, std::unique_ptr<int>&& first, std::unique_ptr<response::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<response::Value>&& before) const
270280
{
271281
auto spThis = shared_from_this();
282+
auto state = params.state;
272283
return std::async(std::launch::async,
273-
[this, spThis](const 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)
284+
[this, spThis, state](std::unique_ptr<int>&& firstWrapped, std::unique_ptr<response::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<response::Value>&& beforeWrapped)
274285
{
275-
loadAppointments(stateWrapped);
286+
loadAppointments(state);
276287

277-
EdgeConstraints<Appointment, AppointmentConnection> constraints(stateWrapped, _appointments);
288+
EdgeConstraints<Appointment, AppointmentConnection> constraints(state, _appointments);
278289
auto connection = constraints(firstWrapped.get(), afterWrapped.get(), lastWrapped.get(), beforeWrapped.get());
279290

280291
return std::static_pointer_cast<object::AppointmentConnection>(connection);
281-
}, std::move(state), std::move(first), std::move(after), std::move(last), std::move(before));
292+
}, std::move(first), std::move(after), std::move(last), std::move(before));
282293
}
283294

284-
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
295+
std::future<std::shared_ptr<object::TaskConnection>> Query::getTasks(const service::FieldParams& params, std::unique_ptr<int>&& first, std::unique_ptr<response::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<response::Value>&& before) const
285296
{
286297
auto spThis = shared_from_this();
298+
auto state = params.state;
287299
return std::async(std::launch::async,
288-
[this, spThis](const 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)
300+
[this, spThis, state](std::unique_ptr<int>&& firstWrapped, std::unique_ptr<response::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<response::Value>&& beforeWrapped)
289301
{
290-
loadTasks(stateWrapped);
302+
loadTasks(state);
291303

292-
EdgeConstraints<Task, TaskConnection> constraints(stateWrapped, _tasks);
304+
EdgeConstraints<Task, TaskConnection> constraints(state, _tasks);
293305
auto connection = constraints(firstWrapped.get(), afterWrapped.get(), lastWrapped.get(), beforeWrapped.get());
294306

295307
return std::static_pointer_cast<object::TaskConnection>(connection);
296-
}, std::move(state), std::move(first), std::move(after), std::move(last), std::move(before));
308+
}, std::move(first), std::move(after), std::move(last), std::move(before));
297309
}
298310

299-
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
311+
std::future<std::shared_ptr<object::FolderConnection>> Query::getUnreadCounts(const service::FieldParams& params, std::unique_ptr<int>&& first, std::unique_ptr<response::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<response::Value>&& before) const
300312
{
301313
auto spThis = shared_from_this();
314+
auto state = params.state;
302315
return std::async(std::launch::async,
303-
[this, spThis](const 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)
316+
[this, spThis, state](std::unique_ptr<int>&& firstWrapped, std::unique_ptr<response::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<response::Value>&& beforeWrapped)
304317
{
305-
loadUnreadCounts(stateWrapped);
318+
loadUnreadCounts(state);
306319

307-
EdgeConstraints<Folder, FolderConnection> constraints(stateWrapped, _unreadCounts);
320+
EdgeConstraints<Folder, FolderConnection> constraints(state, _unreadCounts);
308321
auto connection = constraints(firstWrapped.get(), afterWrapped.get(), lastWrapped.get(), beforeWrapped.get());
309322

310323
return std::static_pointer_cast<object::FolderConnection>(connection);
311-
}, std::move(state), std::move(first), std::move(after), std::move(last), std::move(before));
324+
}, std::move(first), std::move(after), std::move(last), std::move(before));
312325
}
313326

314-
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
327+
std::future<std::vector<std::shared_ptr<object::Appointment>>> Query::getAppointmentsById(const service::FieldParams& params, std::vector<std::vector<uint8_t>>&& ids) const
315328
{
316329
std::promise<std::vector<std::shared_ptr<object::Appointment>>> promise;
317330
std::vector<std::shared_ptr<object::Appointment>> result(ids.size());
318331

319332
std::transform(ids.cbegin(), ids.cend(), result.begin(),
320-
[this, &state](const std::vector<uint8_t>& id)
333+
[this, &params](const std::vector<uint8_t>& id)
321334
{
322-
return std::static_pointer_cast<object::Appointment>(findAppointment(state, id));
335+
return std::static_pointer_cast<object::Appointment>(findAppointment(params, id));
323336
});
324337
promise.set_value(std::move(result));
325338

326339
return promise.get_future();
327340
}
328341

329-
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
342+
std::future<std::vector<std::shared_ptr<object::Task>>> Query::getTasksById(const service::FieldParams& params, std::vector<std::vector<uint8_t>>&& ids) const
330343
{
331344
std::promise<std::vector<std::shared_ptr<object::Task>>> promise;
332345
std::vector<std::shared_ptr<object::Task>> result(ids.size());
333346

334347
std::transform(ids.cbegin(), ids.cend(), result.begin(),
335-
[this, &state](const std::vector<uint8_t>& id)
348+
[this, &params](const std::vector<uint8_t>& id)
336349
{
337-
return std::static_pointer_cast<object::Task>(findTask(state, id));
350+
return std::static_pointer_cast<object::Task>(findTask(params, id));
338351
});
339352
promise.set_value(std::move(result));
340353

341354
return promise.get_future();
342355
}
343356

344-
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
357+
std::future<std::vector<std::shared_ptr<object::Folder>>> Query::getUnreadCountsById(const service::FieldParams& params, std::vector<std::vector<uint8_t>>&& ids) const
345358
{
346359
std::promise<std::vector<std::shared_ptr<object::Folder>>> promise;
347360
std::vector<std::shared_ptr<object::Folder>> result(ids.size());
348361

349362
std::transform(ids.cbegin(), ids.cend(), result.begin(),
350-
[this, &state](const std::vector<uint8_t>& id)
363+
[this, &params](const std::vector<uint8_t>& id)
351364
{
352-
return std::static_pointer_cast<object::Folder>(findUnreadCount(state, id));
365+
return std::static_pointer_cast<object::Folder>(findUnreadCount(params, id));
353366
});
354367
promise.set_value(std::move(result));
355368

@@ -361,7 +374,7 @@ Mutation::Mutation(completeTaskMutation&& mutateCompleteTask)
361374
{
362375
}
363376

364-
std::future<std::shared_ptr<object::CompleteTaskPayload>> Mutation::getCompleteTask(const std::shared_ptr<service::RequestState>& state, CompleteTaskInput&& input) const
377+
std::future<std::shared_ptr<object::CompleteTaskPayload>> Mutation::getCompleteTask(const service::FieldParams& params, CompleteTaskInput&& input) const
365378
{
366379
std::promise<std::shared_ptr<object::CompleteTaskPayload>> promise;
367380

0 commit comments

Comments
 (0)