ranbuta

Posted on Jan 11, 2022Read on Mirror.xyz

Fetch someone follow list from Foundation

const ADDRESS = '0x...' // Change this ADDRESS
fetch(
  'https://hasura2.foundation.app/v1/graphql', {
  'referrer': 'https://foundation.app/',
  'referrerPolicy': 'strict-origin-when-cross-origin',
  'body': JSON.stringify({
      'query': `
          query UserFollowing($publicKey: String!, $currentUserPublicKey: String!, $offset: Int!, $limit: Int!) {
        user: user_by_pk(publicKey: $publicKey) {
          following(where: {isFollowing: {_eq: true}}, offset: $offset, limit: $limit) {
            user: userByFollowedUser {
              name
              username
              publicKey
              profileImageUrl
              isFollowingUser: follows_aggregate(
                where: {user: {_eq: $currentUserPublicKey}, isFollowing: {_eq: true}}
              ) {
                aggregate {
                  count
                }
              }
            }
          }
        }
      }
    `,
    'variables': {
        'publicKey': ADDRESS,
        'currentUserPublicKey': ADDRESS,
        'limit': 42069,
        'offset': 0
    }
  }),
  'method': 'POST',
  'mode': 'cors',
  'credentials': 'omit'
})
  .then(response => response.json())
  .then(
    ({
      data: {
        user: {
          following = []
        }
      }
    }) => {
      const result = following
        .map(({
          user: {
            name,
            username,
            publicKey,
            profileImageUrl
          }
        }) => `${publicKey}\t${name}\t${username}\t${profileImageUrl}`)
        .join("\n");
      console.log(result);
    }
  );

👇

0x...	Name 1	username1	https://...png
0x...	Name 2	username2	https://...jpg

👌