Has mirrored publication

You need to know if the logged user has mirrored this publication it's viewing, to do this you need to look at the mirrors property on the publication response. This returns an array of publications ids of the mirrored publication as a profile can mirror a publication many times. In the mirrors field resolver you can pass in a profileId you wish to know the mirrrors state for, most apps would use the logged in users selected profile they are browsing on.

API design basic

please note the example below doesn't pick all the content out of the publication it just shows you the field used to get that back.

query Publications {
  publications(request: {
    profileId: "0x09",
    publicationTypes: [POST, COMMENT, MIRROR],
    limit: 10,
  }) {
    items {
      __typename 
      ... on Post {
        mirrors(profileId: "0x01")
      }
      ... on Comment {
        mirrors(profileId: "0x01")
      }
      ... on Mirror {
        mirrors(profileId: "0x01")
      }
    }
    pageInfo {
      prev
      next
      totalCount
    }
  }
}

profileId for mirrors can pass in as a variable easily enough as well. You can imagine passing the logged-in users profile they are browsing on to see if they have mirrored the publication. This can be hooked in like this for every query which returns a publication type (Post or Comment or Mirror)

query Publications($publicationsRequest: PublicationsQueryRequest!, $profileId: ProfileId) {
  publications(request: $publicationsRequest) {
    items {
      __typename 
      ... on Post {
        mirrors(profileId: $profileId)
      }
      ... on Comment {
        mirrors(profileId: $profileId)
      }
      ... on Mirror {
        mirrors(profileId: $profileId)
      }
    }
    pageInfo {
      prev
      next
      totalCount
    }
  }
}

Did this page help you?