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

fix(cli): Service generator supports relations #11250

Merged
merged 3 commits into from
Aug 15, 2024

Conversation

dthyresson
Copy link
Contributor

@dthyresson dthyresson commented Aug 14, 2024

This PR address an issue when using yarn rw g service independently vs having ti be called by yarn rw g sdl or yarn rw g scaffold.

When using yarn rw g service, the model's relations were not correctly determined. For the sdl generator, relations are determined and then passed as an argument to the service generator; however, if you run just the service generator, the relations were always [].

Thus, for the test fixture model schema:

model User {
  id       Int           @id @default(autoincrement())
  name     String?
  email    String        @unique
  isAdmin  Boolean       @default(false)
  profiles UserProfile[]
  transactions Transaction[]
}

A user has two relations: a UserProfile and transactions.

Without the fix, the following is missing from the user service:

export const User = {
  profiles: (_obj, { root }) => {
    return db.user.findUnique({ where: { id: root?.id } }).profiles()
  },
  transactions: (_obj, { root }) => {
    return db.user.findUnique({ where: { id: root?.id } }).transactions()
  },
}

Fixing because when using experimental sdlCodegen, I write the SDL manually and then generate the service. I also will have a custom template for the sdlCogen pattern, but my template failed because it didn't get the the relations to properly build out the service according to my template.

This is why this PR also bumps the sdl-codegen package.

@dthyresson dthyresson added topic/generators-&-scaffolds release:fix This PR is a fix changesets-ok Override the changesets check labels Aug 14, 2024
@dthyresson dthyresson added this to the next-release-patch milestone Aug 14, 2024
@dthyresson dthyresson self-assigned this Aug 14, 2024
@dthyresson dthyresson changed the title fix: Service generator supports relations fix(cli): Service generator supports relations Aug 14, 2024
@Josh-Walker-GM Josh-Walker-GM removed their request for review August 15, 2024 16:49
@dthyresson dthyresson merged commit c32bc62 into main Aug 15, 2024
46 checks passed
@dthyresson dthyresson deleted the dt-service-sdl-generator branch August 15, 2024 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changesets-ok Override the changesets check release:fix This PR is a fix topic/generators-&-scaffolds
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants