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

[BUG] Input Object type UserOKRsUpdateManyMutationInput must define one or more fields #198

Closed
oceanlvr opened this issue Oct 16, 2021 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@oceanlvr
Copy link

Describe the Bug

When I create a new model name UserOKRs, it's relation include one-to-many and many-to-one relation to another model.

Then run apollo server, error occurred while generating GraphQL schema.

It seems that schema builder not work as we expect:

// ERROR
  const schema = await tq.buildSchema({ resolvers: resolvers });

And the error is :

  Input Object type UserOKRsUpdateManyMutationInput must define one or more fields.
Please check the `details` property of the error to get more detailed info.
    at Function.generateFromMetadata (/Users/oceanlvr/oyx/github/jff-OKR/backend/node_modules/type-graphql/dist/schema/schema-generator.js:20:23)

I check the file in UserUpdateManyMutationInput.ts file, and found it is empty export class

import * as TypeGraphQL from "type-graphql";
import * as GraphQLScalars from "graphql-scalars";
import { Prisma } from "@prisma/client";
import { DecimalJSScalar } from "../../scalars";
import { NullableStringFieldUpdateOperationsInput } from "../inputs/NullableStringFieldUpdateOperationsInput";
import { StringFieldUpdateOperationsInput } from "../inputs/StringFieldUpdateOperationsInput";

@TypeGraphQL.InputType({
  isAbstract: true
})
export class UserUpdateManyMutationInput {
}

To Reproduce

here is my schema, when I add the new model UserOKRs, then run yarn run dev start a apollo server.

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

generator typegraphql {
  provider = "typegraphql-prisma"
  output   = "./generated/type-graphql"
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  title     String
  content   String?
  published Boolean  @default(false)
  viewCount Int      @default(0)
  author    User?    @relation(fields: [authorId], references: [id])
  authorId  Int?
}

model OKR {
  id         Int        @id @default(autoincrement())
  squence    Int?       @default(autoincrement())
  obj        Obj        @relation(fields: [objId], references: [id])
  kvs        KeyValue[]
  objId      Int        @unique
  keyValueId Int
+  UserOKRs   UserOKRs?  @relation(fields: [userOKRsId], references: [id])
+  userOKRsId Int?
}

model Obj {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  okr       OKR?
}

model KeyValue {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  okr       OKR      @relation(fields: [okrId], references: [id])
  okrId     Int
}

model TimeStap {
  id        Int        @id @default(autoincrement())
  startTime DateTime
  endTime   DateTime
  createdAt DateTime   @default(now())
  updatedAt DateTime   @updatedAt
+   userOkrs  UserOKRs[]
}

+ model UserOKRs {
+   id         Int       @id @default(autoincrement())
+   okrs       OKR[]
+   timeStapId Int?
+   TimeStap   TimeStap? @relation(fields: [timeStapId], references: [id])
+ }

image

the error comes out:

[INFO] 00:20:33 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 4.4.3)
(node:68706) UnhandledPromiseRejectionWarning: Error: Some errors occurred while generating GraphQL schema:
  Input Object type UserOKRsUpdateManyMutationInput must define one or more fields.
Please check the `details` property of the error to get more detailed info.
    at Function.generateFromMetadata (/Users/oceanlvr/oyx/github/jff-OKR/backend/node_modules/type-graphql/dist/schema/schema-generator.js:20:23)
    at Object.buildSchema (/Users/oceanlvr/oyx/github/jff-OKR/backend/node_modules/type-graphql/dist/utils/buildSchema.js:10:20)
    at app (/Users/oceanlvr/oyx/github/jff-OKR/backend/src/server/src/index.ts:16:18)
(node:68706) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:68706) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

A quick guide how to reproduce the bug.
You can paste here code snippets or even better, provide a link to the repository with minimal reproducible code example.

Expected Behavior
A clear and concise description of what you expected to happen.

Logs
If applicable, add some console logs to help explain your problem.
You can paste the errors with stack trace that were printed when the error occurred.

Environment (please complete the following information):

  • OS: MacOs
  • Node v12.22.6
  • typegraphql-prisma version 0.14.5
  • Prisma version 2.26.0
  • TypeScript version ^4.3.5

Additional Context

Here is my repo link: https://github.com/jff-studio/jff-okr-backend

yarn install
yarn init-repo
yarn run db:generate
yarn run db:migrate
@oceanlvr
Copy link
Author

@MichalLytek typegraphql-prisma is an amazing code generation tool :)

@MichalLytek
Copy link
Owner

Duplicate of #19 🔒

@MichalLytek MichalLytek added the duplicate This issue or pull request already exists label Oct 16, 2021
@oceanlvr
Copy link
Author

The problem is solved. Thanks.

Realize that the empty type is entered because there are no fields other than the relationship

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants