2

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

2
  • Maybe the output type is missing instead? The input type seems to be typed. Commented Nov 26, 2019 at 16:54
  • @Herku Added the output type. Don't think that was the issue. Commented Nov 26, 2019 at 18:25

3 Answers 3

8

@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[]
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

-2

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

1 Comment

It's a wrong syntax. This way you declare a TS tuple type - one-element only array of strings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.