import { ApolloLink , Observable } from "@apollo/client" ; export function asyncSplit ( test , left , right ) { let link ; return new ApolloLink ( ( operation , forward ) => { if ( link ) { return link . request ( operation , forward ) ; } else { return new Observable ( ( observer ) => { ( async ( ) => { if ( await test ( ) ) { link = await left ( ) ; } else { link = await right ( ) ; } link . request ( operation , forward ) ?. subscribe ( observer ) ; } ) ( ) ; } ) ; } } ) ; }