The ReturnTypeFunc
type is utilized within the Query
decorator:
export declare function Query(returnTypeFunc: ReturnTypeFunc, options?: AdvancedOptions): MethodDecorator;
This is a common usage of the Query
decorator:
@Query(returns => [SampleObject])
To enhance readability, the returns
parameter was added: This query returns an array of SampleObject
. Without the returns
argument in the ReturnTypeFunc
type, you would need to write @Query(() => [SampleObject])
instead.
Other decorators that feature an optional void argument include:
@Resolver(of => Recipe) // This resolver is for Recipe. Refer to the ClassTypeResolver.
@Field(type => [Rate]) // This field is of type Rate. Refer to the ClassTypeResolver.
Note:
- It should be noted that only
null
(if strictNullChecks
is not specified) or undefined
can be assigned to a variable of type void
.
- The decorators mentioned are used to annotate classes and generate the GraphQL schema by utilizing the provided metadata. It is important to understand that defining a function with a type of
ReturnTypeFunc
is not recommended. The purpose of using parameters of type void
is primarily for code readability.