target / goalert

Open source on-call scheduling, automated escalations, and notifications so you never miss a critical alert
https://goalert.me
Apache License 2.0
2.22k stars 240 forks source link

univ-keys: add Expr <-> Condition support #3778

Closed mastercactapus closed 5 months ago

mastercactapus commented 6 months ago

Description: Adds initial support for Expr expressions via GraphQL under the univ-keys experimental flag.

Describe any introduced API changes:

extend type Query {
  expr: Expr! @experimental(flagName: "univ-keys")
}

"""
Expr contains helpers for working with Expr expressions.
"""
type Expr {
  """
  exprToCondition converts an Expr expression to a Condition.
  """
  exprToCondition(input: ExprToConditionInput!): Condition!
    @goField(forceResolver: true)

  """
  conditionToExpr converts a Condition to an Expr expression.
  """
  conditionToExpr(input: ConditionToExprInput!): String!
    @goField(forceResolver: true)
}

Additional Info: To test, use make start EXPERIMENTAL=univ-keys

Example GraphQL Query for Explorer ```graphql query { expr { exprToCondition(input:{expr: "foo == \"bar\" and bin != 'baz' and baz in ['asdf','basfd']"}) { clauses { field operator value } } conditionToExpr(input: { condition: { clauses: [ { field: "foo", operator: "contains", value: "\"bar\"" }, { field: "foo", operator: "in", value: "[\"bar\"]" }, { field: "bin", operator: "!=", value: "\"baz\"" } ]} }) } } ```