client.setUserContext is no longer supported by HLF 2.2
you can make use of below snippet if you are working with HLF 2.2 and need to list down affiliations
const { Wallets } = require('fabric-network');
const FabricCAServices = require('fabric-ca-client');
let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/connection-org2.yaml', 'utf8'));
// Create a new CA client for interacting with the CA.
const caInfo = connectionProfile.certificateAuthorities['ca.org2.example.com'];
const caTLSCACerts = caInfo.tlsCACerts.pem;
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
const walletPath = path.join(process.cwd(), 'wallet');
const wallet = await Wallets.newFileSystemWallet(walletPath);
const provider = wallet.getProviderRegistry().getProvider(adminIdentity.type);
const adminUser = await provider.getUserContext(adminIdentity, 'admin');
let affiliationService = ca.newAffiliationService();
let registeredAffiliations = await affiliationService.getAll(adminUser);
console.dir(registeredAffiliations, { depth: null })
for documentation regarding other methods, visit AffiliationService Class documentation