trustfall icon indicating copy to clipboard operation
trustfall copied to clipboard

Allow `@tag` values to be used in edge parameters

Open obi1kenobi opened this issue 1 year ago • 1 comments

Right now, edge parameters have to be literals:

{
    User {
        message(kind: "sms") {
            content @output
        }
    }
}

There's currently no way to use pass a tagged value as the message edge's kind parameter.

Here's one possible Trustfall extension that could make this work:

query UserMessages($kind: String @fromTag) {
    User {
        platform {
            kind @tag
        }

        message(kind: $kind) {
            content @output
        }
    }
}

This is still 100% valid GraphQL syntax (so we keep all the nice editor integrations) while not breaking anything that isn't already broken (Trustfall already requires implicit definition of query variables, so the "variables" portion of GraphQL integrations is already broken).

This is the first option I've found that preserves maximal GraphQL syntax compatibility while allowing using tagged values of any type (not just strings) to be used as edge parameters.

Specifically, the following changes would be needed:

  • new @fromTag directive that can be applied to variable definitions
  • define that tagged value names and names of query variables live in the same namespace (+ test for conflicts, etc.)
  • define that implicit definitions of query variables (like @filter(op: "=", value: ["$implicit"])) are as-if equivalent to explicit variable definitions (like query Name($implicit: String))
  • it is an error to mark a variable @fromTag if no tag by that name exists

obi1kenobi avatar Jul 11 '23 18:07 obi1kenobi

This also solves two other slightly more minor problems in the language:

  • Edge parameters can now also take variables — not limited only to literals anymore!
  • It codifies the behavior of our query variables with respect to how GraphQL treats variables, so our ("implicit") variables start being mere syntax sugar instead of compiler magic.

obi1kenobi avatar Jul 11 '23 19:07 obi1kenobi