Skip to content

Commit fbbd02a

Browse files
committed
feat: implement Object resolver and possible types merge
1 parent b00f34b commit fbbd02a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

include/graphqlservice/GraphQLService.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,9 @@ class [[nodiscard("unnecessary construction")]] Object : public std::enable_shar
824824
GRAPHQLSERVICE_EXPORT explicit Object(TypeNames&& typeNames, ResolverMap&& resolvers) noexcept;
825825
GRAPHQLSERVICE_EXPORT virtual ~Object() = default;
826826

827+
[[nodiscard("unnecessary call")]] GRAPHQLSERVICE_EXPORT std::shared_ptr<Object> StitchObject(
828+
const std::shared_ptr<const Object>& added) const;
829+
827830
[[nodiscard("unnecessary call")]] GRAPHQLSERVICE_EXPORT AwaitableResolver resolve(
828831
const SelectionSetParams& selectionSetParams, const peg::ast_node& selection,
829832
const FragmentMap& fragments, const response::Value& variables) const;
@@ -846,6 +849,7 @@ class [[nodiscard("unnecessary construction")]] Object : public std::enable_shar
846849
private:
847850
TypeNames _typeNames;
848851
ResolverMap _resolvers;
852+
std::vector<std::shared_ptr<const Object>> _stitched;
849853
};
850854

851855
// Test if this Type inherits from Object.
@@ -1466,6 +1470,7 @@ class [[nodiscard("unnecessary construction")]] Request
14661470
collectRegistrations(std::string_view field, RequestDeliverFilter&& filter) const noexcept;
14671471

14681472
const TypeMap _operations;
1473+
const std::shared_ptr<schema::Schema> _schema;
14691474
mutable std::mutex _validationMutex {};
14701475
const std::unique_ptr<ValidateExecutableVisitor> _validation;
14711476
mutable std::mutex _subscriptionMutex {};

src/GraphQLService.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,37 @@ Object::Object(TypeNames&& typeNames, ResolverMap&& resolvers) noexcept
12221222
{
12231223
}
12241224

1225+
std::shared_ptr<Object> Object::StitchObject(const std::shared_ptr<const Object>& added) const
1226+
{
1227+
auto typeNames = _typeNames;
1228+
1229+
for (const auto& name : added->_typeNames)
1230+
{
1231+
typeNames.emplace(name);
1232+
}
1233+
1234+
auto resolvers = _resolvers;
1235+
bool hasStitchedResolvers = false;
1236+
1237+
for (const auto& [name, resolver] : added->_resolvers)
1238+
{
1239+
hasStitchedResolvers = resolvers.emplace(name, resolver).second || hasStitchedResolvers;
1240+
}
1241+
1242+
std::vector<std::shared_ptr<const Object>> stitched { shared_from_this() };
1243+
1244+
if (hasStitchedResolvers)
1245+
{
1246+
stitched.push_back(added);
1247+
}
1248+
1249+
auto object = std::make_shared<Object>(std::move(typeNames), std::move(resolvers));
1250+
1251+
object->_stitched = std::move(stitched);
1252+
1253+
return object;
1254+
}
1255+
12251256
AwaitableResolver Object::resolve(const SelectionSetParams& selectionSetParams,
12261257
const peg::ast_node& selection, const FragmentMap& fragments,
12271258
const response::Value& variables) const

0 commit comments

Comments
 (0)