edgedb / edgedb-js

The official TypeScript/JS client library and query builder for EdgeDB
https://edgedb.com
Apache License 2.0
513 stars 66 forks source link

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

Open jackfischer opened 1 year ago

jackfischer commented 1 year ago

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):

CarsonF commented 1 year ago

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 commented 2 months ago

I believe this is fixed with #971?