edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

`e.op(optional, "??", required)` cardinality

Open jackfischer opened this issue 2 years ago • 2 comments

Follow up from discord

Code The code causing the error.

  name: e.op(a.optionalProperty, "??", a.requiredProperty),

Schema

Your application schema.

type A {
optionalProperty: str;
required requiredProperty: str;
}

Generated EdgeQL

...
    SELECT __scope_1_defaultOrganization {
      name := (__scope_1_defaultA.optionalProperty ?? __scope_1_defaultA.requiredProperty)
    }
...

Run the .toEdgeQL() method on your query and print the result. Then copy the generated query here.

Error or desired behavior

name infers to string | null instead of the expected string.

Versions (please complete the following information):

  • OS: macos 13
  • EdgeDB version (e.g. 2.0): 3.0
  • EdgeDB CLI version (e.g. 2.0): 3.3.0+3f6a0a0
  • edgedb-js version (e.g. 0.20.10;): 1.3.2
  • @edgedb/generate version (e.g. 0.0.7;): 0.3.0
  • Typescript version: 5.1.6
  • Node/Deno version:

jackfischer avatar Jul 06 '23 19:07 jackfischer

I'd like to call out too a type's declared property cannot override cardinality when computing like this. i.e. @jackfischer example above is different than

 optionalProperty: e.op(a.optionalProperty, "??", a.requiredProperty),

But it would be great if both inferred the correct cardinality to TS.

CarsonF avatar Jul 06 '23 19:07 CarsonF