Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Polymorphic shapes that share property names are being shadowed #630

Open
scotttrinh opened this issue Jun 5, 2023 · 2 comments
Open

Polymorphic shapes that share property names are being shadowed #630

scotttrinh opened this issue Jun 5, 2023 · 2 comments
Assignees
Labels

Comments

@scotttrinh
Copy link
Collaborator

scotttrinh commented Jun 5, 2023

In the case that a query has polymorphic shapes where multiple subtypes return a shape that share the same property name, only the last subtype actually gets built into the final query.

Example:

e.select(e.Content, content => ({
  title: true,
  ...e.is(e.Movie, { link: true }),
  ...e.is(e.TVShow, { link: true }),
}));

In the above example, only the e.TVShow polymorphic shape is built into the final expression object that is transformed into EdgeQL.

@scotttrinh scotttrinh added the bug label Jun 5, 2023
@scotttrinh scotttrinh self-assigned this Jun 5, 2023
@scotttrinh
Copy link
Collaborator Author

scotttrinh commented Jun 6, 2023

As an aside, renaming the field using computed doesn't work due to how we look up the type:

https://github.com/edgedb/edgedb-js/blob/464b0988121e7183a8304b37014a096ff0d01895/packages/generate/src/syntax/typesystem.ts#L374-L383

We do not save the source key into the expression, so we match the key to the pointer's key.

So this does not work:

e.select(e.Content, content => ({
  title: true,
  movie_link: e.is(e.Movie, { link: true }).link,
  tv_show_link: e.is(e.TVShow, { link: true }).link,
}));

Since infer will look for e.Movie.movie_link instead of e.Movie.link in this case.

@dotlouis
Copy link

dotlouis commented Oct 13, 2023

Quick workaround to mimic union types and solve the above problem using the coalescing operator.
In EdgeQL

Select Content {
  release_year := [is Movie].release_year ?? [is TVShow].release_year
}

In query Builder (TS)

const q = e.select(e.Content, content => ({
        ...e.Content['*'],
        release_year: e.op(
          content.is(e.Movie).release_year,
          '??',
          content.is(e.TVShow).release_year,
        ),
      },
    }))

Other related issue : geldata/gel#1577

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants