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

Input Object type ... must define one or more fields in a m-n Relation #1354

Open
Maetes opened this issue Aug 13, 2020 · 5 comments
Open

Input Object type ... must define one or more fields in a m-n Relation #1354

Maetes opened this issue Aug 13, 2020 · 5 comments
Labels
type/bug Something is not working the way it should

Comments

@Maetes
Copy link

Maetes commented Aug 13, 2020

Maybe this is a prisma bug rather than a nexus one.

Nexus Report

1749 ✕ fatal nexus:schema Input Object type dbs_category_has_postUpdateManyDataInput must define one or more fields.

Input Object type dbs_tag_has_postUpdateManyDataInput must define one or more fields. 

  Stack:
Input Object type dbs_tag_has_postUpdateManyDataInput must define one or more fields.
    at assertValidSchema (~/Desktop/Projekte/backend/node_modules/graphql/type/validate.js:71:11)
    at Object.validate (~/Desktop/Projekte/backend/node_modules/graphql/validation/validate.js:54:35)
    at Object.assemble (~/Desktop/Projekte/backend/node_modules/nexus/src/runtime/schema/schema.ts:149:21)
    at Object.assemble (~/Desktop/Projekte/oldunique/backend/node_modules/nexus/src/runtime/app.ts:193:64)
    at eval (eval at main (/Users/Desktop/Projekte/backend/node_modules/nexus/src/lib/watcher/runner.ts:83:3), <anonymous>:26:20)
    at main (~/Desktop/Projekte/backend/node_modules/nexus/src/lib/watcher/runner.ts:83:3)
    at Object.<anonymous> (~/Desktop/Projekte/backend/node_modules/nexus/src/lib/watcher/runner.ts:12:1)

Description

I have a m - n relation which does not have any additional meta field in the pivot table.
So when there are only the minimal needed columns defined for the relation the error pops up. When i add an additional field all is ok. Example follows:

when modelling the prisma schema like so the error is thrown:

model dbs_category_has_post {
  postId       Int
  categoryId   Int
  dbs_category dbs_category @relation(fields: [categoryId], references: [id])
  dbs_post     dbs_post     @relation(fields: [postId], references: [id])

  @@id([postId, categoryId])
}

This is okay:

model dbs_category_has_post {
  postId       Int
  categoryId   Int
  time         Int
  dbs_category dbs_category @relation(fields: [categoryId], references: [id])
  dbs_post     dbs_post     @relation(fields: [postId], references: [id])

  @@id([postId, categoryId])
}

I should be able to define an explicit model also without meta information.

@Maetes Maetes added the type/bug Something is not working the way it should label Aug 13, 2020
@sfratini
Copy link

Having the same issue. I realized that nexus 0.26.0 and up, will just not run nor generate the api.graphql file, and that also causes the model/crud objects to not be added into the nexus context. (VS Code does not recognizes the objects, even after restarting TS Server)

With version 0.25.0 the nexus server starts, generates the graphql file but as soon as you try to access it, I get the same issue:

4465 ✕ app unhandledRejection
       | error  Error: Input Object type PoiCategoryUpdateManyDataInput must define one or more fields.
       |        
       |        Input Object type CompanyUserUpdateManyDataInput must define one or more fields.

In my case even if I add all the fields I still can't get the error to go away, and I can see the object has no fields on the prisma generated client:

{\"name\":\"PoiCategoryUpdateManyDataInput\",\"isOneOf\":false,\"fields\":[]},{\"name\":\"PoiCategoryUpdateManyWithWhereNestedInput\",\"isOneOf\":false,\"fields\":[{\"name\":\"where\",\"inputType\":[{\"type\":\"PoiCategoryScalarWhereInput\",\"kind\":\"object\",\"isRequired\":true,\"isList\":false,\"isNullable\":false}]},{\"name\":\"data\",\"inputType\":[{\"type\":\"PoiCategoryUpdateManyDataInput\",\"kind\":\"object\",\"isRequired\":true,\"isList\":false,\"isNullable\":false}]}]},

@sfratini
Copy link

Well, not sure if it is the same case, but mine just fails when I add any t.crud.updateOneXXXX methods. It just goes right to complain about these missing fields. But it I just leave the queries, then it compiles correctly. Tested with nexus 0.26.1.

import {schema} from 'nexus'

schema.mutationType({
    definition(t) {
      t.crud.createOneCategory()
     // t.crud.updateOneCategory() //This one will triger the issue
      
      t.crud.createOneCompany()
      //t.crud.updateOneCompany()  //This one will triger the issue
  
      t.crud.createOneCollection()
  
    }
  })

@yueyueniao90
Copy link

I think that upsertOnes will also triger the issue @sfratini
t.crud.upsertOnesCategory()

I am not using nexus. but i have the same issue with @nexus/schema 0.14.0 and nexus-prisma 0.13.0

@sfratini
Copy link

I think that upsertOnes will also triger the issue @sfratini
t.crud.upsertOnesCategory()

I am not using nexus. but i have the same issue with @nexus/schema 0.14.0 and nexus-prisma 0.13.0

I just created one specific bug for that and I can confirm the upsert triggers the same issue for me.

@ff-randy
Copy link

Any fix/update on this? I'm facing same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is not working the way it should
Projects
None yet
Development

No branches or pull requests

4 participants