Skip to content

Commit 7d8e661

Browse files
committed
Add @deprecated support and official Introspection schema
1 parent e0289c6 commit 7d8e661

9 files changed

+544
-378
lines changed

Introspection.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ void EnumType::AddEnumValues(std::vector<EnumValueType> enumValues)
272272

273273
for (auto& value : enumValues)
274274
{
275-
_enumValues.push_back(std::make_shared<EnumValue>(std::move(value.value), std::move(value.description)));
275+
_enumValues.push_back(std::make_shared<EnumValue>(std::move(value.value),
276+
std::move(value.description),
277+
std::unique_ptr<std::string>(value.deprecationReason
278+
? new std::string(value.deprecationReason)
279+
: nullptr)));
276280
}
277281
}
278282

@@ -346,9 +350,10 @@ std::shared_ptr<object::__Type> WrapperType::getOfType() const
346350
return _ofType;
347351
}
348352

349-
Field::Field(std::string name, std::string description, std::vector<std::shared_ptr<InputValue>> args, std::shared_ptr<object::__Type> type)
353+
Field::Field(std::string name, std::string description, std::unique_ptr<std::string>&& deprecationReason, std::vector<std::shared_ptr<InputValue>> args, std::shared_ptr<object::__Type> type)
350354
: _name(std::move(name))
351355
, _description(std::move(description))
356+
, _deprecationReason(std::move(deprecationReason))
352357
, _args(std::move(args))
353358
, _type(std::move(type))
354359
{
@@ -382,12 +387,14 @@ std::shared_ptr<object::__Type> Field::getType() const
382387

383388
bool Field::getIsDeprecated() const
384389
{
385-
return false;
390+
return _deprecationReason != nullptr;
386391
}
387392

388393
std::unique_ptr<std::string> Field::getDeprecationReason() const
389394
{
390-
return nullptr;
395+
return _deprecationReason
396+
? std::unique_ptr<std::string>(new std::string(*_deprecationReason))
397+
: nullptr;
391398
}
392399

393400
InputValue::InputValue(std::string name, std::string description, std::shared_ptr<object::__Type> type, const rapidjson::Value& defaultValue)
@@ -477,9 +484,10 @@ std::string InputValue::formatDefaultValue(const rapidjson::Value& defaultValue)
477484
return output.str();
478485
}
479486

480-
EnumValue::EnumValue(std::string name, std::string description)
487+
EnumValue::EnumValue(std::string name, std::string description, std::unique_ptr<std::string>&& deprecationReason)
481488
: _name(std::move(name))
482489
, _description(std::move(description))
490+
, _deprecationReason(std::move(deprecationReason))
483491
{
484492
}
485493

@@ -497,12 +505,14 @@ std::unique_ptr<std::string> EnumValue::getDescription() const
497505

498506
bool EnumValue::getIsDeprecated() const
499507
{
500-
return false;
508+
return _deprecationReason != nullptr;
501509
}
502510

503511
std::unique_ptr<std::string> EnumValue::getDeprecationReason() const
504512
{
505-
return nullptr;
513+
return _deprecationReason
514+
? std::unique_ptr<std::string>(new std::string(*_deprecationReason))
515+
: nullptr;
506516
}
507517

508518
} /* namespace facebook */

Introspection.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ struct EnumValueType
142142
{
143143
std::string value;
144144
std::string description;
145+
const char* deprecationReason;
145146
};
146147

147148
class EnumType : public BaseType
@@ -197,7 +198,7 @@ class WrapperType : public BaseType
197198
class Field : public object::__Field
198199
{
199200
public:
200-
explicit Field(std::string name, std::string description, std::vector<std::shared_ptr<InputValue>> args, std::shared_ptr<object::__Type> type);
201+
explicit Field(std::string name, std::string description, std::unique_ptr<std::string>&& deprecationReason, std::vector<std::shared_ptr<InputValue>> args, std::shared_ptr<object::__Type> type);
201202

202203
// Accessors
203204
std::string getName() const override;
@@ -210,6 +211,7 @@ class Field : public object::__Field
210211
private:
211212
const std::string _name;
212213
const std::string _description;
214+
const std::unique_ptr<std::string> _deprecationReason;
213215
const std::vector<std::shared_ptr<InputValue>> _args;
214216
const std::shared_ptr<object::__Type> _type;
215217
};
@@ -237,7 +239,7 @@ class InputValue : public object::__InputValue
237239
class EnumValue : public object::__EnumValue
238240
{
239241
public:
240-
explicit EnumValue(std::string name, std::string description);
242+
explicit EnumValue(std::string name, std::string description, std::unique_ptr<std::string>&& deprecationReason);
241243

242244
// Accessors
243245
std::string getName() const override;
@@ -248,6 +250,7 @@ class EnumValue : public object::__EnumValue
248250
private:
249251
const std::string _name;
250252
const std::string _description;
253+
const std::unique_ptr<std::string> _deprecationReason;
251254
};
252255

253256
} /* namespace facebook */

0 commit comments

Comments
 (0)