I have a custom class named Foo
with a property called bar
that is of type string
.
class Foo {
bar: string
}
When I use an Arg
(from the library type-graphql
) without explicitly specifying the type and set the argument type to string
, everything works smoothly, for example:
doSomething(
@Arg('bar') bar: string,
){
// code goes here
}
However, if I specify the type of the bar
property of Foo
(which is a string), it doesn't work as expected, like so:
doSomething(
@Arg('bar') bar: Foo['bar'], // the property type is string
){
// code goes here
}
When I say "it doesn't work," I mean it gives me an error message saying unable to infer.
Unable to infer GraphQL type from TypeScript reflection system. You need to provide explicit type for argument named 'bar' of 'doSomething' in 'FooResolver' class
Why can't it infer the type? Shouldn't it be able to do so?