Filtering with null / optional variable via apollo client

I cannot reproduce your error on Slash GraphQL (v20.07.1-rc1-29-g43c04cff). Your particular error may be specific to 20.11 which I don’t have up and running.

Does your setup differ from this?

Schema:

type Users {
    id: String! @id
    name: String
    posts: [Posts]
}

type Posts {
    id: String! @id
    message: String
}

Add data mutation:

mutation addData {
  addUsers(input: [{
    id: "1"
    name: "First"
    posts: [{
      id: "A"
      message: "Apple"
    }{
      id: "B"
      message: "Ball"
    }]
  }{
    id: "2"
    name: "Second"
    posts: [{
      id: "C"
      message: "Cat"
    }]
  }]) {
    numUids
  }
}

Try to duplicate your error message:

query testError($postId: String) {
  queryUsers {
    id
    name
    posts(filter: { id: { eq: $postId } }) {
      id
      message
    }
  }
}

Which gives me:

{
  "data": {
    "queryUsers": [
      {
        "id": "1",
        "name": "First",
        "posts": []
      },
      {
        "id": "2",
        "name": "Second",
        "posts": []
      }
    ]
  },
  "extensions": { ... }
}

When $postId is null the posts edge will return an empty array. If you want

then that is different. The filter Posts.id === null is not the same as “no filter”.

To get a “no filter is applied”, you need to extrapolate the $postId into the parent type of { eq: String } which in my particular case with my schema directives is StringHashFilter Then when providing a null variable it will return all.

query UsersWithPostFilterVariable ($postIdFilter: StringHashFilter) {
  queryUsers {
    id
    name
    posts(filter: { id: $postIdFilter })
  }
}

I wouldn’t suspect any of this to be any different for version 20.11 but there could very well be a bug in there.