async function counterparty(user, { first = 100, after, id }, _, info) {
  const fields = graphqlFields(info)
  const u1 = user.id,
    u2 = id

  const u1Listings = await ec().allEvents('ListingCreated', u1)
  const u1ListingIds = u1Listings.map(e => Number(e.returnValues.listingID))
  const u2Listings = await ec().allEvents('ListingCreated', u2)
  const u2ListingIds = u2Listings.map(e => Number(e.returnValues.listingID))

  const u1BuyerEvents = await ec().offers(
    u2ListingIds,
    null,
    'OfferCreated',
    u2,
    u1
  )
  const u1OfferIds = u1BuyerEvents.map(
    e => `${e.returnValues.listingID}-${e.returnValues.offerID}`
  )
  const u2BuyerEvents = await ec().offers(
    u1ListingIds,
    null,
    'OfferCreated',
    u1,
    u2
  )
  const u2OfferIds = u2BuyerEvents.map(
    e => `${e.returnValues.listingID}-${e.returnValues.offerID}`
  )

  const unsortedEvents = await ec().allEvents(null, null, [
    ...u1OfferIds,
    ...u2OfferIds
  ])
  const allEvents = sortBy(unsortedEvents, e => -e.blockNumber)

  const totalCount = allEvents.length,
    allIds = allEvents.map(e => e.id)

  const { ids, start } = getIdsForPage({ after, ids: allIds, first })
  const filteredEvents = allEvents.filter(e => ids.indexOf(e.id) >= 0)

  let offers = [],
    nodes = []

  if (fields.nodes) {
    offers = await Promise.all(
      filteredEvents.map(event =>
        contracts.eventSource.getOffer(
          event.returnValues.listingID,
          event.returnValues.offerID,
          event.blockNumber
        )
      )
    )
    nodes = filteredEvents.map((event, idx) => {
      const party = event.returnValues.party
      return {
        id: event.id,
        offer: offers[idx],
        party: { id: party, account: { id: party } },
        event,
        read: false
      }
    })
  }

  return getConnection({ start, first, nodes, ids, totalCount })
}
// Sourced from offer events where user is alternate party
Sourced from offer events where user is alternate party
Sourced from offer events where user is alternate party
async function counterparty(user, { first = 100, after, id }, _, info) {
  const fields = graphqlFields(info)
  const u1 = user.id,
    u2 = id
  const u1Listings = await ec().allEvents('ListingCreated', u1)
  const u1ListingIds = u1Listings.map(e => Number(e.returnValues.listingID))
  const u2Listings = await ec().allEvents('ListingCreated', u2)
  const u2ListingIds = u2Listings.map(e => Number(e.returnValues.listingID))
  const u1BuyerEvents = await ec().offers(
    u2ListingIds,
    null,
    'OfferCreated',
    u2,
    u1
  )
  const u1OfferIds = u1BuyerEvents.map(
    e => `${e.returnValues.listingID}-${e.returnValues.offerID}`
  )
  const u2BuyerEvents = await ec().offers(
    u1ListingIds,
    null,
    'OfferCreated',
    u1,
    u2
  )
  const u2OfferIds = u2BuyerEvents.map(
    e => `${e.returnValues.listingID}-${e.returnValues.offerID}`
  )
  const unsortedEvents = await ec().allEvents(null, null, [
    ...u1OfferIds,
    ...u2OfferIds
  ])
  const allEvents = sortBy(unsortedEvents, e => -e.blockNumber)
  const totalCount = allEvents.length,
    allIds = allEvents.map(e => e.id)
  const { ids, start } = getIdsForPage({ after, ids: allIds, first })
  const filteredEvents = allEvents.filter(e => ids.indexOf(e.id) >= 0)
  let offers = [],
    nodes = []
  if (fields.nodes) {
    offers = await Promise.all(
      filteredEvents.map(event =>
        contracts.eventSource.getOffer(
          event.returnValues.listingID,
          event.returnValues.offerID,
          event.blockNumber
        )
      )
    )
    nodes = filteredEvents.map((event, idx) => {
      const party = event.returnValues.party
      return {
        id: event.id,
        offer: offers[idx],
        party: { id: party, account: { id: party } },
        event,
        read: false
      }
    })
  }
  return getConnection({ start, first, nodes, ids, totalCount })
}
async function counterparty ( user , { first = 100 , after , id } , _ , info ) { const fields = graphqlFields ( info ) const u1 = user . id , u2 = id const u1Listings = await ec ( ) . allEvents ( 'ListingCreated' , u1 ) const u1ListingIds = u1Listings . map ( e => Number ( e . returnValues . listingID ) ) const u2Listings = await ec ( ) . allEvents ( 'ListingCreated' , u2 ) const u2ListingIds = u2Listings . map ( e => Number ( e . returnValues . listingID ) ) const u1BuyerEvents = await ec ( ) . offers ( u2ListingIds , null , 'OfferCreated' , u2 , u1 ) const u1OfferIds = u1BuyerEvents . map ( e => ` ${ e . returnValues . listingID } ${ e . returnValues . offerID } ` ) const u2BuyerEvents = await ec ( ) . offers ( u1ListingIds , null , 'OfferCreated' , u1 , u2 ) const u2OfferIds = u2BuyerEvents . map ( e => ` ${ e . returnValues . listingID } ${ e . returnValues . offerID } ` ) const unsortedEvents = await ec ( ) . allEvents ( null , null , [ ... u1OfferIds , ... u2OfferIds ] ) const allEvents = sortBy ( unsortedEvents , e => - e . blockNumber ) const totalCount = allEvents . length , allIds = allEvents . map ( e => e . id ) const { ids , start } = getIdsForPage ( { after , ids : allIds , first } ) const filteredEvents = allEvents . filter ( e => ids . indexOf ( e . id ) >= 0 ) let offers = [ ] , nodes = [ ] if ( fields . nodes ) { offers = await Promise . all ( filteredEvents . map ( event => contracts . eventSource . getOffer ( event . returnValues . listingID , event . returnValues . offerID , event . blockNumber ) ) ) nodes = filteredEvents . map ( ( event , idx ) => { const party = event . returnValues . party return { id : event . id , offer : offers [ idx ] , party : { id : party , account : { id : party } } , event , read : false } } ) } return getConnection ( { start , first , nodes , ids , totalCount } ) }
Sourced from offer events where user is alternate party
Sourced from offer events where user is alternate party