Skip to content

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

@SevInf

Description

@SevInf

If 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions