-
Notifications
You must be signed in to change notification settings - Fork 45
/
QueryObject.cpp
327 lines (278 loc) · 20.2 KB
/
QueryObject.cpp
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// WARNING! Do not edit this file manually, your changes will be overwritten.
#include "QueryObject.h"
#include "NodeObject.h"
#include "AppointmentConnectionObject.h"
#include "TaskConnectionObject.h"
#include "FolderConnectionObject.h"
#include "AppointmentObject.h"
#include "TaskObject.h"
#include "FolderObject.h"
#include "NestedTypeObject.h"
#include "ExpensiveObject.h"
#include "UnionTypeObject.h"
#include "graphqlservice/internal/Introspection.h"
#include "graphqlservice/introspection/SchemaObject.h"
#include "graphqlservice/introspection/TypeObject.h"
#include <algorithm>
#include <functional>
#include <sstream>
#include <stdexcept>
#include <unordered_map>
using namespace std::literals;
namespace graphql::today {
namespace object {
Query::Query(std::unique_ptr<const Concept> pimpl) noexcept
: service::Object{ getTypeNames(), getResolvers() }
, _schema { GetSchema() }
, _pimpl { std::move(pimpl) }
{
}
service::TypeNames Query::getTypeNames() const noexcept
{
return {
R"gql(Query)gql"sv
};
}
service::ResolverMap Query::getResolvers() const noexcept
{
return {
{ R"gql(node)gql"sv, [this](service::ResolverParams&& params) { return resolveNode(std::move(params)); } },
{ R"gql(tasks)gql"sv, [this](service::ResolverParams&& params) { return resolveTasks(std::move(params)); } },
{ R"gql(__type)gql"sv, [this](service::ResolverParams&& params) { return resolve_type(std::move(params)); } },
{ R"gql(nested)gql"sv, [this](service::ResolverParams&& params) { return resolveNested(std::move(params)); } },
{ R"gql(anyType)gql"sv, [this](service::ResolverParams&& params) { return resolveAnyType(std::move(params)); } },
{ R"gql(default)gql"sv, [this](service::ResolverParams&& params) { return resolveDefault(std::move(params)); } },
{ R"gql(__schema)gql"sv, [this](service::ResolverParams&& params) { return resolve_schema(std::move(params)); } },
{ R"gql(expensive)gql"sv, [this](service::ResolverParams&& params) { return resolveExpensive(std::move(params)); } },
{ R"gql(tasksById)gql"sv, [this](service::ResolverParams&& params) { return resolveTasksById(std::move(params)); } },
{ R"gql(__typename)gql"sv, [this](service::ResolverParams&& params) { return resolve_typename(std::move(params)); } },
{ R"gql(appointments)gql"sv, [this](service::ResolverParams&& params) { return resolveAppointments(std::move(params)); } },
{ R"gql(unreadCounts)gql"sv, [this](service::ResolverParams&& params) { return resolveUnreadCounts(std::move(params)); } },
{ R"gql(testTaskState)gql"sv, [this](service::ResolverParams&& params) { return resolveTestTaskState(std::move(params)); } },
{ R"gql(unimplemented)gql"sv, [this](service::ResolverParams&& params) { return resolveUnimplemented(std::move(params)); } },
{ R"gql(appointmentsById)gql"sv, [this](service::ResolverParams&& params) { return resolveAppointmentsById(std::move(params)); } },
{ R"gql(unreadCountsById)gql"sv, [this](service::ResolverParams&& params) { return resolveUnreadCountsById(std::move(params)); } }
};
}
void Query::beginSelectionSet(const service::SelectionSetParams& params) const
{
_pimpl->beginSelectionSet(params);
}
void Query::endSelectionSet(const service::SelectionSetParams& params) const
{
_pimpl->endSelectionSet(params);
}
service::AwaitableResolver Query::resolveNode(service::ResolverParams&& params) const
{
auto argId = service::ModifiedArgument<response::IdType>::require("id", params.arguments);
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getNode(service::FieldParams { std::move(selectionSetParams), std::move(directives) }, std::move(argId));
resolverLock.unlock();
return service::ModifiedResult<Node>::convert<service::TypeModifier::Nullable>(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveAppointments(service::ResolverParams&& params) const
{
auto argFirst = service::ModifiedArgument<int>::require<service::TypeModifier::Nullable>("first", params.arguments);
auto argAfter = service::ModifiedArgument<response::Value>::require<service::TypeModifier::Nullable>("after", params.arguments);
auto argLast = service::ModifiedArgument<int>::require<service::TypeModifier::Nullable>("last", params.arguments);
auto argBefore = service::ModifiedArgument<response::Value>::require<service::TypeModifier::Nullable>("before", params.arguments);
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getAppointments(service::FieldParams { std::move(selectionSetParams), std::move(directives) }, std::move(argFirst), std::move(argAfter), std::move(argLast), std::move(argBefore));
resolverLock.unlock();
return service::ModifiedResult<AppointmentConnection>::convert(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveTasks(service::ResolverParams&& params) const
{
auto argFirst = service::ModifiedArgument<int>::require<service::TypeModifier::Nullable>("first", params.arguments);
auto argAfter = service::ModifiedArgument<response::Value>::require<service::TypeModifier::Nullable>("after", params.arguments);
auto argLast = service::ModifiedArgument<int>::require<service::TypeModifier::Nullable>("last", params.arguments);
auto argBefore = service::ModifiedArgument<response::Value>::require<service::TypeModifier::Nullable>("before", params.arguments);
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getTasks(service::FieldParams { std::move(selectionSetParams), std::move(directives) }, std::move(argFirst), std::move(argAfter), std::move(argLast), std::move(argBefore));
resolverLock.unlock();
return service::ModifiedResult<TaskConnection>::convert(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveUnreadCounts(service::ResolverParams&& params) const
{
auto argFirst = service::ModifiedArgument<int>::require<service::TypeModifier::Nullable>("first", params.arguments);
auto argAfter = service::ModifiedArgument<response::Value>::require<service::TypeModifier::Nullable>("after", params.arguments);
auto argLast = service::ModifiedArgument<int>::require<service::TypeModifier::Nullable>("last", params.arguments);
auto argBefore = service::ModifiedArgument<response::Value>::require<service::TypeModifier::Nullable>("before", params.arguments);
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getUnreadCounts(service::FieldParams { std::move(selectionSetParams), std::move(directives) }, std::move(argFirst), std::move(argAfter), std::move(argLast), std::move(argBefore));
resolverLock.unlock();
return service::ModifiedResult<FolderConnection>::convert(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveAppointmentsById(service::ResolverParams&& params) const
{
static const auto defaultArguments = []()
{
response::Value values(response::Type::Map);
response::Value entry;
entry = []()
{
response::Value elements(response::Type::List);
response::Value entry;
entry = response::Value(std::string(R"gql(ZmFrZUFwcG9pbnRtZW50SWQ=)gql"));
elements.emplace_back(std::move(entry));
return elements;
}();
values.emplace_back("ids", std::move(entry));
return values;
}();
auto pairIds = service::ModifiedArgument<response::IdType>::find<service::TypeModifier::List>("ids", params.arguments);
auto argIds = (pairIds.second
? std::move(pairIds.first)
: service::ModifiedArgument<response::IdType>::require<service::TypeModifier::List>("ids", defaultArguments));
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getAppointmentsById(service::FieldParams { std::move(selectionSetParams), std::move(directives) }, std::move(argIds));
resolverLock.unlock();
return service::ModifiedResult<Appointment>::convert<service::TypeModifier::List, service::TypeModifier::Nullable>(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveTasksById(service::ResolverParams&& params) const
{
auto argIds = service::ModifiedArgument<response::IdType>::require<service::TypeModifier::List>("ids", params.arguments);
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getTasksById(service::FieldParams { std::move(selectionSetParams), std::move(directives) }, std::move(argIds));
resolverLock.unlock();
return service::ModifiedResult<Task>::convert<service::TypeModifier::List, service::TypeModifier::Nullable>(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveUnreadCountsById(service::ResolverParams&& params) const
{
auto argIds = service::ModifiedArgument<response::IdType>::require<service::TypeModifier::List>("ids", params.arguments);
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getUnreadCountsById(service::FieldParams { std::move(selectionSetParams), std::move(directives) }, std::move(argIds));
resolverLock.unlock();
return service::ModifiedResult<Folder>::convert<service::TypeModifier::List, service::TypeModifier::Nullable>(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveNested(service::ResolverParams&& params) const
{
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getNested(service::FieldParams { std::move(selectionSetParams), std::move(directives) });
resolverLock.unlock();
return service::ModifiedResult<NestedType>::convert(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveUnimplemented(service::ResolverParams&& params) const
{
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getUnimplemented(service::FieldParams { std::move(selectionSetParams), std::move(directives) });
resolverLock.unlock();
return service::ModifiedResult<std::string>::convert(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveExpensive(service::ResolverParams&& params) const
{
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getExpensive(service::FieldParams { std::move(selectionSetParams), std::move(directives) });
resolverLock.unlock();
return service::ModifiedResult<Expensive>::convert<service::TypeModifier::List>(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveTestTaskState(service::ResolverParams&& params) const
{
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getTestTaskState(service::FieldParams { std::move(selectionSetParams), std::move(directives) });
resolverLock.unlock();
return service::ModifiedResult<TaskState>::convert(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveAnyType(service::ResolverParams&& params) const
{
auto argIds = service::ModifiedArgument<response::IdType>::require<service::TypeModifier::List>("ids", params.arguments);
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getAnyType(service::FieldParams { std::move(selectionSetParams), std::move(directives) }, std::move(argIds));
resolverLock.unlock();
return service::ModifiedResult<UnionType>::convert<service::TypeModifier::List, service::TypeModifier::Nullable>(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolveDefault(service::ResolverParams&& params) const
{
std::unique_lock resolverLock(_resolverMutex);
service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) };
auto directives = std::move(params.fieldDirectives);
auto result = _pimpl->getDefault(service::FieldParams { std::move(selectionSetParams), std::move(directives) });
resolverLock.unlock();
return service::ModifiedResult<std::string>::convert<service::TypeModifier::Nullable>(std::move(result), std::move(params));
}
service::AwaitableResolver Query::resolve_typename(service::ResolverParams&& params) const
{
return service::Result<std::string>::convert(std::string{ R"gql(Query)gql" }, std::move(params));
}
service::AwaitableResolver Query::resolve_schema(service::ResolverParams&& params) const
{
return service::Result<service::Object>::convert(std::static_pointer_cast<service::Object>(std::make_shared<introspection::object::Schema>(std::make_shared<introspection::Schema>(_schema))), std::move(params));
}
service::AwaitableResolver Query::resolve_type(service::ResolverParams&& params) const
{
auto argName = service::ModifiedArgument<std::string>::require("name", params.arguments);
const auto& baseType = _schema->LookupType(argName);
std::shared_ptr<introspection::object::Type> result { baseType ? std::make_shared<introspection::object::Type>(std::make_shared<introspection::Type>(baseType)) : nullptr };
return service::ModifiedResult<introspection::object::Type>::convert<service::TypeModifier::Nullable>(result, std::move(params));
}
} // namespace object
void AddQueryDetails(const std::shared_ptr<schema::ObjectType>& typeQuery, const std::shared_ptr<schema::Schema>& schema)
{
typeQuery->AddFields({
schema::Field::Make(R"gql(node)gql"sv, R"md([Object Identification](https://facebook.github.io/relay/docs/en/graphql-server-specification.html#object-identification))md"sv, std::nullopt, schema->LookupType(R"gql(Node)gql"sv), {
schema::InputValue::Make(R"gql(id)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(ID)gql"sv)), R"gql()gql"sv)
}),
schema::Field::Make(R"gql(appointments)gql"sv, R"md(Appointments [Connection](https://facebook.github.io/relay/docs/en/graphql-server-specification.html#connections))md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(AppointmentConnection)gql"sv)), {
schema::InputValue::Make(R"gql(first)gql"sv, R"md()md"sv, schema->LookupType(R"gql(Int)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(after)gql"sv, R"md()md"sv, schema->LookupType(R"gql(ItemCursor)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(last)gql"sv, R"md()md"sv, schema->LookupType(R"gql(Int)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(before)gql"sv, R"md()md"sv, schema->LookupType(R"gql(ItemCursor)gql"sv), R"gql()gql"sv)
}),
schema::Field::Make(R"gql(tasks)gql"sv, R"md(Tasks [Connection](https://facebook.github.io/relay/docs/en/graphql-server-specification.html#connections))md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(TaskConnection)gql"sv)), {
schema::InputValue::Make(R"gql(first)gql"sv, R"md()md"sv, schema->LookupType(R"gql(Int)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(after)gql"sv, R"md()md"sv, schema->LookupType(R"gql(ItemCursor)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(last)gql"sv, R"md()md"sv, schema->LookupType(R"gql(Int)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(before)gql"sv, R"md()md"sv, schema->LookupType(R"gql(ItemCursor)gql"sv), R"gql()gql"sv)
}),
schema::Field::Make(R"gql(unreadCounts)gql"sv, R"md(Folder unread counts [Connection](https://facebook.github.io/relay/docs/en/graphql-server-specification.html#connections))md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(FolderConnection)gql"sv)), {
schema::InputValue::Make(R"gql(first)gql"sv, R"md()md"sv, schema->LookupType(R"gql(Int)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(after)gql"sv, R"md()md"sv, schema->LookupType(R"gql(ItemCursor)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(last)gql"sv, R"md()md"sv, schema->LookupType(R"gql(Int)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(before)gql"sv, R"md()md"sv, schema->LookupType(R"gql(ItemCursor)gql"sv), R"gql()gql"sv)
}),
schema::Field::Make(R"gql(appointmentsById)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->WrapType(introspection::TypeKind::LIST, schema->LookupType(R"gql(Appointment)gql"sv))), {
schema::InputValue::Make(R"gql(ids)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->WrapType(introspection::TypeKind::LIST, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(ID)gql"sv)))), R"gql(["ZmFrZUFwcG9pbnRtZW50SWQ="])gql"sv)
}),
schema::Field::Make(R"gql(tasksById)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->WrapType(introspection::TypeKind::LIST, schema->LookupType(R"gql(Task)gql"sv))), {
schema::InputValue::Make(R"gql(ids)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->WrapType(introspection::TypeKind::LIST, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(ID)gql"sv)))), R"gql()gql"sv)
}),
schema::Field::Make(R"gql(unreadCountsById)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->WrapType(introspection::TypeKind::LIST, schema->LookupType(R"gql(Folder)gql"sv))), {
schema::InputValue::Make(R"gql(ids)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->WrapType(introspection::TypeKind::LIST, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(ID)gql"sv)))), R"gql()gql"sv)
}),
schema::Field::Make(R"gql(nested)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(NestedType)gql"sv))),
schema::Field::Make(R"gql(unimplemented)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(String)gql"sv))),
schema::Field::Make(R"gql(expensive)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->WrapType(introspection::TypeKind::LIST, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(Expensive)gql"sv))))),
schema::Field::Make(R"gql(testTaskState)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(TaskState)gql"sv))),
schema::Field::Make(R"gql(anyType)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->WrapType(introspection::TypeKind::LIST, schema->LookupType(R"gql(UnionType)gql"sv))), {
schema::InputValue::Make(R"gql(ids)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->WrapType(introspection::TypeKind::LIST, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(ID)gql"sv)))), R"gql()gql"sv)
}),
schema::Field::Make(R"gql(default)gql"sv, R"md(Test C++ keyword names)md"sv, std::nullopt, schema->LookupType(R"gql(String)gql"sv))
});
}
} // namespace graphql::today