vjeko
vjeko

Reputation: 47

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

Upvotes: 2

Views: 4633

Answers (3)

eoan
eoan

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

Michał Lytek
Michał Lytek

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

vjeko
vjeko

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

Related Questions