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

feat(codegen): support sdl generation for model with compound id #8556

Merged
merged 5 commits into from
Aug 30, 2024

Conversation

russell-dot-js
Copy link
Contributor

@russell-dot-js russell-dot-js commented Jun 7, 2023

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.

@russell-dot-js
Copy link
Contributor Author

Hi all, just wanted to check in on the status of this PR. Let me know when / if I can prepare for release.

@russell-dot-js
Copy link
Contributor Author

pinging @jtoar & @dthyresson

@Tobbe
Copy link
Member

Tobbe commented Dec 18, 2023

@russell-dot-js Sorry this PR got stuck. I'll try to get you a decision on some next steps here.
I did find an old PR by @dthyresson that tries to solve the same problem: #6051

As noted in his PR we did decide to hold off on implementing this feature. But with community help (like yours!) maybe we can move forward. I'll discuss with the team.

I do think his implementation looks a bit cleaner. But yours is newer and therefore probably easier to keep working on. Could you please compare your two's PRs and combine the best of both into this one? Either get started right now, or wait until the team has decided if this is something we're ready for now or not.

@Tobbe
Copy link
Member

Tobbe commented Dec 19, 2023

Hey @russell-dot-js it would be awesome if you still wanted to work on this.

The team wants to see this feature, but we don't have time to implement it ourselves now or in the close future. But would be happy to review your code and generally help you along if you're up for it.

Some extra thought will probably have to be given to the Prisma part of the templates, and also the scaffold generator. Especially the forms the scaffolded stuff uses.

Totally understand if you lost the motivation for this. If I don't hear back from you I'll just close this PR for now.

For anyone else reading this, if we don't hear back from Russel you're more than welcome to pick up where this PR left off 🙂

@thedavidprice thedavidprice added the contributor-pr Use to automatically add PRs to the "Contributor PRs" Project Board label Mar 26, 2024
@thedavidprice
Copy link
Contributor

I'm marking this one for close — the work here by @russell-dot-js is great so want to discuss it internally to see if we can first see if others in the community want to pick it up.

@russell-dot-js
Copy link
Contributor Author

@thedavidprice just saw your comments... a bit demotivating when my 3 pr's were ignored for about 6 months :(

see also:
#8557
#8524

why can't this be merged as-is? there's already the option to use your own template for the generators based on how your app is structured, and it's non-breaking for apps that aren't already using compound id's (and it was previously unusable for compound id's, so in practice this PR, in its current state, has no downside)

@thedavidprice
Copy link
Contributor

@thedavidprice just saw your comments... a bit demotivating when my 3 pr's were ignored for about 6 months :(

Completely understood @russell-dot-js We haven't supported you well across these three PRs. Given that we'd dropped the ball and hadn't heard back from you, I assumed you'd given up on us.

Are you interested in picking this (and possibly the other two) up again? Let me know if so and I'll review with the team to see when we can offer you support. We are a small team and devoting 80% of our focus to Bighorn development right now. But we just talked today about resourcing some work on GQL and codegen, so the timing couldn't be better.

@russell-dot-js
Copy link
Contributor Author

@thedavidprice just saw your comments... a bit demotivating when my 3 pr's were ignored for about 6 months :(

Completely understood @russell-dot-js We haven't supported you well across these three PRs. Given that we'd dropped the ball and hadn't heard back from you, I assumed you'd given up on us.

Are you interested in picking this (and possibly the other two) up again? Let me know if so and I'll review with the team to see when we can offer you support. We are a small team and devoting 80% of our focus to Bighorn development right now. But we just talked today about resourcing some work on GQL and codegen, so the timing couldn't be better.

I'm happy to get the three PR's across the finish line. It wasn't clear to me what's lacking in any of them from our convos thus far. If you can provide feedback I can find some time to make the changes

@thedavidprice
Copy link
Contributor

I'm happy to get the three PR's across the finish line. It wasn't clear to me what's lacking in any of them from our convos thus far. If you can provide feedback I can find some time to make the changes

Sounds good @russell-dot-js I'll follow up with the team so we can prioritize and get back to you about next steps. Regardless, we'll get you feedback + clarity.

Appreciate your time and involvement. Truly!

@orta
Copy link
Contributor

orta commented May 2, 2024

This hits me roughly once a month, including today - so I'd like to see this get in.

I don't know if you've used this in a real project, but IMO, you'll probably also need to drop the check which throws in the CLI for the scaffolds ( look for missingIdConsoleMessage) otherwise it won't get here (maybe it was added since you started this PR)

@thedavidprice
Copy link
Contributor

@russell-dot-js handing this off to @orta (see his reply). You're in good hands!

@russell-dot-js
Copy link
Contributor Author

russell-dot-js commented May 2, 2024

This hits me roughly once a month, including today - so I'd like to see this get in.

I don't know if you've used this in a real project, but IMO, you'll probably also need to drop the check which throws in the CLI for the scaffolds ( look for missingIdConsoleMessage) otherwise it won't get here (maybe it was added since you started this PR)

To be honest, I stopped using redwood after my PR's went stale because I didn't feel confident the framework could keep up with our needs, so I haven't used it in a "real" project, but I POC'd a project I later moved to Nest with this feature, and it was working great at the time. My experience was that >50% of scaffolded code will get deleted or refactored anyway, so just having it work and create the files as an entrypoint was the time saver I was looking for.

Can you please elaborate the issue with missingIdConsoleMessage? This PR still requires you to have an id field, but extends @@id to allow an array or a string.

@Tobbe
Copy link
Member

Tobbe commented May 2, 2024

To be honest, I stopped using redwood after my PR's went stale because I didn't feel confident the framework could keep up with our needs, so I haven't used it in a "real" project, but I POC'd a project I later moved to Nest

Thank you so much for telling us this @russell-dot-js 🙏
I really wish more users would tell us both why they stopped using RW and what they went with instead.
This is super valuable to us! Thanks again.

@orta
Copy link
Contributor

orta commented May 3, 2024

Cool, yeah, this should have just gotten merged ages ago then - at some point I'll run the linter over this PR and fix the conflicts and we'll get it in

@orta
Copy link
Contributor

orta commented Aug 28, 2024

This is now rebased, and passes lints etc, I'm going to hand off to someone else to wrap up getting it merged

@orta orta removed their assignment Aug 28, 2024
@Josh-Walker-GM Josh-Walker-GM self-assigned this Aug 28, 2024
@Josh-Walker-GM Josh-Walker-GM added the release:fix This PR is a fix label Aug 30, 2024
@Josh-Walker-GM Josh-Walker-GM added this to the next-release milestone Aug 30, 2024
@Josh-Walker-GM Josh-Walker-GM modified the milestone: next-release Aug 30, 2024
@Josh-Walker-GM Josh-Walker-GM merged commit c9beece into redwoodjs:main Aug 30, 2024
52 of 54 checks passed
dac09 added a commit to dac09/redwood that referenced this pull request Aug 30, 2024
…edwood into feat/prisma-extension-crud-extra

* 'feat/prisma-extension-crud-extra' of github.com:dac09/redwood:
  feat(codegen): support sdl generation for model with compound id (redwoodjs#8556)
  chore(ci): Follow up to workflow permissions (redwoodjs#11397)
  chore(deps): Bump 'loader-utils' within docs (redwoodjs#11396)
  chore(ci): Pin action dependencies by digest (redwoodjs#11395)
  chore(ci): More workflow permission changes (redwoodjs#11394)
  chore(ci): Add permissions to some workflows/jobs (redwoodjs#11393)
  Add OSSF scorecard action to our CI (redwoodjs#11392)
  chore(rsc): Rename rsf -> rsa (redwoodjs#11391)
  few Flightcontrol template & doc updates (redwoodjs#11383)
  chore(jobs tests): Fix a couple of TS issues (redwoodjs#11389)
dac09 added a commit to dac09/redwood that referenced this pull request Sep 2, 2024
…ads-storage

* 'main' of github.com:redwoodjs/redwood: (32 commits)
  chore(uploads): Reorganise, change uploads package to storage (redwoodjs#11411)
  fix(cli-helpers): Don't add spaces around `=` for env vars (redwoodjs#11414)
  feat(uploads): Increase default fastify body limit to 100MB (redwoodjs#11412)
  chore: Rebuild fixture (redwoodjs#11413)
  chore(rsc): Refactor: Rename RscFetcher -> RscRoutes (redwoodjs#11409)
  chore(test-project): Update postcss to 8.4.42 (redwoodjs#11408)
  chore(rsc): Rename rscFetch to rscFetchRoutes and hardcode the rscId (redwoodjs#11407)
  feat(rsc): Initial support for RSA rerender (redwoodjs#11406)
  chore(router): Switch to experimental types (redwoodjs#11405)
  chore(router): Make React a normal dependency (redwoodjs#11404)
  feat(rsc): Return flight from RSAs (redwoodjs#11403)
  rscRequestHandler.ts: Make BASE_PATH naming match client.ts (redwoodjs#11401)
  fix(template): api type declaration merging for scripts (redwoodjs#11367)
  RSC: Disable client side flight caching for now (redwoodjs#11400)
  chore(fixtures): Use proper name for AuthLayout component (redwoodjs#11399)
  feat(storage): Add support for createMany, updateMany and upsert (redwoodjs#11390)
  feat(codegen): support sdl generation for model with compound id (redwoodjs#8556)
  chore(ci): Follow up to workflow permissions (redwoodjs#11397)
  chore(deps): Bump 'loader-utils' within docs (redwoodjs#11396)
  chore(ci): Pin action dependencies by digest (redwoodjs#11395)
  ...
@Josh-Walker-GM Josh-Walker-GM modified the milestones: next-release, v8.0.0 Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor-pr Use to automatically add PRs to the "Contributor PRs" Project Board release:fix This PR is a fix
Projects
Archived in project
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants