API Followers (GQL)

๐Ÿ“˜

Followers

An API consumer can follow an API in the About tab of the API's listing.

An API consumer can view APIs that they follow in their user profile (click their icon in the upper right, select User Profile, then the APIs Following tab).

Note on followers and announcements: Only users or teams that subscribe to an API receive announcements. API followers do not receive announcements.

Listing an API's Followers

There are at least two ways to do this. The first is using query.apiFollowers:

query ApiFollowers(
  $where: ApiFollowerWhereInput!
  $orderBy: ApiFollowerOrderByInput
  $pagination: PaginationInput
) {
  apiFollowers(where: $where, orderBy: $orderBy, pagination: $pagination) {
    nodes {
      id
      followerId
      apiId
      createdAt
      api {
        id
      }
      follower {
        id
        email
      }
    }
    edges {
      node {
        id
      }
      cursor
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
  }
}
{
  "where": {
    "apiId": "api_737d0adb-a966-4b3c-a4a6-c961fd88b22f"
  },
  "orderBy": {
    "fields": {
      "fieldName": "ID",
      "by": "DESC"
    }
  },
  "pagination": {
    "first": 10
  }
}

Another way to obtain an API's Followers is with query.api:

query readAPI($apiId: ID!) {
  api(id: $apiId) {
    id
    name
    slugifiedName
    visibility
    ownerId
    owner {
      name
      slugifiedName
    }
    followers {
      follower
      id
      user {
        id
        email
      }
    }
    currentVersion {
      name
      id
    }
    versions {
      id
      name
    }
  }
}
{
  "apiId": "api_737d0adb-a966-4b3c-a4a6-c961fd88b22f"
}

Listing a user's Followed APIs

You can use query.users and return followedApis.

query users($where: UserWhereInput!) {
  users(where: $where) {
      id
      thumbnail
      username
      name
      email
      createdAt
      followedApis{
        id
        followerId
        createdAt
        api {
          id
          name
        }
      }
    }
}
{
  "where": {
    "email": "[SOME EMAIL]"
  }
}

List any user or team's followed APIs (admin)

Environment Admins can query for any user or team's followed APIs. This query is used in the Users tab of the Admin Panel. In the Variables, the userId can contain a user or team ID.

๐Ÿ“˜

Under construction

This query is not yet implemented.

๐Ÿ“˜

Environment Admin from personal account

This query only works if you are an Environment Admin. Currently, you must execute this query from your Personal Account (not a team account). This means if the GraphQL Platform API is private, you must personally be invited to use the API.

  query followingApis($userId: ID!) {
    followingApis(userId: $userId){
     nodes {
      id
      name
      visibility
      category
      createdAt
     }
    }
  }
  {
      "userId": "7344547"
  }

Adding a Follower to an API

The example below adds the user or team calling the mutation as a Follower of the API.

If the follower is a user, the follower field will be populated in the results. If the follower is a team, the team id will be returned in the followerId field (the fields in follower will return null). The team's details can be obtained with query.team (see Users, Teams, and Roles (GQL Platform API).

mutation($ApiFollowerCreateInput: ApiFollowerCreateInput!) {
  createApiFollowers(apiFollowers: $ApiFollowerCreateInput) {
    id
    followerId
    apiId
    createdAt
    api {
      id
    }
    follower {
      id
      email
    }
  }
}
{
  "ApiFollowerCreateInput": {
    "apiId": "api_737d0adb-a966-4b3c-a4a6-c961fd88b22f"
  }
}

Deleting a Follower of an API

The example below "unfollows" the user or team calling the mutation.

mutation ($ApiFollowerDeleteInput: ApiFollowerDeleteInput!) {
  deleteApiFollowers(apiFollowers: $ApiFollowerDeleteInput)
}
{
  "ApiFollowerDeleteInput": {
    "apiId": "api_737d0adb-a966-4b3c-a4a6-c961fd88b22f"
  }
}