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

Prisma one-to-many relation: Error: Unknown type #10

Open
stepanic opened this issue Jan 26, 2022 · 2 comments
Open

Prisma one-to-many relation: Error: Unknown type #10

stepanic opened this issue Jan 26, 2022 · 2 comments
Assignees

Comments

@stepanic
Copy link

I've tried a lot of combinations for Angular with Node but this is the most awesome starter :)), nice job.

ISSUE

When I update schema.prisma by adding simple one-to-many relation

model User {
  id        Int       @id @default(autoincrement())
  createdAt DateTime  @default(now())
  username  String    @unique
  password  String
  email     String    @unique
  roles     Role[]
  
  products  Product[]
}

model Product {
  id      Int  @id @default(autoincrement())
  owner   User @relation(fields: [ownerId], references: [id])
  ownerId Int
}

And after npm run prisma:migrate it is possible to insert data with Prisma Studio but it is not possible to start Node.js backend with npm run start:api.

Interface ProductUpdateManyMutationInput is not generated (file: resolversTypes.ts).
Screenshot 2022-01-26 at 13 08 29

$ npm run start:api

> zen@2.0.2 start:api
> concurrently "ng serve api" "gulp handlebars:copy" "gulp handlebars:watch"

[0]
[0] > nx run api:serve
[0]
[2] [13:00:01] Using gulpfile ~/git/stepanic/angular-nest-prisma-graphql-demo/gulpfile.js
[1] [13:00:01] Using gulpfile ~/git/stepanic/angular-nest-prisma-graphql-demo/gulpfile.js
[2] [13:00:01] Starting 'handlebars:watch'...
[1] [13:00:01] Starting 'handlebars:copy'...
[1] [13:00:01] Finished 'handlebars:copy' after 36 ms
[1] gulp handlebars:copy exited with code 0
[0] chunk (runtime: main) main.js (main) 59.6 KiB (javascript) 937 bytes (runtime) [entry] [rendered]
[0]
[0] WARNING in ./apps/api/src/app/auth/index.ts 2:0-45
[0] export 'RequestUser' (reexported as 'RequestUser') was not found in './request-user' (module has no exports)
[0]
[0] WARNING in ./apps/api/src/app/graphql/models/index.ts 1:0-37
[0] export 'IContext' (reexported as 'IContext') was not found in './context' (module has no exports)
[0]
[0] webpack compiled with 2 warnings (c1b573c333bb0c74)
[0] Debugger listening on ws://localhost:9229/8cfbe261-8f68-4f5d-b827-f2de74de6fd5
[0] Debugger listening on ws://localhost:9229/8cfbe261-8f68-4f5d-b827-f2de74de6fd5
[0] For help, see: https://nodejs.org/en/docs/inspector
[0] Issues checking in progress...
[0]
[0] /Users/stepanic/git/stepanic/angular-nest-prisma-graphql-demo/node_modules/graphql/validation/validate.js:107
[0]     throw new Error(errors.map(function (error) {
[0]           ^
[0] Error: Unknown type "ProductUpdateManyMutationInput". Did you mean "UserUpdateManyMutationInput", "ProductUpdateManyWithoutOwnerInput", "ProductCreateManyInput", "ProductCreateManyOwnerInput", or "ProductUpdateInput"?
[0]     at assertValidSDL (/Users/stepanic/git/stepanic/angular-nest-prisma-graphql-demo/node_modules/graphql/validation/validate.js:107:11)
[0]     at Object.buildASTSchema (/Users/stepanic/git/stepanic/angular-nest-prisma-graphql-demo/node_modules/graphql/utilities/buildASTSchema.js:45:34)
[0]     at makeExecutableSchema (/Users/stepanic/git/stepanic/angular-nest-prisma-graphql-demo/node_modules/@graphql-tools/schema/index.js:497:26)
[0]     at Object../apps/api/src/app/graphql/resolvers/index.ts (/Users/stepanic/git/stepanic/angular-nest-prisma-graphql-demo/dist/apps/api/webpack:/zen/apps/api/src/app/graphql/resolvers/index.ts:17:51)
[0]     at __webpack_require__ (/Users/stepanic/git/stepanic/angular-nest-prisma-graphql-demo/dist/apps/api/webpack:/zen/webpack/bootstrap:19:1)
[0]     at Object../apps/api/src/app/graphql/gql-config.service.ts (/Users/stepanic/git/stepanic/angular-nest-prisma-graphql-demo/dist/apps/api/main.js:934:68)
[0]     at __webpack_require__ (/Users/stepanic/git/stepanic/angular-nest-prisma-graphql-demo/dist/apps/api/webpack:/zen/webpack/bootstrap:19:1)
[0]     at Object../apps/api/src/app/graphql/zen-graphql.module.ts (/Users/stepanic/git/stepanic/angular-nest-prisma-graphql-demo/dist/apps/api/main.js:2050:77)
[0]     at __webpack_require__ (/Users/stepanic/git/stepanic/angular-nest-prisma-graphql-demo/dist/apps/api/webpack:/zen/webpack/bootstrap:19:1)
[0]     at Object../apps/api/src/app/graphql/index.ts (/Users/stepanic/git/stepanic/angular-nest-prisma-graphql-demo/dist/apps/api/main.js:999:77)
[0] ERROR in apps/api/src/app/graphql/resolversTypes.ts:443:9
[0] TS2304: Cannot find name 'ProductUpdateManyMutationInput'.
[0]     441 |
[0]     442 | export interface UpdateManyProductArgs {
[0]   > 443 |   data: ProductUpdateManyMutationInput;
[0]         |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[0]     444 |   where?: ProductWhereInput;
[0]     445 | }
[0]     446 |
[0]
^C[2] gulp handlebars:watch exited with code SIGINT
[0] ng serve api exited with code 0
@ZenSoftware
Copy link
Owner

ZenSoftware commented Jan 28, 2022

Hello @stepanic. ✨ Thank you for the complements. The project has come a long way. Also, yes you are right. Something seems to be broken right now with the Pal.js code generation. I have been upgrading the dependencies for this repo at a fairly rapid pace as of late. I was trying to get the repo working with the latest versions for this particular technology stack. Pal.js and Prisma versions can sometimes have discrepancies and have been notoriously finicky about breaking changes to the Prisma DMMF as new features within Prisma have been integrated in newer versions. Sometimes it takes some effort to get Pal.js and Prisma to gel well again. I have had hiccups before where some things would break due to advancing Prisma to a newer version. It seems to have happened again. It happens! ⛩

🎐 Thanks for the heads up! Let me regress the semantic version numbers until things are at least in working order again. I'll freeze the version numbers within the package.json and block there until more compatible future updates come out. I'll be working on the issue now and inform you when things are back in working order. Cheers! 🥂

@ZenSoftware ZenSoftware self-assigned this Jan 29, 2022
@ZenSoftware
Copy link
Owner

ZenSoftware commented Jan 29, 2022

Related: paljs/prisma-tools#252

Hello @AhmedElywa! 🎎

Pal.js apollo SDL first code generation does not seem to be working with a very simple one-to-many schema. I have created a bare minimum reproduction of this Pal.js bug for you by cloning your prisma-tools/packages/create/examples/apollo-sdl-first example and modifying the schema.prisma file.

My system:

  • Windows 10
  • Node v16.13.2
  • prisma@3.8.1
  • @paljs/plugins@4.0.13
  • @paljs/cli@4.0.13

schema.prisma

 model User { 
   id        Int      @id @default(autoincrement()) 
   username  String   @unique 
   password  String 
  
   products Product[] 
 } 
  
 model Product { 
   id      Int  @id @default(autoincrement()) 
   owner   User @relation(fields: [ownerId], references: [id]) 
   ownerId Int 
 } 

Notice how the definition for ProductUpdateManyMutationInput is not being generated. src/resolversTypes.ts#L482-L485

/*
export interface ProductUpdateManyMutationInput {
   ... missing ...
}
*/

export interface UpdateManyProductArgs { 
   data: ProductUpdateManyMutationInput 
   where?: ProductWhereInput 
 }

Though UserUpdateManyMutationInput is being properly generated.

resolversTypes.ts#L454-L457

export interface UpdateManyUserArgs {
  data: UserUpdateManyMutationInput
  where?: UserWhereInput
}

src/resolversTypes.ts#L605-L608

 export interface UserUpdateManyMutationInput { 
   username?: StringFieldUpdateOperationsInput 
   password?: StringFieldUpdateOperationsInput 
 } 

Would you happen to know what is happening? Thanks 🎐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants