Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for shortest path examples in formatter #406

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tomasnyberg
Copy link
Contributor

Description

Greg noted that some of the examples from this page have some quirks that would be good to straighten out. This PR addresses those concerns, by making the following changes:

  • The selector (e.g. SHORTEST 1) now prefers not to split (and if it does, it lines up to the right of the path if there is one)
  • Fixed a grouping issue with listItemsPredicate
    • I considered forcing a break after the WHERE as well but that only made it worse in my opinion
  • Parenthesized paths with a quantifier prefer to stick together.
    • I considered a forced break after quantifiers, which looks good in some examples, but looks weird for e.g. this one MATCH (p)-[]->*(q)

Examples (from the page linked above)

Before

MATCH SHORTEST 1 (:Station {name: 'Hartlebury'}) (()--(n))+
                 (:Station {name: 'Cheltenham Spa'})
RETURN [stop IN n[.. -1] | stop.name] AS stops;

MATCH SHORTEST 1 ((:Station {name: 'Hartlebury'}) (()--(n:Station))+
                 (:Station {name: 'Cheltenham Spa'}) WHERE none(
                 stop IN n[.. -1] WHERE stop.name = 'Bromsgrove'))
RETURN [stop IN n[.. -1] | stop.name] AS stops;

MATCH p = SHORTEST
      1 ((:Station {name: 'Thisisanabsurdlylongnametomakeitawkward'})
        (()--(n:Station))+(:Station {name: 'Cheltenham Spa'}) WHERE none(
        stop IN n[.. -1] WHERE stop.name = 'Bromsgrove'))
RETURN [stop IN n[.. -1] | stop.name] AS stops;

MATCH path = ANY (:Station {name: 'Pershore'})-[l:LINK WHERE l.distance < 10]-+
                 (b:Station {name: 'Bromsgrove'})
RETURN [r IN relationships(path) | r.distance] AS distances

After

MATCH SHORTEST 1 (:Station {name: 'Hartlebury'}) (()--(n))+
                 (:Station {name: 'Cheltenham Spa'})
RETURN [stop IN n[.. -1] | stop.name] AS stops;

MATCH SHORTEST 1 ((:Station {name: 'Hartlebury'}) (()--(n:Station))+
                  (:Station {name: 'Cheltenham Spa'}) WHERE
                  none(stop IN n[.. -1] WHERE stop.name = 'Bromsgrove'))
RETURN [stop IN n[.. -1] | stop.name] AS stops;

MATCH p = SHORTEST 1
          ((:Station {name: 'Thisisanabsurdlylongnametomakeitawkward'})
           (()--(n:Station))+(:Station {name: 'Cheltenham Spa'}) WHERE
           none(stop IN n[.. -1] WHERE stop.name = 'Bromsgrove'))
RETURN [stop IN n[.. -1] | stop.name] AS stops;

MATCH path = ANY (:Station {name: 'Pershore'})-[l:LINK WHERE l.distance < 10]-+
                 (b:Station {name: 'Bromsgrove'})
RETURN [r IN relationships(path) | r.distance] AS distances

Testing

  • Added tests for the queries listed above

Copy link

changeset-bot bot commented Mar 11, 2025

⚠️ No Changeset found

Latest commit: 1127baa

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant