import { withFilter } from "graphql-subscriptions" ; import { IApolloContext } from "../../graphql_server" ; import { Balance , BalanceSubscriptionPayload } from "../../model" ; import { BALANCE , pubsub } from "../../pubsub" ; import { toFloatAmountString } from "../../util/stellar" ; import * as resolvers from "./shared" ; import { eventMatches } from "./util" ; const balanceSubscription = ( event ) => { return { subscribe : withFilter ( ( ) => pubsub . asyncIterator ( event ) , ( payload , variables ) => { return eventMatches ( variables . args , payload . account , payload . mutationType ) ; } ) , resolve ( payload , args , ctx , info ) { return payload ; } } ; } ; const floatAmountFormatResolver = ( field ) => { return ( root ) => toFloatAmountString ( root [ field ] ) ; } ; export default { Balance : { account : resolvers . account , ledger : resolvers . ledger , asset : resolvers . asset , limit : floatAmountFormatResolver ( "limit" ) , balance : floatAmountFormatResolver ( "balance" ) , spendableBalance : floatAmountFormatResolver ( "spendableBalance" ) , receivableBalance : floatAmountFormatResolver ( "receivableBalance" ) } , BalanceSubscriptionPayload : { account : resolvers . account , asset : resolvers . asset } , BalanceValues : { account : resolvers . account , asset : resolvers . asset , limit : ( root ) => toFloatAmountString ( root . limit ) , balance : ( root ) => toFloatAmountString ( root . balance ) } , Subscription : { balance : balanceSubscription ( BALANCE ) } } ;