-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(codegen): support sdl generation for model with compound id (#8556)
partial resolution of #8552 with this prisma schema: ``` model Temp { tenantId String id String @default(uuid()) name String @@id([tenantId, id]) } ``` running `yarn rw g sdl temp` now generates: ``` export const schema = gql` type Temp { tenantId: String! id: String! name: String! } type Query { temps: [Temp!]! @requireAuth temp(id: TempIdInput!): Temp @requireAuth } input CreateTempInput { tenantId: String! name: String! } input TempIdInput { tenantId: String! id: String! } input UpdateTempInput { tenantId: String name: String } type Mutation { createTemp(input: CreateTempInput!): Temp! @requireAuth updateTemp(id: TempIdInput!, input: UpdateTempInput!): Temp! @requireAuth deleteTemp(id: TempIdInput!): Temp! @requireAuth } ` ``` It's not perfect for the following reasons: 1. Generated service still expects a single { id } argument (but this may or may not be correct depending on where you get your tenantId from) 2. CreateTempInput is expecting part of the primary key in the request 3. UpdateTempInput duplicates the tenantId property from the TempIdInput #2 and #3 above are easily fixable. In my opinion #3 above makes sense to fix, but for both #1 and #2, we cannot draw assumptions about what the developer intends to take as an input when using a compound primary key. Sometimes it might be part of the input, sometimes (in the case of tenantId) it might come from the authorized user and be invisible to the API consumers. The important thing is, now you can generate your SDL's and modify from there. Previously, redwood threw an error and you couldn't use codegen. This may be considered a breaking change because users who supply their own `sdl.{j,t}s.template` should now update to support `idInput`. However, since the feature didn't exist before, I personally don't consider this breaking. --------- Co-authored-by: Orta Therox <[email protected]>
- Loading branch information
1 parent
5e6c258
commit c9beece
Showing
5 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
- feat(codegen): support sdl generation for model with compound id (#8556) by @russell-dot-js | ||
|
||
The SDL generator will no longer error when handling a table with a composite id, like so: | ||
|
||
```prisma | ||
model Order { | ||
tenantId String | ||
id String @unique @default(uuid()) | ||
@@id([tenantId, id]) | ||
} | ||
``` | ||
|
||
It will now generate code in the SDL that handles input of both these variables: | ||
|
||
```gql | ||
input TempIdInput { | ||
tenantId: String! | ||
id: String! | ||
} | ||
``` | ||
|
||
If you are using a custom `sdl.{j,t}s.template` then you may have to update it to support the new `idInput`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters