trustfall icon indicating copy to clipboard operation
trustfall copied to clipboard

Lint: Unnecessary `@fold @transform(op: "count") @filter(op: ">", value: ["$zero"])` on "X to one" edge

Open obi1kenobi opened this issue 1 year ago • 0 comments

Consider this schema:

type Post {
    content: String!

    author: User  # or optionally `User!` -- same in both cases
}

type User {
    name: String!
}

and this query:

{
    Post {
        content @output

        author @fold @transform(op: "count") @filter(op: ">", value: ["$zero"]) {
            name @filter(op: "=", value: ["$author"])
        }
    }
}

The @fold @transform(op: "count") @filter(op: ">", value: ["$zero"]) part can be removed without changing the query semantics at all, since:

  • The author edge returns a maximum of one neighboring vertex.
  • If there is no author, the result would be discarded both with and without the fold.
  • Nothing is output from the fold, so none of the output types change.

obi1kenobi avatar Jul 07 '23 16:07 obi1kenobi