neo4j-graphql-js icon indicating copy to clipboard operation
neo4j-graphql-js copied to clipboard

[Bug] Auto-generated mutations cause error when first field on type is not Scalar type

Open btroop opened this issue 6 years ago • 3 comments

I think I found a bug where, in the type definitions, if the first field on a type is not a scalar the auto generated mutations fail to pass validation, resulting in the following error:

The type of Mutation.Update<Type>(<field>:) must be Input Type but got: <Type>!

 throw new Error(errors.map(function (error) {
Error: The type of Mutation.UpdateRentalAgreement(renter:) must be Input Type but got: Renter!.
The type of Mutation.DeleteRentalAgreement(renter:) must be Input Type but got: Renter!.
The type of _RentalAgreementInput.renter must be Input Type but got: Renter!.

here's the type def I was playing around with that caused the issue.

works:

type RentalAgreement {
  uuid: ID
  renter: Renter @relation(name:"RENTER", direction:"OUT")
  vehicle: Vehicle @relation(name:"VEHICLE_RENTED", direction: "OUT")
  rentedFrom: RentalLocation @relation(name:"RENTED_FROM", direction:"OUT")
  returnedTo: RentalLocation @relation(name:"RETURNED_TO", direction:"OUT")
  beginningMileage: Int
  endingMileage: Int
  startDate: String
  endDate: String
  status: String
  createdBy: Employee @relation(name:"CREATED", direction:"IN")
}

throws error:

type RentalAgreement {
  renter: Renter @relation(name:"RENTER", direction:"OUT")
  vehicle: Vehicle @relation(name:"VEHICLE_RENTED", direction: "OUT")
  rentedFrom: RentalLocation @relation(name:"RENTED_FROM", direction:"OUT")
  returnedTo: RentalLocation @relation(name:"RETURNED_TO", direction:"OUT")
  beginningMileage: Int
  endingMileage: Int
  startDate: String
  endDate: String
  status: String
  createdBy: Employee @relation(name:"CREATED", direction:"IN")
}

I kept deleting fields referring to other types and restarting the server until I got down to the "beginningMileage" field; the error promptly went away once the first field was the scalar type.

Neo4j 3.5, neo4jgraphql-js @ 2.3.1, makeAugmentedSchema({typeDefs})

btroop avatar Feb 09 '19 00:02 btroop

I've run into the same problem. It works fine if the first field is scalar, and breaks with the same type of error if the first field is a relation. There's no difference in the actual fields, just their order in the type definition.

chadnorvell avatar Apr 03 '19 05:04 chadnorvell

From very cursory testing, it looks like the first field defined on a type is used to define the auto-generated _*Input types. GraphQL input types can only have scalar fields, so it makes sense that the resulting schema would not validate.

chadnorvell avatar Apr 04 '19 01:04 chadnorvell

https://github.com/neo4j-graphql/neo4j-graphql-js/issues/608

michaeldgraham avatar May 02 '21 04:05 michaeldgraham