-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathToday.h
More file actions
338 lines (273 loc) · 9.89 KB
/
Today.h
File metadata and controls
338 lines (273 loc) · 9.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include "TodaySchema.h"
namespace facebook {
namespace graphql {
namespace today {
class Appointment;
class Task;
class Folder;
class Query : public object::Query
{
public:
using appointmentsLoader = std::function<std::vector<std::shared_ptr<Appointment>>()>;
using tasksLoader = std::function<std::vector<std::shared_ptr<Task>>()>;
using unreadCountsLoader = std::function<std::vector<std::shared_ptr<Folder>>()>;
explicit Query(appointmentsLoader&& getAppointments, tasksLoader&& getTasks, unreadCountsLoader&& getUnreadCounts);
std::shared_ptr<service::Object> getNode(std::vector<unsigned char>&& id) const override;
std::shared_ptr<object::AppointmentConnection> getAppointments(std::unique_ptr<int>&& first, std::unique_ptr<web::json::value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<web::json::value>&& before) const override;
std::shared_ptr<object::TaskConnection> getTasks(std::unique_ptr<int>&& first, std::unique_ptr<web::json::value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<web::json::value>&& before) const override;
std::shared_ptr<object::FolderConnection> getUnreadCounts(std::unique_ptr<int>&& first, std::unique_ptr<web::json::value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<web::json::value>&& before) const override;
std::vector<std::shared_ptr<object::Appointment>> getAppointmentsById(std::vector<std::vector<unsigned char>>&& ids) const override;
std::vector<std::shared_ptr<object::Task>> getTasksById(std::vector<std::vector<unsigned char>>&& ids) const override;
std::vector<std::shared_ptr<object::Folder>> getUnreadCountsById(std::vector<std::vector<unsigned char>>&& ids) const override;
private:
std::shared_ptr<Appointment> findAppointment(const std::vector<unsigned char>& id) const;
std::shared_ptr<Task> findTask(const std::vector<unsigned char>& id) const;
std::shared_ptr<Folder> findUnreadCount(const std::vector<unsigned char>& id) const;
// Lazy load the fields in each query
void loadAppointments() const;
void loadTasks() const;
void loadUnreadCounts() const;
mutable appointmentsLoader _getAppointments;
mutable tasksLoader _getTasks;
mutable unreadCountsLoader _getUnreadCounts;
mutable std::vector<std::shared_ptr<Appointment>> _appointments;
mutable std::vector<std::shared_ptr<Task>> _tasks;
mutable std::vector<std::shared_ptr<Folder>> _unreadCounts;
};
class PageInfo : public object::PageInfo
{
public:
explicit PageInfo(bool hasNextPage, bool hasPreviousPage)
: _hasNextPage(hasNextPage)
, _hasPreviousPage(hasPreviousPage)
{
}
bool getHasNextPage() const override
{
return _hasNextPage;
}
bool getHasPreviousPage() const override
{
return _hasPreviousPage;
}
private:
const bool _hasNextPage;
const bool _hasPreviousPage;
};
class Appointment : public object::Appointment
{
public:
explicit Appointment(std::vector<unsigned char>&& id, std::string&& when, std::string&& subject, bool isNow);
std::vector<unsigned char> getId() const override { return _id; }
std::unique_ptr<web::json::value> getWhen() const override{ return std::unique_ptr<web::json::value>(new web::json::value(web::json::value::string(utility::conversions::to_string_t(_when)))); }
std::unique_ptr<std::string> getSubject() const override { return std::unique_ptr<std::string>(new std::string(_subject)); }
bool getIsNow() const override { return _isNow; }
private:
std::vector<unsigned char> _id;
std::string _when;
std::string _subject;
bool _isNow;
};
class AppointmentEdge : public object::AppointmentEdge
{
public:
explicit AppointmentEdge(std::shared_ptr<Appointment> appointment)
: _appointment(std::move(appointment))
{
}
std::shared_ptr<object::Appointment> getNode() const override
{
return std::static_pointer_cast<object::Appointment>(_appointment);
}
web::json::value getCursor() const override
{
return web::json::value::string(utility::conversions::to_base64(_appointment->getId()));
}
private:
std::shared_ptr<Appointment> _appointment;
};
class AppointmentConnection : public object::AppointmentConnection
{
public:
explicit AppointmentConnection(bool hasNextPage, bool hasPreviousPage, std::vector<std::shared_ptr<Appointment>> appointments)
: _pageInfo(std::make_shared<PageInfo>(hasNextPage, hasPreviousPage))
, _appointments(std::move(appointments))
{
}
std::shared_ptr<object::PageInfo> getPageInfo() const override
{
return _pageInfo;
}
std::unique_ptr<std::vector<std::shared_ptr<object::AppointmentEdge>>> getEdges() const override
{
auto result = std::unique_ptr<std::vector<std::shared_ptr<object::AppointmentEdge>>>(new std::vector<std::shared_ptr<object::AppointmentEdge>>(_appointments.size()));
std::transform(_appointments.cbegin(), _appointments.cend(), result->begin(),
[](const std::shared_ptr<Appointment>& node)
{
return std::make_shared<AppointmentEdge>(node);
});
return result;
}
private:
std::shared_ptr<PageInfo> _pageInfo;
std::vector<std::shared_ptr<Appointment>> _appointments;
};
class Task : public object::Task
{
public:
explicit Task(std::vector<unsigned char>&& id, std::string&& title, bool isComplete);
std::vector<unsigned char> getId() const override { return _id; }
std::unique_ptr<std::string> getTitle() const override { return std::unique_ptr<std::string>(new std::string(_title)); }
bool getIsComplete() const override { return _isComplete; }
private:
std::vector<unsigned char> _id;
std::string _title;
bool _isComplete;
TaskState _state = TaskState::New;
};
class TaskEdge : public object::TaskEdge
{
public:
explicit TaskEdge(std::shared_ptr<Task> task)
: _task(std::move(task))
{
}
std::shared_ptr<object::Task> getNode() const override
{
return std::static_pointer_cast<object::Task>(_task);
}
web::json::value getCursor() const override
{
return web::json::value::string(utility::conversions::to_base64(_task->getId()));
}
private:
std::shared_ptr<Task> _task;
};
class TaskConnection : public object::TaskConnection
{
public:
explicit TaskConnection(bool hasNextPage, bool hasPreviousPage, std::vector<std::shared_ptr<Task>> tasks)
: _pageInfo(std::make_shared<PageInfo>(hasNextPage, hasPreviousPage))
, _tasks(std::move(tasks))
{
}
std::shared_ptr<object::PageInfo> getPageInfo() const override
{
return _pageInfo;
}
std::unique_ptr<std::vector<std::shared_ptr<object::TaskEdge>>> getEdges() const override
{
auto result = std::unique_ptr<std::vector<std::shared_ptr<object::TaskEdge>>>(new std::vector<std::shared_ptr<object::TaskEdge>>(_tasks.size()));
std::transform(_tasks.cbegin(), _tasks.cend(), result->begin(),
[](const std::shared_ptr<Task>& node)
{
return std::make_shared<TaskEdge>(node);
});
return result;
}
private:
std::shared_ptr<PageInfo> _pageInfo;
std::vector<std::shared_ptr<Task>> _tasks;
};
class Folder : public object::Folder
{
public:
explicit Folder(std::vector<unsigned char>&& id, std::string&& name, int unreadCount);
std::vector<unsigned char> getId() const override { return _id; }
std::unique_ptr<std::string> getName() const override { return std::unique_ptr<std::string>(new std::string(_name)); }
int getUnreadCount() const override { return _unreadCount; }
private:
std::vector<unsigned char> _id;
std::string _name;
int _unreadCount;
};
class FolderEdge : public object::FolderEdge
{
public:
explicit FolderEdge(std::shared_ptr<Folder> folder)
: _folder(std::move(folder))
{
}
std::shared_ptr<object::Folder> getNode() const override
{
return std::static_pointer_cast<object::Folder>(_folder);
}
web::json::value getCursor() const override
{
return web::json::value::string(utility::conversions::to_base64(_folder->getId()));
}
private:
std::shared_ptr<Folder> _folder;
};
class FolderConnection : public object::FolderConnection
{
public:
explicit FolderConnection(bool hasNextPage, bool hasPreviousPage, std::vector<std::shared_ptr<Folder>> folders)
: _pageInfo(std::make_shared<PageInfo>(hasNextPage, hasPreviousPage))
, _folders(std::move(folders))
{
}
std::shared_ptr<object::PageInfo> getPageInfo() const override
{
return _pageInfo;
}
std::unique_ptr<std::vector<std::shared_ptr<object::FolderEdge>>> getEdges() const override
{
auto result = std::unique_ptr<std::vector<std::shared_ptr<object::FolderEdge>>>(new std::vector<std::shared_ptr<object::FolderEdge>>(_folders.size()));
std::transform(_folders.cbegin(), _folders.cend(), result->begin(),
[](const std::shared_ptr<Folder>& node)
{
return std::make_shared<FolderEdge>(node);
});
return result;
}
private:
std::shared_ptr<PageInfo> _pageInfo;
std::vector<std::shared_ptr<Folder>> _folders;
};
class CompleteTaskPayload : public object::CompleteTaskPayload
{
public:
explicit CompleteTaskPayload(std::shared_ptr<Task> task, std::unique_ptr<std::string>&& clientMutationId)
: _task(std::move(task))
, _clientMutationId(std::move(clientMutationId))
{
}
std::shared_ptr<object::Task> getTask() const override
{
return std::static_pointer_cast<object::Task>(_task);
}
std::unique_ptr<std::string> getClientMutationId() const override
{
return std::unique_ptr<std::string>(_clientMutationId
? new std::string(*_clientMutationId)
: nullptr);
}
private:
std::shared_ptr<Task> _task;
std::unique_ptr<std::string> _clientMutationId;
};
class Mutation : public object::Mutation
{
public:
using completeTaskMutation = std::function<std::shared_ptr<CompleteTaskPayload>(CompleteTaskInput&&)>;
explicit Mutation(completeTaskMutation&& mutateCompleteTask);
std::shared_ptr<object::CompleteTaskPayload> getCompleteTask(CompleteTaskInput&& input) const override;
private:
completeTaskMutation _mutateCompleteTask;
};
class Subscription : public object::Subscription
{
public:
explicit Subscription() = default;
std::shared_ptr<object::Appointment> getNextAppointmentChange() const override
{
return nullptr;
}
};
} /* namespace today */
} /* namespace graphql */
} /* namespace facebook */