Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix type of a computed prop in query builder #1114

Open
diksipav opened this issue Oct 7, 2024 · 0 comments
Open

Fix type of a computed prop in query builder #1114

diksipav opened this issue Oct 7, 2024 · 0 comments
Assignees

Comments

@diksipav
Copy link
Contributor

diksipav commented Oct 7, 2024

Schema

module default {
  type User {
    ...
    multi movies: Movie;
    multi shows: Show;
    multi documentaries: Documentary;

    multi watching_list := ( 
      select .movies union .shows
      order by .year
    );

    multi all_media := (
       select .movies union .shows union .documentaries
    )
  }

  abstract type Content {
    required year: int16;
    required title: str;
  }

  type Movie extending Content {
   required plot: str;
  }

  type Show extending Content {
   required seasons: int16;
  }

  type Documentary {
    required title: str;
    required plot: str;
  }
};

In the test below type of plot prop should be string | null.

const q = e.select(e.User, () => ({
      all_media: (all_media) => ({
        title: true,
        ...e.is(e.Content, { year: true }),
        ...e.is(e.Show, {
          seasons: true,
        }),
        plot: e.op(
          all_media.is(e.Movie).plot,
          "??",
          all_media.is(e.Documentary).plot,
        ),
      }),
    }));

    type qT = $infer<typeof q>;

    tc.assert<
      tc.IsExact<
        qT,
        {
          all_media: (
            | {
                title: string;
                plot: string;
                __typename: "default::Documentary";
              }
            | {
                title: string;
                plot: string;
                year: number;
                __typename: "default::Movie";
              }
            | {
                title: string;
                plot: string;
                year: number;
                seasons: number;
                __typename: "default::Show";
              }
          )[];
        }[]
      >
    >(true);

  • EdgeDB: "5.6+adb9e77"
  • EdgeDB CLI: EdgeDB CLI 5.4.0+fe09abc
  • edgedb-js: edgedb@1.5.12
  • @edgedb/generate): v0.5.6
  • Node: v22.4.1
@diksipav diksipav self-assigned this Oct 7, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant