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

Allow @tag values to be used in edge parameters #371

Open
obi1kenobi opened this issue Jul 11, 2023 · 1 comment
Open

Allow @tag values to be used in edge parameters #371

obi1kenobi opened this issue Jul 11, 2023 · 1 comment
Labels
A-syntax Area: query or schema syntax C-feature-request Category: request for new future functionality E-medium Call for participation: experience needed to fix: medium / intermediate

Comments

@obi1kenobi
Copy link
Owner

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 obi1kenobi added A-syntax Area: query or schema syntax C-feature-request Category: request for new future functionality E-medium Call for participation: experience needed to fix: medium / intermediate labels Jul 11, 2023
@obi1kenobi
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntax Area: query or schema syntax C-feature-request Category: request for new future functionality E-medium Call for participation: experience needed to fix: medium / intermediate
Projects
None yet
Development

No branches or pull requests

1 participant