Skip to content

Commit f4b0fbe

Browse files
committed
Break circular references between object::__Type
1 parent e477ba7 commit f4b0fbe

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

Introspection.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ std::vector<std::shared_ptr<object::__Type>> Schema::getTypes() const
6767

6868
std::shared_ptr<object::__Type> Schema::getQueryType() const
6969
{
70-
return _query.lock();
70+
return _query;
7171
}
7272

7373
std::shared_ptr<object::__Type> Schema::getMutationType() const
@@ -236,7 +236,12 @@ UnionType::UnionType(std::string name, std::string description)
236236

237237
void UnionType::AddPossibleTypes(std::vector<std::shared_ptr<object::__Type>> possibleTypes)
238238
{
239-
_possibleTypes = std::move(possibleTypes);
239+
_possibleTypes.resize(possibleTypes.size());
240+
std::transform(possibleTypes.cbegin(), possibleTypes.cend(), _possibleTypes.begin(),
241+
[](const std::shared_ptr<object::__Type>& shared)
242+
{
243+
return shared;
244+
});
240245
}
241246

242247
__TypeKind UnionType::getKind() const
@@ -255,7 +260,11 @@ std::unique_ptr<std::vector<std::shared_ptr<object::__Type>>> UnionType::getPoss
255260
{
256261
std::unique_ptr<std::vector<std::shared_ptr<object::__Type>>> result(new std::vector<std::shared_ptr<object::__Type>>(_possibleTypes.size()));
257262

258-
std::copy(_possibleTypes.cbegin(), _possibleTypes.cend(), result->begin());
263+
std::transform(_possibleTypes.cbegin(), _possibleTypes.cend(), result->begin(),
264+
[](const std::weak_ptr<object::__Type>& weak)
265+
{
266+
return weak.lock();
267+
});
259268

260269
return result;
261270
}
@@ -347,7 +356,7 @@ __TypeKind WrapperType::getKind() const
347356

348357
std::shared_ptr<object::__Type> WrapperType::getOfType() const
349358
{
350-
return _ofType;
359+
return _ofType.lock();
351360
}
352361

353362
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)
@@ -382,7 +391,7 @@ std::vector<std::shared_ptr<object::__InputValue>> Field::getArgs() const
382391

383392
std::shared_ptr<object::__Type> Field::getType() const
384393
{
385-
return _type;
394+
return _type.lock();
386395
}
387396

388397
bool Field::getIsDeprecated() const
@@ -419,7 +428,7 @@ std::unique_ptr<std::string> InputValue::getDescription() const
419428

420429
std::shared_ptr<object::__Type> InputValue::getType() const
421430
{
422-
return _type;
431+
return _type.lock();
423432
}
424433

425434
std::unique_ptr<std::string> InputValue::getDefaultValue() const

Introspection.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Schema : public object::__Schema
4141
std::vector<std::shared_ptr<object::__Directive>> getDirectives() const override;
4242

4343
private:
44-
std::weak_ptr<ObjectType> _query;
44+
std::shared_ptr<ObjectType> _query;
4545
std::shared_ptr<ObjectType> _mutation;
4646
std::shared_ptr<ObjectType> _subscription;
4747
std::unordered_map<std::string, size_t> _typeMap;
@@ -135,7 +135,7 @@ class UnionType : public BaseType
135135
private:
136136
const std::string _name;
137137

138-
std::vector<std::shared_ptr<object::__Type>> _possibleTypes;
138+
std::vector<std::weak_ptr<object::__Type>> _possibleTypes;
139139
};
140140

141141
struct EnumValueType
@@ -192,7 +192,7 @@ class WrapperType : public BaseType
192192

193193
private:
194194
const __TypeKind _kind;
195-
const std::shared_ptr<object::__Type> _ofType;
195+
const std::weak_ptr<object::__Type> _ofType;
196196
};
197197

198198
class Field : public object::__Field
@@ -213,7 +213,7 @@ class Field : public object::__Field
213213
const std::string _description;
214214
const std::unique_ptr<std::string> _deprecationReason;
215215
const std::vector<std::shared_ptr<InputValue>> _args;
216-
const std::shared_ptr<object::__Type> _type;
216+
const std::weak_ptr<object::__Type> _type;
217217
};
218218

219219
class InputValue : public object::__InputValue
@@ -232,7 +232,7 @@ class InputValue : public object::__InputValue
232232

233233
const std::string _name;
234234
const std::string _description;
235-
const std::shared_ptr<object::__Type> _type;
235+
const std::weak_ptr<object::__Type> _type;
236236
const std::string _defaultValue;
237237
};
238238

0 commit comments

Comments
 (0)