FinnWithIt
FinnWithIt

Reputation: 65

Is this valid in GraphQL

This doesn't bring up any errors but I wanted to know if this is valid in GraphQL. I'm using useQuery and I pass in a list of strings. Origionally I wanted to use useState and pass in a variable with a true/false value of weather it was in the list or not but due to the rules of hooks I can't do that I guess. SO what I did was use the include directive to see if a string is in the list passed in as a variable. Does this work?

query ContentQuery(
    $stringList: [String!]!
  ) {
        ...welcomeImageFragment
          @include(if: "STRING", in: $stringList)
  }

Upvotes: 0

Views: 133

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84687

The @skip and @include directives only take a single argument (if) whose type is Boolean!. The argument only accepts true, false or a variable whose type is also Boolean!.

If you want to conditionally include some field or fragment based on some arbitrary condition, you should declare a variable of the type Boolean! and then set the value of the variable to the condition.

If you want to not execute the query at all, you should use the skip option of the hook instead.

Upvotes: 1

Related Questions