Skip to content

Commit 93d25f3

Browse files
committed
Consolidate the lazy loading in Today.* and use move semantics throughout
1 parent e6c1ccb commit 93d25f3

File tree

5 files changed

+188
-320
lines changed

5 files changed

+188
-320
lines changed

GraphQLService.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,37 +122,37 @@ std::vector<unsigned char> ModifiedArgument<std::vector<unsigned char>>::convert
122122
}
123123

124124
template <>
125-
web::json::value ModifiedResult<int>::convert(const int& result, ResolverParams)
125+
web::json::value ModifiedResult<int>::convert(const int& result, ResolverParams&&)
126126
{
127127
return web::json::value::number(result);
128128
}
129129

130130
template <>
131-
web::json::value ModifiedResult<double>::convert(const double& result, ResolverParams)
131+
web::json::value ModifiedResult<double>::convert(const double& result, ResolverParams&&)
132132
{
133133
return web::json::value::number(result);
134134
}
135135

136136
template <>
137-
web::json::value ModifiedResult<std::string>::convert(const std::string& result, ResolverParams)
137+
web::json::value ModifiedResult<std::string>::convert(const std::string& result, ResolverParams&&)
138138
{
139139
return web::json::value::string(utility::conversions::to_string_t(result));
140140
}
141141

142142
template <>
143-
web::json::value ModifiedResult<bool>::convert(const bool& result, ResolverParams)
143+
web::json::value ModifiedResult<bool>::convert(const bool& result, ResolverParams&&)
144144
{
145145
return web::json::value::boolean(result);
146146
}
147147

148148
template <>
149-
web::json::value ModifiedResult<web::json::value>::convert(const web::json::value& result, ResolverParams)
149+
web::json::value ModifiedResult<web::json::value>::convert(const web::json::value& result, ResolverParams&&)
150150
{
151151
return result;
152152
}
153153

154154
template <>
155-
web::json::value ModifiedResult<std::vector<unsigned char>>::convert(const std::vector<unsigned char>& result, ResolverParams)
155+
web::json::value ModifiedResult<std::vector<unsigned char>>::convert(const std::vector<unsigned char>& result, ResolverParams&&)
156156
{
157157
try
158158
{
@@ -170,7 +170,7 @@ web::json::value ModifiedResult<std::vector<unsigned char>>::convert(const std::
170170
}
171171

172172
template <>
173-
web::json::value ModifiedResult<Object>::convert(const std::shared_ptr<Object>& result, ResolverParams params)
173+
web::json::value ModifiedResult<Object>::convert(const std::shared_ptr<Object>& result, ResolverParams&& params)
174174
{
175175
if (!result)
176176
{
@@ -185,7 +185,7 @@ web::json::value ModifiedResult<Object>::convert(const std::shared_ptr<Object>&
185185
return result->resolve(*params.selection, params.fragments, params.variables);
186186
}
187187

188-
Object::Object(TypeNames typeNames, ResolverMap resolvers)
188+
Object::Object(TypeNames&& typeNames, ResolverMap&& resolvers)
189189
: _typeNames(std::move(typeNames))
190190
, _resolvers(std::move(resolvers))
191191
{
@@ -215,7 +215,7 @@ web::json::value Object::resolve(const ast::SelectionSet& selection, const Fragm
215215
return result;
216216
}
217217

218-
Request::Request(TypeMap operationTypes)
218+
Request::Request(TypeMap&& operationTypes)
219219
: _operations(std::move(operationTypes))
220220
{
221221
}

GraphQLService.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct ResolverParams
6666
const web::json::object& variables;
6767
};
6868

69-
using Resolver = std::function<web::json::value(ResolverParams)>;
69+
using Resolver = std::function<web::json::value(ResolverParams&&)>;
7070
using ResolverMap = std::unordered_map<std::string, Resolver>;
7171

7272
// Types be wrapped non-null or list types in GraphQL. Since nullability is a more special case
@@ -100,7 +100,7 @@ struct ModifiedArgument
100100
>::type;
101101

102102
// Peel off the none modifier. If it's included, it should always be last in the list.
103-
static type require(typename std::conditional<TypeModifier::None == _Modifier, std::string, DisableNone>::type name,
103+
static type require(const typename std::conditional<TypeModifier::None == _Modifier, std::string, DisableNone>::type& name,
104104
const web::json::object& arguments)
105105
{
106106
static_assert(TypeModifier::None == _Modifier, "this is the empty version");
@@ -111,7 +111,7 @@ struct ModifiedArgument
111111
}
112112

113113
// Peel off nullable modifiers.
114-
static type require(typename std::conditional<TypeModifier::Nullable == _Modifier, std::string, DisableNullable>::type name,
114+
static type require(const typename std::conditional<TypeModifier::Nullable == _Modifier, std::string, DisableNullable>::type& name,
115115
const web::json::object& arguments)
116116
{
117117
static_assert(TypeModifier::Nullable == _Modifier, "this is the nullable version");
@@ -140,7 +140,7 @@ struct ModifiedArgument
140140
}
141141

142142
// Peel off list modifiers.
143-
static type require(typename std::conditional<TypeModifier::List == _Modifier, std::string, DisableList>::type name,
143+
static type require(const typename std::conditional<TypeModifier::List == _Modifier, std::string, DisableList>::type& name,
144144
const web::json::object& arguments)
145145
{
146146
static_assert(TypeModifier::List == _Modifier, "this is the list version");
@@ -171,7 +171,7 @@ struct ModifiedArgument
171171
}
172172
}
173173

174-
static std::pair<type, bool> find(std::string name, const web::json::object& arguments) noexcept
174+
static std::pair<type, bool> find(const std::string& name, const web::json::object& arguments) noexcept
175175
{
176176
try
177177
{
@@ -193,7 +193,7 @@ struct ModifiedArgument<_Type, TypeModifier::None>
193193
using type = _Type;
194194

195195
// Call convert on this type without any other modifiers.
196-
static _Type require(std::string name, const web::json::object& arguments)
196+
static _Type require(const std::string& name, const web::json::object& arguments)
197197
{
198198
try
199199
{
@@ -209,7 +209,7 @@ struct ModifiedArgument<_Type, TypeModifier::None>
209209
}
210210

211211
// Wrap require in a try/catch block.
212-
static std::pair<_Type, bool> find(std::string name, const web::json::object& arguments) noexcept
212+
static std::pair<_Type, bool> find(const std::string& name, const web::json::object& arguments) noexcept
213213
{
214214
try
215215
{
@@ -248,7 +248,7 @@ using TypeNames = std::unordered_set<std::string>;
248248
class Object : public std::enable_shared_from_this<Object>
249249
{
250250
public:
251-
explicit Object(TypeNames typeNames, ResolverMap resolvers);
251+
explicit Object(TypeNames&& typeNames, ResolverMap&& resolvers);
252252

253253
web::json::value resolve(const ast::SelectionSet& selection, const FragmentMap& fragments, const web::json::object& variables) const;
254254

@@ -283,7 +283,7 @@ struct ModifiedResult
283283

284284
// Peel off the none modifier. If it's included, it should always be last in the list.
285285
static web::json::value convert(const typename std::conditional<TypeModifier::None == _Modifier, type, DisableNone>::type& result,
286-
ResolverParams params)
286+
ResolverParams&& params)
287287
{
288288
static_assert(TypeModifier::None == _Modifier, "this is the empty version");
289289
static_assert(sizeof...(_Other) == 0, "TypeModifier::None should always be last in the list of modifiers if it's included at all");
@@ -295,7 +295,7 @@ struct ModifiedResult
295295
// Peel off nullable modifiers for std::shared_ptr<Object>.
296296
static web::json::value convert(const typename std::conditional<TypeModifier::Nullable == _Modifier
297297
&& std::is_same<std::shared_ptr<_Type>, typename ModifiedResult<_Type, _Other...>::type>::value, type, DisableNullableSharedPtr>::type& result,
298-
ResolverParams params)
298+
ResolverParams&& params)
299299
{
300300
static_assert(TypeModifier::Nullable == _Modifier, "this is the nullable version");
301301
static_assert(std::is_same<std::shared_ptr<_Type>, typename ModifiedResult<_Type, _Other...>::type>::value, "this is the shared_ptr version");
@@ -311,7 +311,7 @@ struct ModifiedResult
311311
// Peel off nullable modifiers for anything else, which should all be std::unique_ptr.
312312
static web::json::value convert(const typename std::conditional<TypeModifier::Nullable == _Modifier
313313
&& !std::is_same<std::shared_ptr<_Type>, typename ModifiedResult<_Type, _Other...>::type>::value, type, DisableNullable>::type& result,
314-
ResolverParams params)
314+
ResolverParams&& params)
315315
{
316316
static_assert(TypeModifier::Nullable == _Modifier, "this is the nullable version");
317317
static_assert(!std::is_same<std::shared_ptr<_Type>, typename ModifiedResult<_Type, _Other...>::type>::value, "this is the unique_ptr version");
@@ -326,7 +326,7 @@ struct ModifiedResult
326326

327327
// Peel off list modifiers.
328328
static web::json::value convert(const typename std::conditional<TypeModifier::List == _Modifier, type, DisableList>::type& result,
329-
ResolverParams params)
329+
ResolverParams&& params)
330330
{
331331
static_assert(TypeModifier::List == _Modifier, "this is the list version");
332332

@@ -335,7 +335,7 @@ struct ModifiedResult
335335
std::transform(result.cbegin(), result.cend(), value.as_array().begin(),
336336
[params](const typename ModifiedResult<_Type, _Other...>::type& element)
337337
{
338-
return ModifiedResult<_Type, _Other...>::convert(element, params);
338+
return ModifiedResult<_Type, _Other...>::convert(element, ResolverParams(params));
339339
});
340340

341341
return value;
@@ -352,7 +352,7 @@ struct ModifiedResult<_Type, TypeModifier::None>
352352

353353
// Convert a subclass of Object and call that specialization.
354354
static web::json::value convert(const typename std::conditional<!std::is_same<Object, _Type>::value && std::is_base_of<Object, _Type>::value,
355-
type, DisableNone>::type& result, ResolverParams params)
355+
type, DisableNone>::type& result, ResolverParams&& params)
356356
{
357357
static_assert(std::is_same<std::shared_ptr<_Type>, type>::value, "this is the derived object type");
358358

@@ -361,7 +361,7 @@ struct ModifiedResult<_Type, TypeModifier::None>
361361

362362
// Convert a single value of the specified type to JSON.
363363
static web::json::value convert(const typename std::conditional<!std::is_same<Object, _Type>::value && std::is_base_of<Object, _Type>::value,
364-
DisableNone, type>::type& result, ResolverParams params);
364+
DisableNone, type>::type& result, ResolverParams&& params);
365365
};
366366

367367
// Convenient type aliases for testing, generated code won't actually use these. These are also
@@ -381,7 +381,7 @@ template <TypeModifier... _Modifiers> using ObjectResult = ModifiedResult<Object
381381
class Request : public std::enable_shared_from_this<Request>
382382
{
383383
public:
384-
explicit Request(TypeMap operationTypes);
384+
explicit Request(TypeMap&& operationTypes);
385385

386386
web::json::value resolve(const ast::Node& document, const std::string& operationName, const web::json::object& variables) const;
387387

SchemaGenerator.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -949,13 +949,13 @@ class )cpp" << objectType.type << R"cpp(
949949
}
950950

951951
headerFile << R"cpp(
952-
web::json::value resolve__typename(service::ResolverParams params);
952+
web::json::value resolve__typename(service::ResolverParams&& params);
953953
)cpp";
954954

955955
if (objectType.type == queryType)
956956
{
957-
headerFile << R"cpp( web::json::value resolve__schema(service::ResolverParams params);
958-
web::json::value resolve__type(service::ResolverParams params);
957+
headerFile << R"cpp( web::json::value resolve__schema(service::ResolverParams&& params);
958+
web::json::value resolve__type(service::ResolverParams&& params);
959959
960960
std::shared_ptr<)cpp" << s_introspectionNamespace << R"cpp(::Schema> _schema;
961961
)cpp";
@@ -1066,7 +1066,7 @@ std::string Generator::getResolverDeclaration(const OutputField& outputField) co
10661066

10671067
fieldName[0] = std::toupper(fieldName[0]);
10681068
output << R"cpp( web::json::value resolve)cpp" << fieldName
1069-
<< R"cpp((service::ResolverParams params);
1069+
<< R"cpp((service::ResolverParams&& params);
10701070
)cpp";
10711071

10721072
return output.str();
@@ -1141,7 +1141,7 @@ template <>
11411141
template <>
11421142
web::json::value service::ModifiedResult<)cpp" << _schemaNamespace << R"cpp(::)cpp" << enumType.type
11431143
<< R"cpp(>::convert(const )cpp" << _schemaNamespace << R"cpp(::)cpp" << enumType.type
1144-
<< R"cpp(& value, ResolverParams)
1144+
<< R"cpp(& value, ResolverParams&&)
11451145
{
11461146
static const std::string s_names[] = {
11471147
)cpp";
@@ -1337,9 +1337,8 @@ namespace object {
13371337

13381338
fieldName[0] = std::toupper(fieldName[0]);
13391339
sourceFile << R"cpp( { ")cpp" << outputField.name
1340-
<< R"cpp(", std::bind(std::mem_fun(&)cpp" << objectType.type
1341-
<< R"cpp(::resolve)cpp" << fieldName
1342-
<< R"cpp(), this, std::placeholders::_1) })cpp";
1340+
<< R"cpp(", [this](service::ResolverParams&& params) { return resolve)cpp" << fieldName
1341+
<< R"cpp((std::move(params)); } })cpp";
13431342
}
13441343

13451344
if (!firstField)
@@ -1348,17 +1347,14 @@ namespace object {
13481347
)cpp";
13491348
}
13501349

1351-
sourceFile << R"cpp( { "__typename", std::bind(std::mem_fun(&)cpp" << objectType.type
1352-
<< R"cpp(::resolve__typename), this, std::placeholders::_1) })cpp";
1350+
sourceFile << R"cpp( { "__typename", [this](service::ResolverParams&& params) { return resolve__typename(std::move(params)); } })cpp";
13531351

13541352

13551353
if (objectType.type == queryType)
13561354
{
13571355
sourceFile << R"cpp(,
1358-
{ "__schema", std::bind(std::mem_fun(&)cpp" << objectType.type
1359-
<< R"cpp(::resolve__schema), this, std::placeholders::_1) },
1360-
{ "__type", std::bind(std::mem_fun(&)cpp" << objectType.type
1361-
<< R"cpp(::resolve__type), this, std::placeholders::_1) })cpp";
1356+
{ "__schema", [this](service::ResolverParams&& params) { return resolve__schema(std::move(params)); } },
1357+
{ "__type", [this](service::ResolverParams&& params) { return resolve__type(std::move(params)); } })cpp";
13621358
}
13631359

13641360
sourceFile << R"cpp(
@@ -1397,7 +1393,7 @@ namespace object {
13971393
sourceFile << R"cpp(
13981394
web::json::value )cpp" << objectType.type
13991395
<< R"cpp(::resolve)cpp" << fieldName
1400-
<< R"cpp((service::ResolverParams params)
1396+
<< R"cpp((service::ResolverParams&& params)
14011397
{
14021398
)cpp";
14031399

@@ -1500,7 +1496,7 @@ web::json::value )cpp" << objectType.type
15001496

15011497
sourceFile << R"cpp(
15021498
web::json::value )cpp" << objectType.type
1503-
<< R"cpp(::resolve__typename(service::ResolverParams)
1499+
<< R"cpp(::resolve__typename(service::ResolverParams&&)
15041500
{
15051501
return web::json::value::string(_XPLATSTR(")cpp" << objectType.type << R"cpp("));
15061502
}
@@ -1510,15 +1506,15 @@ web::json::value )cpp" << objectType.type
15101506
{
15111507
sourceFile << R"cpp(
15121508
web::json::value )cpp" << objectType.type
1513-
<< R"cpp(::resolve__schema(service::ResolverParams params)
1509+
<< R"cpp(::resolve__schema(service::ResolverParams&& params)
15141510
{
15151511
auto result = service::ModifiedResult<introspection::Schema>::convert(_schema, std::move(params));
15161512
15171513
return result;
15181514
}
15191515
15201516
web::json::value )cpp" << objectType.type
1521-
<< R"cpp(::resolve__type(service::ResolverParams params)
1517+
<< R"cpp(::resolve__type(service::ResolverParams&& params)
15221518
{
15231519
auto argName = service::ModifiedArgument<std::string>::require("name", params.arguments);
15241520
auto result = service::ModifiedResult<introspection::object::__Type, service::TypeModifier::Nullable>::convert(_schema->LookupType(argName), std::move(params));

0 commit comments

Comments
 (0)