type-graphql
type-graphql copied to clipboard
Better checking and meaningfull errors
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
@Argswith@InputTypeor without@ArgsType - [x] inform about missing
reflect-metadatapolyfill - [x] missing
@InterfaceTypeon class provided to{ implements: SomeClass }(@gdanov) - [x] more details in message when
GeneratingSchemaErroroccured - [ ] duplicated arg name
- [ ] description/depreciation on not supported field
- [ ] multiple usage of
@Args() - [ ] field resolver not matching resolver object type
- [ ] using
@Argwith@ArgsTypeclass - [ ] 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
undefinedor other invalid values provided by mistake intype => X - [ ] detect wrong
targetsetting and arrow function detection issue (#206, #219) - [ ] more specific error message when root Query is missing (#218)
- [ ] using
defaultValueoption in@Fieldplaced 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
@FieldResolverthan in@Field() - [ ] ...others 😜
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
@Argswith@InputTypeor without@ArgsType - missing
@InterfaceTypeon class provided to{ implements: SomeClass }(@gdanov) - more details in message when
GeneratingSchemaErroroccured
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
propof #<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 agetmember, 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
Can we implement this in V2?
@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.