benawad / type-graphql-series

Typescript GraphQL Server built with TypeGraphQL
326 stars 129 forks source link

Schema must contain uniquely named types but contains multiple types named "PasswordInput". #14

Closed P4trik closed 5 years ago

P4trik commented 5 years ago

Hi Ben,

I get some error while transpiling with "npm start":

UnhandledPromiseRejectionWarning: Error: Schema must contain uniquely named types but contains multiple types named "PasswordInput". at invariant (/Users/user1/Documents/Development/Projects/Current/API/node_modules/graphql/jsutils/invariant.js:21:11) at typeMapReducer (/Users/user1/Documents/Development/Projects/Current/API/node_modules/graphql/type/schema.js:299:57) at Array.reduce (<anonymous>) at new GraphQLSchema (/Users/user1/Documents/Development/Projects/Current/API/node_modules/graphql/type/schema.js:145:28) at Function.generateFromMetadataSync (/Users/user1/Documents/Development/Projects/Current/API/node_modules/type-graphql/dist/schema/schema-generator.js:31:24) at Function.<anonymous> (/Users/user1/Documents/Development/Projects/Current/API/node_modules/type-graphql/dist/schema/schema-generator.js:16:33) at Generator.next (<anonymous>) at /Users/user1/Documents/Development/Projects/Current/API/node_modules/tslib/tslib.js:110:75 at new Promise (<anonymous>) at Object.__awaiter (/Users/user1/Documents/Development/Projects/Current/API/node_modules/tslib/tslib.js:106:16) (node:53364) 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(). (rejection id: 2) (node:53364) [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

Do you have any idea where it comes from? I'm quite new to TypeORM and graphQL and a bit overwhelmed ;-)

benawad commented 5 years ago

for PasswordInput try using @InputType({isAbstract: true})

P4trik commented 5 years ago

Same error :-(

export const PasswordMixin = <T extends ClassType>(BaseClass: T) => { @InputType({isAbstract: true}) class PasswordInput extends BaseClass { @Field() @MinLength(5) password: string; } return PasswordInput; };

P4trik commented 5 years ago

Ah k, after changing the RegisterInput too, it work's perfectly:

@InputType({isAbstract:true}) export class RegisterInput extends PasswordMixin(class {}) {

But to be honest, I don't understand why you haven't had the same problems?!

Thank you! 😊

igortas commented 4 years ago

I've like to ask question, but I will answer ahow I resolve this issue. Actually looks like there is issue when u left @ObjectType empty without name. I've need to provide explicitly the name of the table.

Just to mentioned that this error appears also when u have flat class, and not extends from some other class.

Example: @ObjectType('user')

jeff-ofobrukweta commented 4 years ago

Had same issue but after adding @InputType({isAbstract: true}) to PasswordInput class it worked .Please ill like to know what isAbstract: true means

jeff-ofobrukweta commented 4 years ago

you can also read how to solve the issue here thanks guys for the help https://typegraphql.com/docs/inheritance.html .Note make sure the graphql types are same ie @InputType + @ObjectType do not work together during inheritance it must be @InputType + @InputType || @ObjectType + @ObjectType during inheritance