type-graphql icon indicating copy to clipboard operation
type-graphql copied to clipboard

Better checking and meaningfull errors

Open MichalLytek opened this issue 6 years ago • 20 comments

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

  • [x] more info about the need to provide explicit type
  • [x] more info about problems with determining GraphQL type for property/argument (@esindger)
  • [x] using @Args with @InputType or without @ArgsType
  • [x] inform about missing reflect-metadata polyfill
  • [x] missing @InterfaceType on class provided to { implements: SomeClass } (@gdanov)
  • [x] more details in message when GeneratingSchemaError occured
  • [ ] duplicated arg name
  • [ ] description/depreciation on not supported field
  • [ ] multiple usage of @Args()
  • [ ] field resolver not matching resolver object type
  • [ ] using @Arg with @ArgsType class
  • [ ] duplicated query/mutation name (now it overwrites)
  • [ ] overwriting interface/base class field types
  • [ ] creating field resolver for method resolver
  • [ ] no resolver files match glob pattern
  • [ ] detect ES5 compilation (no Function.name)
  • [ ] detect undefined or other invalid values provided by mistake in type => X
  • [ ] detect wrong target setting and arrow function detection issue (#206, #219)
  • [ ] more specific error message when root Query is missing (#218)
  • [ ] using defaultValue option in @Field placed in @ObjectType
  • [ ] abstract type is used directly in GraphQL schema
  • [ ] checking implementation of all abstract interface field resolvers
  • [ ] inform that decorators don't work on static methods (@karladler)
  • [ ] duplicated types/enums before schema auto-check (with stacktrace to point source files)
  • [ ] warn about declaring different type (or type options) in @FieldResolver than in @Field()
  • [ ] ...others 😜

MichalLytek avatar Jan 28 '18 21:01 MichalLytek

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:

  • resolver name
  • query/mutation name
  • argument name

esindger avatar Sep 01 '18 23:09 esindger

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):

  • type-graphql@ "version": "0.17.5"

gdanov avatar Nov 25 '19 17:11 gdanov

This issue is really important.

radarsu avatar Dec 15 '19 00:12 radarsu

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,

sido420 avatar Feb 14 '20 02:02 sido420

@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.

karladler avatar Apr 01 '20 08:04 karladler

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

  • more info about the need to provide explicit type
  • more info about problems with determining GraphQL type for property/argument (@esindger)
  • using @Args with @InputType or without @ArgsType
  • missing @InterfaceType on class provided to { implements: SomeClass } (@gdanov)
  • more details in message when GeneratingSchemaError occured

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

MichalLytek avatar Apr 07 '20 19:04 MichalLytek

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!

krisquigley avatar Apr 25 '20 14:04 krisquigley

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

madmaxlax avatar Jun 09 '20 15:06 madmaxlax

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;

himharsh1997 avatar Sep 16 '20 17:09 himharsh1997

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

MichalLytek avatar Sep 16 '20 17:09 MichalLytek

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?

himharsh1997 avatar Sep 16 '20 17:09 himharsh1997

@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.

MichalLytek avatar Sep 16 '20 17:09 MichalLytek

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.

yummyweb avatar Jan 14 '21 06:01 yummyweb

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

MichalLytek avatar Jan 14 '21 07:01 MichalLytek

@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?

yummyweb avatar Jan 14 '21 07:01 yummyweb

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.

MichalLytek avatar Jan 14 '21 07:01 MichalLytek

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

yummyweb avatar Jan 14 '21 07:01 yummyweb

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

MichalLytek avatar Jan 14 '21 08:01 MichalLytek

Can we implement this in V2?

carlocorradini avatar Mar 09 '23 14:03 carlocorradini

@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.

MichalLytek avatar Mar 09 '23 14:03 MichalLytek