Type-graphql: Better checking and meaningfull errors

Created on 28 Jan 2018  路  18Comments  路  Source: MichalLytek/type-graphql

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)
  • [ ] ...others 馃槣
Enhancement

Most helpful comment

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

All 18 comments

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

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"

This issue is really important.

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,

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

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 馃槈

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!

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

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 Use graphql-type-json library. Where do your || syntax come from (Object || null)?

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

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.

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

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

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.

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tafelito picture tafelito  路  3Comments

winuxue picture winuxue  路  4Comments

memark picture memark  路  3Comments

MichalLytek picture MichalLytek  路  4Comments

oliversalzburg picture oliversalzburg  路  3Comments