Skip to content

Commit

Permalink
feat(qe): implement relationLoadStrategy query argument (#4601)
Browse files Browse the repository at this point in the history
Implement per-query configuration of relation load strategy as described in https://www.notion.so/prismaio/Relation-load-strategy-API-013e3ba957a34d45b4de1b722ca6804d, particularly [this section](https://www.notion.so/prismaio/Relation-load-strategy-API-013e3ba957a34d45b4de1b722ca6804d?pvs=4#045efb0e3cd54caeb6584d65f667fbb5) (Variant 1, only top level).

This allows to choose the relation load strategy for all relations in a single query.

Engine API:

```graphql
query {
  findManyUser(relationLoadStrategy: join) {
    login
    posts { title }
  }
}
```

Client API:

```ts
await prisma.user.findMany({
  relationLoadStrategy: 'join', // or 'query'
  select: {
    login: true,
    posts: {
      title: true,
    },
  },
})
```

The new `relationLoadStrategy` argument is available in the following operations:

- findMany
- findFirst
- findFirstOrThrow
- findUnique
- findUniqueOrThrow
- create
- update
- delete
- upsert

The argument is not available in the following operations:
- aggregate
- groupBy
- createMany
- updateMany
- deleteMany

Tests are included for all operations in this PR.

Additionally, it must not be available in the `count` operation, which needs to be handled separately on the client side, because `count` is a synthetic operation that does not exist in the query schema and is not known to the engine, and its TS types are generated based on `findMany` args rather than `aggregate` that it translates to.

Next steps:
- Finalize the Client integration PR
- Implement the global setting

Part of prisma/team-orm#703
Closes: prisma/team-orm#801
Client PR: prisma/prisma#22483
  • Loading branch information
aqrln authored Jan 9, 2024
1 parent 98ee706 commit 0a83d85
Show file tree
Hide file tree
Showing 19 changed files with 648 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .buildkite/engineer
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fi
# Check if the system has engineer installed, if not, use a local copy.
if ! type "engineer" &> /dev/null; then
# Setup Prisma engine build & test tool (engineer).
curl --fail -sSL "https://prisma-engineer.s3-eu-west-1.amazonaws.com/1.65/latest/$OS/engineer.gz" --output engineer.gz
curl --fail -sSL "https://prisma-engineer.s3-eu-west-1.amazonaws.com/1.66/latest/$OS/engineer.gz" --output engineer.gz
gzip -d engineer.gz
chmod +x engineer

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ services:

mysql-5-6:
image: mysql:5.6.50
command: mysqld
command: mysqld --table_definition_cache=2000
restart: unless-stopped
platform: linux/x86_64
environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ prisma-value = { path = "../../../libs/prisma-value" }
query-engine-metrics = { path = "../../metrics"}
once_cell = "1.15.0"
futures = "0.3"
paste = "1.0.14"

[dev-dependencies]
insta = "1.7.1"
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ mod native_upsert;
mod occ;
mod ref_actions;
mod regressions;
mod relation_load_strategy;
mod update_no_select;
mod write_conflict;
Loading

0 comments on commit 0a83d85

Please sign in to comment.