You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current version has no built-in mechanism to prevent invalid clause orders, as nothing prevents or warns the user from doing the following:
$n = Query::node()->withVariable('n');
$query = Query::new()
->match($n)
->orderBy($n->property('age'))
->returning($n)
->build();
// MATCH (n) ORDER BY n.age RETURN n
The above query is invalid, since ORDER BY may only be used after a RETURN or WITH clause.
The fact that the DSL allows this is undesirable for two reasons:
An invalid query may be executed on a database, leading to a runtime error;
It weakens the static analysis capabilities of the DSL, since there is no way for your IDE to warn you about the invalid query or to give hints about which clauses can follow the previous.
Possible solution
My proposal to fix this is as follows:
Create an interface for each clause that only contains the signatures for the builder methods that make sense on that clause (for example, the ReturnQuery interface would have the signature for orderBy, but the CreateQuery interface would not).
Have each builder method specify as a type hint the interface of the clause it adds to the query. That is, the returning method specific it returns a ReturnQuery, the call method a CallQuery and so on.
Have the Query class implement all interfaces.
If a user now tries to build the query above, their IDE should warn them that the orderBy method is not part of the MatchQuery interface.
The text was updated successfully, but these errors were encountered:
The current version has no built-in mechanism to prevent invalid clause orders, as nothing prevents or warns the user from doing the following:
The above query is invalid, since
ORDER BY
may only be used after aRETURN
orWITH
clause.The fact that the DSL allows this is undesirable for two reasons:
Possible solution
My proposal to fix this is as follows:
ReturnQuery
interface would have the signature fororderBy
, but theCreateQuery
interface would not).returning
method specific it returns aReturnQuery
, thecall
method aCallQuery
and so on.Query
class implement all interfaces.If a user now tries to build the query above, their IDE should warn them that the
orderBy
method is not part of theMatchQuery
interface.The text was updated successfully, but these errors were encountered: