1

I want to have a single query to take in a bool? Active parameter which could possibly be null.

Although, from experimenting I can either have a query which always excepts a value from Active OR just not use the filter at all.

Errors that I get from passing null:

The provided value for filter `eq` of type BooleanOperationFilterInput is invalid. Null values are not supported

Query that I am using to show active/inactive

query getOrgsByPartner($partnerId: UUID!, $active: Boolean, $take: Int, $after: String) {
  organisations(
    first: $take
    after: $after
    where: { 
      partner: { key: { eq: $partnerId } },
      isActive: { eq: $active }
    }
  ) {
    nodes {
      key
      displayName
      email
      isActive
    }
  }
}

For the meantime, I have just created 2 separate queries and just handle them on the client with a conditional operator.

1 Answer 1

1

GraphQL does not support conditionally changing a variable's type. In your situation, you can provide the entire where value as a variable, which you conditionally vary:

# Variables:
#
# {
#   "filter": {
#     "partner": { "key": { "eq": "<partner id>" } },
#     "isActive": { "eq": <active> }
#   }
# }
#
# or
#
# {
#   "filter": {
#     "partner": { "key": { "eq": "<partner id>" } }
#   }
# }
query getOrgsByPartner($filter: WhereType!, $take: Int, $after: String) {
  organisations(
    first: $take
    after: $after
    where: $filter
  ) {
    nodes {
      key
      displayName
      email
      isActive
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

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.