Skip to content

Commit fbdad10

Browse files
committed
Try a more limited version of #126
1 parent 5b995d1 commit fbdad10

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

include/graphqlservice/GraphQLService.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,14 +947,17 @@ struct SubscriptionData : std::enable_shared_from_this<SubscriptionData>
947947
const peg::ast_node& selection;
948948
};
949949

950+
// Forward declare just the class type so we can reference it in the Request::_validation member.
951+
class ValidateExecutableVisitor;
952+
950953
// Request scans the fragment definitions and finds the right operation definition to interpret
951954
// depending on the operation name (which might be empty for a single-operation document). It
952955
// also needs the values of the request variables.
953956
class Request : public std::enable_shared_from_this<Request>
954957
{
955958
protected:
956959
GRAPHQLSERVICE_EXPORT explicit Request(TypeMap&& operationTypes);
957-
GRAPHQLSERVICE_EXPORT virtual ~Request() = default;
960+
GRAPHQLSERVICE_EXPORT virtual ~Request();
958961

959962
public:
960963
GRAPHQLSERVICE_EXPORT std::vector<schema_error> validate(peg::ast& query) const;
@@ -1025,6 +1028,7 @@ class Request : public std::enable_shared_from_this<Request>
10251028
const std::string& operationName, response::Value&& variables) const;
10261029

10271030
TypeMap _operations;
1031+
std::unique_ptr<ValidateExecutableVisitor> _validation;
10281032
std::map<SubscriptionKey, std::shared_ptr<SubscriptionData>> _subscriptions;
10291033
std::unordered_map<SubscriptionName, std::set<SubscriptionKey>> _listeners;
10301034
SubscriptionKey _nextKey = 0;

src/GraphQLService.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,20 +1759,25 @@ void SubscriptionDefinitionVisitor::visitInlineFragment(const peg::ast_node& inl
17591759

17601760
Request::Request(TypeMap&& operationTypes)
17611761
: _operations(std::move(operationTypes))
1762+
, _validation(std::make_unique<ValidateExecutableVisitor>(*this))
17621763
{
17631764
}
17641765

1766+
Request::~Request()
1767+
{
1768+
// The default implementation is fine, but it can't be declared as = default because it needs to
1769+
// know how to destroy the _validation member and it can't do that with just a forward
1770+
// declaration of the class.
1771+
}
1772+
17651773
std::vector<schema_error> Request::validate(peg::ast& query) const
17661774
{
17671775
std::vector<schema_error> errors;
17681776

17691777
if (!query.validated)
17701778
{
1771-
ValidateExecutableVisitor visitor(*this);
1772-
1773-
visitor.visit(*query.root);
1774-
1775-
errors = visitor.getStructuredErrors();
1779+
_validation->visit(*query.root);
1780+
errors = _validation->getStructuredErrors();
17761781
query.validated = errors.empty();
17771782
}
17781783

0 commit comments

Comments
 (0)