albertoventurini / graphdb-intellij-plugin

Graph database plugin for the IntelliJ Platform
https://plugins.jetbrains.com/plugin/20417-graph-database
Apache License 2.0
53 stars 15 forks source link

Missing level of indentations an sub-queries and where clauses #74

Open reckter opened 1 year ago

reckter commented 1 year ago

Hey, thanks for the plugin!

I've noticed that sub queries and where clauses, do not get correctly intended. (at least in my opinion).

Example:

MATCH (subject:User)
    WHERE (subject.id = $subjectId) OR (subject.openId = $subjectId)
CALL {
WITH subject
CALL apoc.path.expandConfig(subject, {relationshipFilter: 'IS_IN',
                                      labelFilter:        '/User',
                                      uniqueness:         'NODE_GLOBAL'}) YIELD path

WITH nodes(path) AS nodes
UNWIND nodes AS n

WITH n
    WHERE
    (n.id = $userId) AND
    'User' IN labels(n)

RETURN n AS s
UNION
WITH subject
RETURN subject AS s
}
WITH s
    WHERE s.id = $userId
RETURN s

imo it should look like this:

MATCH (subject:User)
    WHERE (subject.id = $subjectId) OR (subject.openId = $subjectId)
CALL {
    WITH subject
    CALL apoc.path.expandConfig(subject, {
        relationshipFilter: 'IS_IN', 
        labelFilter:        '/User',
        uniqueness:         'NODE_GLOBAL'
    }) YIELD path

    WITH nodes(path) AS nodes
    UNWIND nodes AS n

    WITH n
        WHERE
            (n.id = $userId) AND
            'User' IN labels(n)

    RETURN n AS s
    UNION
    WITH subject
    RETURN subject AS s
}
WITH s
    WHERE s.id = $userId
RETURN s

(not sure on the apoc, call, no strong opinion there). The CALL {...} expresson and the WHERE expression should add an intendation imo