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

Link property types are not inferred in a computed property

Open smstromb opened this issue 3 years ago • 0 comments

Version: 0.19.15

For the following schema:

  type User {
    required property auth0_id -> str {
      constraint exclusive;
    }
    
    multi link workspaces -> Workspace {
      property member_role -> WorkspaceRole;
      property title -> str;
  }

  type Workspace {
    required property name -> str;
    required property plan -> WorkspacePlan;
    property avatar -> str;
  }

  scalar type WorkspaceRole extending enum<ADMIN, STAFF, GUEST>;
  scalar type WorkspacePlan extending enum<FREE, PAID>;
type UserWorkspace = $infer<typeof getUserWorkspaceQuery>;

const getUserWorkspaceQuery = e.select(e.User, (user) => ({
  workspace: e.select(user.workspaces, (workspace) => ({
    id: true,
    name: true,
    avatar: true,
    plan: true,
    "@member_role": true,
    "@title": true,
    filter: e.op(workspace.id, "=", e.uuid(workspaceId)),
  })),
  filter: e.op(user.auth0_id, "=", context.auth.sub),
}));

getUserWorkspaceQuery.toEdgeQL():

WITH
  __scope_0_User := DETACHED default::User
SELECT __scope_0_User {
  single workspace := (
    WITH
      __scope_1_Workspace := (
        SELECT __scope_0_User.workspaces {
          __linkprop_member_role := __scope_0_User.workspaces@member_role,
          __linkprop_title := __scope_0_User.workspaces@title
        }
      )
    SELECT __scope_1_Workspace {
      id,
      name,
      avatar,
      plan,
      single @member_role := __scope_1_Workspace.__linkprop_member_role,
      single @title := __scope_1_Workspace.__linkprop_title
    }
    FILTER (__scope_1_Workspace.id = <std::uuid>"17f3d54ca64d11ec96178b61ef0689f4")
  )
}
FILTER (__scope_0_User.auth0_id = "sms|620d0f7178d57a7db2c8e3c9")

Issue:

@member_role and @title link properties are typed as never. However, the query actually does return data for the those two link properties.

Expected:

type UserWorkspace = {
    workspace: {
        name: string;
        id: string;
        plan: "FREE" | "PAID";
        avatar: string | null;
        "@member_role":  "ADMIN" | "STAFF" | "GUEST" | null;
        "@title":  string | null;
    } | null;
} | null

Actual:

type UserWorkspace = {
    workspace: {
        name: string;
        id: string;
        plan: "FREE" | "PAID";
        avatar: string | null;
        "@member_role":  never;
        "@title":  never;
    } | null;
} | null

smstromb avatar Mar 18 '22 14:03 smstromb