profile
viewpoint

Ask questionsSchema Generation fails in 0.17.5

I recently upgraded to type-graphql 0.17.5 and while generating schema, I get this error.

node:81114) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'map' of undefined at types (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/@nestjs/graphql/node_modules/type-graphql/dist/schema/schema-generator.js:64:59) at resolveThunk (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/definition.js:383:40) at defineTypes (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/definition.js:765:15) at GraphQLUnionType.getTypes (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/definition.js:735:26) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:307:23) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:330:22) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:330:22) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:330:22) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:330:22) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:330:22) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) at typeMapReducer (/Users/kunalrelan/Documents/Dev/freelance/ekomi/collect-backend/database/node_modules/graphql/type/schema.js:295:12) (node:81114) 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:81114) [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.

MichalLytek/type-graphql

Answer questions MichalLytek

GraphQLError: Type Query must define one or more fields.

Still not runnable example. Do you just blindy paste some snippets from your project's code?

I've updated your code example:

@ObjectType()
export class Contact {
  @Field(type => ID)
  id: number;

  @Field(type => Event)
  event: any;
}

export const EventDataUnion = createUnionType({
  name: "EventData",
  types: () => [Contact], // any entities
});

@ObjectType()
export class Event {
  @Field(type => ID)
  id: number;

  @Field(type => EventDataUnion)
  data: typeof EventDataUnion;
}

@Resolver(of => Event)
export class EventsResolver {
  @Query()
  test(): string {
    return "test";
  }

  @FieldResolver(returns => EventDataUnion)
  async data(@Root() event: Event): Promise<any> {
    // some actions
  }
}

async function main() {
  const schema = await buildSchema({
    resolvers: [EventsResolver],
  });
  console.log(printSchema(schema));
}

main().catch(console.error);

Still cannot reproduce.

type Contact {
  id: ID!
  event: Event!
}

type Event {
  id: ID!
  data: EventData!
}

union EventData = Contact

type Query {
  test: String!
}

As you use Nest, you should ask for help in theirs repo, as I'm not responsible for theirs integration that is sometimes faulty: https://github.com/nestjs/graphql/issues/231

useful!
source:https://uonfu.com/
answerer
Michał Lytek MichalLytek @bluereceipt1 Poland https://typegraphql.com/ Full-stack developer with a tendency to perfectionism. GraphQL and TypeScript evangelist, Node.js and React enthusiast. Author of the TypeGraphQL framework.
Github User Rank List