=str #16221 fix graph precondition checks when attaching Source/Sink

Cherry-copy-pasted from #16182.

Fixes #16221.