MichalLytek / type-graphql

Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
https://typegraphql.com
MIT License
8.03k stars 676 forks source link

Better checking and meaningfull errors #12

Open MichalLytek opened 6 years ago

MichalLytek commented 6 years ago

Please feel free to comment in this issue and tell what check is missing or what check throw not detailed errors!

esindger commented 6 years ago

more info about the need to provide explicit type

Type definition error text is unclear. For example, if I try to use output type in mutation, I got an error

(node:10303) UnhandledPromiseRejectionWarning: Error: Cannot determine GraphQL input type for filter

How to figure out what exactly type was missed?

It would be nice to provide some additional info:

gdanov commented 4 years ago

Describe the bug I have CRM.Client and ClientImpl with the second being annotated as

@tq.ObjectType({ implements: CRM.Client }) export abstract class ClientImpl extends CRM.Client {

when CRM.Client is not annotated with @InterfaceType the error message has no data to help fix the issue.

The code throwing the error is at : node_modules/type-graphql/dist/schema/schema-generator.js:157:59)

possible solution something along the lines of:

let interfaces = interfaceClasses.map(interfaceClass =>{
   let ifdef= this.interfaceTypesInfo.find(info => info.target === interfaceClass)
   if(ifdef) {return ifdef.type}
   else{ console.error("can't find interface definition for",interfaceClass," in ",objectType.target)  }

immediately gives away the culprit.

Enviorment (please complete the following information):

radarsu commented 4 years ago

This issue is really important.

sido420 commented 4 years ago

This is an extremely important issue.

I have a fairly complex Graphql schema using typegraphql and wasn't getting any typescript errors. However, when buildschema was executed after some time it started throwing "Cannot determine Graphql output type for items" errors. But, I have no clue where the issue exactly is.

I already have the following set:

        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
karladler commented 4 years ago

@Query decorator wont work on static functions

  @Query(() => User)
  static user(@Arg('username') username: string): User {
    return mockedUsers.find((user) => user.username === username);
  }

produces this while executing request to ... user(username:"test"){ ...

TypeError: Cannot read property 'apply' of undefined in .../type-graphql/dist/resolvers/create.js:19:64

Would be great to get a more semantic error here.

MichalLytek commented 4 years ago

I've added a bunch of changes to errors system in 0.18.0-beta.16 release:

Please let me know if the new error messages are informative enough or they have missing some valuable info 😉

krisquigley commented 4 years ago

Loving the new error messages! I can only guess how much time this error message has saved me Error: The value used as a type of '@Args' for 'addProduct' of 'ProductResolver' is not a class decorated with '@ArgsType' decorator!

madmaxlax commented 4 years ago

Error: Cannot set property prop of #<ObjectType> which has only a getter this error could be more specific, and point out that InputTypes (or ObjectTypes with an InputType alias) cannot have a get member, you have to split up the classes

himharsh1997 commented 4 years ago

I have a key in the collection which suppose to be an object but the schema is not fixed for it. What will be the type of that in Model for typeorm, @typegoose/typegoose?? Getting Error: Cannot determine GraphQL output type for 'attributes' of 'XModel' class. Does the value used as its TS type or explicit type is decorated with a proper decorator or is it a proper output value? the attribute is one of the key of collection XModel.

Sample Code:

    @Field(() => Object || null, { nullable: false })
    @prop({ unique: false, required: true })
    @Column()
    public attributes!: object | null;
MichalLytek commented 4 years ago

@himharsh1997 Use graphql-type-json library. Where do your || syntax come from (Object || null)?

himharsh1997 commented 4 years ago

My issue got resolved from one of your feedback of GitLab issues where you mention using graphql-type-json. But why it give the same error if I set type as any?

MichalLytek commented 4 years ago

@himharsh1997 Because what any means in GraphQL? String scalar? Boolean? It has to be the special JSON scalar for any data. And Typescript reflection system is limited, things like {} or any or Record<string, number> are reflected as Object in runtime, so TypeGraphQL throws an error.

yummyweb commented 3 years ago
Error: You need to provide explicit type for MessageResolver#subscription !

Much better description for this error is needed.

The subscription for which this error is being thrown:

@Subscription({
    topics: "NEW_MESSAGE"
  })
  subscription(
    @Root() messagePayload: Object
  ): any  {
    // const messages = await Message.query('SELECT * FROM MESSAGE')

    // const channel = Math.random().toString(36).slice(2, 15);
    // onMessagesUpdate(() => pubSub.publish(channel, { messages }));
    // setTimeout(() => pubSub.publish(channel, { messages }), 0);
    // return pubSub.asyncIterator(channel);

    return messagePayload
  }

As you can see I have provided an explicit type any. I also provided some more types like Object and MessagePayload (custom type). None of them worked. Would love some help.

MichalLytek commented 3 years ago

@antriksh123 Looks like you're not using v1.0+ which has different error messages

yummyweb commented 3 years ago

@antriksh123 Looks like you're not using v1.0+ which has different error messages

Oh yeah, I'm using 0.17.5. Okay, so will this error be resolved in v1?

MichalLytek commented 3 years ago

I've already posted solution to your issue in Gitter. It won't be automagically resolved, it's a user error.

Have you read the docs at all? It's all described there when and how to provide graphql types.

yummyweb commented 3 years ago

in the docs for subscription, there wan't any info on providing type in the @Subscription() decorator.

MichalLytek commented 3 years ago

Providing types is described in types and fields docs - please read the whole docs and use search instead of asking such questions: https://typegraphql.com/docs/types-and-fields.html

carlocorradini commented 1 year ago

Can we implement this in V2?

MichalLytek commented 1 year ago

@carlocorradini I think it's out of scope. V2 is a maintance release, we can't put there everything, we need to release it quickly. It will be implemented in V3 rewrite.