Reputation: 47
I need to pass an array of strings to my query so I can iterate over it but I cant figure out how to do it.
Something like this:
@Query(() => Boolean)
async fetchUrl(
@Arg('urls') urls: string[]
): Promise<Boolean> {
// do something
return true
}
Error: You need to provide explicit type for FetchResolver#fetchUrl parameter #0 !
I don't really know how to provide a proper type for an array of strings
Upvotes: 2
Views: 4633
Reputation: 111
@Michał Lytek's answer was almost working for me, but for anyone else struggling with it, I had to change it to this to get it working:
@Arg('urls', type => [String]) urls: [String]
Upvotes: -2
Reputation: 12077
@vjeko
To provide a proper type for an array of strings, you should use the second param of @Arg
decorator and use the bracket []
notation:
@Arg('urls', type => [String]) urls: string[]
Upvotes: 8
Reputation: 47
Solved this by passing a stringified object instead of an array of strings, but would still be good to know how to type an array of strings in type graphql.
Upvotes: 0