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

Add select e2e test to demo issue when select within include #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ranmocy
Copy link

@ranmocy ranmocy commented Dec 2, 2023

First thanks for the awesome project!

I found an issue in my production code so here is the e2e test to reproduce it.
When I select only some fields in a nested table, and the select clause is within another include clause, this bug happens. It doesn't automatically filter the deleted nested items any more. If I explicit select the deleted field, then it works as expected.

If you run this test, you will see findFirst with include and select is failed, but findFirst with include and select deleted field is passed.

Failed test:

 FAIL  test/e2e/select.test.ts
  ● select › findFirst › with nested select › findFirst with include and select

    expect(received).toHaveLength(expected)

    Expected length: 1
    Received length: 2
    Received array:  [{"id": 1}, {"id": 2}]

      224 |         expect(foundUser!.posts).toHaveLength(1);
      225 |         // TODO: this should be 1
    > 226 |         expect(foundUser!.posts[0].comments).toHaveLength(1);
          |                                              ^
      227 |         expect(foundUser!.posts[0].comments[0].id).toBe(comment1.id);
      228 |       });

I suspect it's due to this part of the code, as it skips the recursion:

export const createSelectParams: CreateParams = (config, params) => {
// selects in includes are handled by createIncludeParams
if (params.scope?.parentParams.operation === "include") {
return { params };
}

But I'm not sure yet what's the right fix, or if there are any other pitfalls ahead.

@olivierwilkinson
Copy link
Owner

Thank you for raising this, and for the e2e test!

I'm not sure right now what the fix is, but I will get to it as soon as I can 😄

I'm glad you are finding the library helpful, please don't hesitate to raise any other issues you find or any ideas you have 🙏

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

Successfully merging this pull request may close these issues.

2 participants