Skip to content

Commit 75c3a2e

Browse files
committed
Un-nest some of the types in the response namespace
1 parent 593c272 commit 75c3a2e

14 files changed

+286
-284
lines changed

GraphQLResponse.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Value& Value::operator=(Value&& rhs)
172172
return *this;
173173
}
174174

175-
Value::Type Value::type() const
175+
Type Value::type() const
176176
{
177177
return _type;
178178
}
@@ -226,7 +226,7 @@ void Value::emplace_back(std::string&& name, Value&& value)
226226
_map->emplace_back(std::make_pair(std::move(name), std::move(value)));
227227
}
228228

229-
Value::MapType::const_iterator Value::find(const std::string& name) const
229+
MapType::const_iterator Value::find(const std::string& name) const
230230
{
231231
if (_type != Type::Map)
232232
{
@@ -276,7 +276,7 @@ const Value& Value::operator[](size_t index) const
276276
}
277277

278278
template <>
279-
void Value::set<Value::StringType>(StringType&& value)
279+
void Value::set<StringType>(StringType&& value)
280280
{
281281
if (_type != Type::String
282282
&& _type != Type::EnumValue)
@@ -288,7 +288,7 @@ void Value::set<Value::StringType>(StringType&& value)
288288
}
289289

290290
template <>
291-
void Value::set<Value::BooleanType>(BooleanType&& value)
291+
void Value::set<BooleanType>(BooleanType&& value)
292292
{
293293
if (_type != Type::Boolean)
294294
{
@@ -299,7 +299,7 @@ void Value::set<Value::BooleanType>(BooleanType&& value)
299299
}
300300

301301
template <>
302-
void Value::set<Value::IntType>(IntType&& value)
302+
void Value::set<IntType>(IntType&& value)
303303
{
304304
if (_type != Type::Int)
305305
{
@@ -310,7 +310,7 @@ void Value::set<Value::IntType>(IntType&& value)
310310
}
311311

312312
template <>
313-
void Value::set<Value::FloatType>(FloatType&& value)
313+
void Value::set<FloatType>(FloatType&& value)
314314
{
315315
if (_type != Type::Float)
316316
{
@@ -321,7 +321,7 @@ void Value::set<Value::FloatType>(FloatType&& value)
321321
}
322322

323323
template <>
324-
void Value::set<Value::ScalarType>(ScalarType&& value)
324+
void Value::set<ScalarType>(ScalarType&& value)
325325
{
326326
if (_type != Type::Scalar)
327327
{
@@ -332,7 +332,7 @@ void Value::set<Value::ScalarType>(ScalarType&& value)
332332
}
333333

334334
template <>
335-
const Value::MapType& Value::get<const Value::MapType&>() const
335+
const MapType& Value::get<const MapType&>() const
336336
{
337337
if (_type != Type::Map)
338338
{
@@ -343,7 +343,7 @@ const Value::MapType& Value::get<const Value::MapType&>() const
343343
}
344344

345345
template <>
346-
const Value::ListType& Value::get<const Value::ListType&>() const
346+
const ListType& Value::get<const ListType&>() const
347347
{
348348
if (_type != Type::List)
349349
{
@@ -354,7 +354,7 @@ const Value::ListType& Value::get<const Value::ListType&>() const
354354
}
355355

356356
template <>
357-
const Value::StringType& Value::get<const Value::StringType&>() const
357+
const StringType& Value::get<const StringType&>() const
358358
{
359359
if (_type != Type::String
360360
&& _type != Type::EnumValue)
@@ -366,7 +366,7 @@ const Value::StringType& Value::get<const Value::StringType&>() const
366366
}
367367

368368
template <>
369-
Value::BooleanType Value::get<Value::BooleanType>() const
369+
BooleanType Value::get<BooleanType>() const
370370
{
371371
if (_type != Type::Boolean)
372372
{
@@ -377,7 +377,7 @@ Value::BooleanType Value::get<Value::BooleanType>() const
377377
}
378378

379379
template <>
380-
Value::IntType Value::get<Value::IntType>() const
380+
IntType Value::get<IntType>() const
381381
{
382382
if (_type != Type::Int)
383383
{
@@ -388,7 +388,7 @@ Value::IntType Value::get<Value::IntType>() const
388388
}
389389

390390
template <>
391-
Value::FloatType Value::get<Value::FloatType>() const
391+
FloatType Value::get<FloatType>() const
392392
{
393393
if (_type != Type::Float)
394394
{
@@ -399,7 +399,7 @@ Value::FloatType Value::get<Value::FloatType>() const
399399
}
400400

401401
template <>
402-
const Value::ScalarType& Value::get<const Value::ScalarType&>() const
402+
const ScalarType& Value::get<const ScalarType&>() const
403403
{
404404
if (_type != Type::Scalar)
405405
{
@@ -410,7 +410,7 @@ const Value::ScalarType& Value::get<const Value::ScalarType&>() const
410410
}
411411

412412
template <>
413-
Value::MapType Value::release<Value::MapType>()
413+
MapType Value::release<MapType>()
414414
{
415415
if (_type != Type::Map)
416416
{
@@ -425,7 +425,7 @@ Value::MapType Value::release<Value::MapType>()
425425
}
426426

427427
template <>
428-
Value::ListType Value::release<Value::ListType>()
428+
ListType Value::release<ListType>()
429429
{
430430
if (_type != Type::List)
431431
{
@@ -438,7 +438,7 @@ Value::ListType Value::release<Value::ListType>()
438438
}
439439

440440
template <>
441-
Value::StringType Value::release<Value::StringType>()
441+
StringType Value::release<StringType>()
442442
{
443443
if (_type != Type::String
444444
&& _type != Type::EnumValue)
@@ -452,7 +452,7 @@ Value::StringType Value::release<Value::StringType>()
452452
}
453453

454454
template <>
455-
Value::ScalarType Value::release<Value::ScalarType>()
455+
ScalarType Value::release<ScalarType>()
456456
{
457457
if (_type != Type::Scalar)
458458
{

GraphQLResponse.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,35 @@ namespace facebook {
1212
namespace graphql {
1313
namespace response {
1414

15-
// Represent a discriminated union of GraphQL response value types.
16-
struct Value
15+
// GraphQL responses are not technically JSON-specific, although that is probably the most common
16+
// way of representing them. These are the primitive types that may be represented in GraphQL, as
17+
// of the [June 2018 spec](https://facebook.github.io/graphql/June2018/#sec-Serialization-Format).
18+
enum class Type : uint8_t
1719
{
18-
// GraphQL responses are not technically JSON-specific, although that is probably the most common
19-
// way of representing them. These are the primitive types that may be represented in GraphQL, as
20-
// of the [June 2018 spec](https://facebook.github.io/graphql/June2018/#sec-Serialization-Format).
21-
enum class Type : uint8_t
22-
{
23-
Map, // JSON Object
24-
List, // JSON Array
25-
String, // JSON String
26-
Null, // JSON null
27-
Boolean, // JSON true or false
28-
Int, // JSON Number
29-
Float, // JSON Number
30-
EnumValue, // JSON String
31-
Scalar, // JSON any type
32-
};
20+
Map, // JSON Object
21+
List, // JSON Array
22+
String, // JSON String
23+
Null, // JSON null
24+
Boolean, // JSON true or false
25+
Int, // JSON Number
26+
Float, // JSON Number
27+
EnumValue, // JSON String
28+
Scalar, // JSON any type
29+
};
3330

34-
using MapType = std::vector<std::pair<std::string, Value>>;
35-
using ListType = std::vector<Value>;
36-
using StringType = std::string;
37-
using BooleanType = bool;
38-
using IntType = int;
39-
using FloatType = double;
40-
using ScalarType = Value;
31+
struct Value;
4132

33+
using MapType = std::vector<std::pair<std::string, Value>>;
34+
using ListType = std::vector<Value>;
35+
using StringType = std::string;
36+
using BooleanType = bool;
37+
using IntType = int;
38+
using FloatType = double;
39+
using ScalarType = Value;
40+
41+
// Represent a discriminated union of GraphQL response value types.
42+
struct Value
43+
{
4244
Value(Type type = Type::Null);
4345

4446
explicit Value(StringType&& value);

0 commit comments

Comments
 (0)