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

Client extensions: result extensions should be applied after query extensions #20437

Closed
SevInf opened this issue Jul 28, 2023 · 0 comments · Fixed by #20438
Closed

Client extensions: result extensions should be applied after query extensions #20437

SevInf opened this issue Jul 28, 2023 · 0 comments · Fixed by #20438
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: clientExtensions
Milestone

Comments

@SevInf
Copy link
Contributor

SevInf commented Jul 28, 2023

f you are short-curcuting query call, result extensions would also be skipped. For example:

prisma.$extends({
    query: {
        $allOperations({ query, args }) {
              if (someCondition) return someMockedResponse
              return query(args)
         }
    }
}).$extends({
   result: {
      someModel: {
         computedField: { ...}
      }
   }
})

Imagine they are two separate extensions, not aware of each other and someMockedResponse perfectly mimics DB response for particular query. From the standpoint of mocking extension, it does everything correctly. However, return value of query extension acts as final decider on what gets returned from the query. So, in case mocking condition holds true, someMockedResponse would act as one and final result of the query and result extension will get skipped. So, mocked response won’t contain computedField, unlike normal request.

Result extensions should apply only and always after all query extensions are done and should not be observable in any way from within query extension.

Internal discussion

@SevInf SevInf self-assigned this Jul 28, 2023
@SevInf SevInf added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. topic: clientExtensions labels Jul 28, 2023
@SevInf SevInf added this to the 5.1.0 milestone Jul 28, 2023
@janpio janpio added the team/client Issue for team Client. label Jul 30, 2023
SevInf added a commit that referenced this issue Jul 31, 2023
…ensions (#20438)

* fix(client): Ensure result extensions are applied after all query extensions

Fix #20437

* Move recursive `applyExtensions` into it's own module
overbit pushed a commit to overbit/prisma that referenced this issue Jul 31, 2023
…ensions (prisma#20438)

* fix(client): Ensure result extensions are applied after all query extensions

Fix prisma#20437

* Move recursive `applyExtensions` into it's own module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: clientExtensions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants