Search code examples
graphqltypegraphql

Graphql query argument array of string


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


Solution

  • @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[]