Skip to content

Create award achievement GraphQL mutations

What does this MR do and why?

Learn more about achievements here: &9429

Related to #385382 (closed)

This MR introduces the ability to award achievements.

It also exposes user_achievements against users and achievements.

Screenshots or screen recordings

image

How to set up and validate locally

Hurray for seed data!!! 🎉

lee@Lees-MBP gitlab % FILTER=achievements rake db:seed_fu

== Filtering seed files against regexp: /achievements/

== Seed from /Users/lee/Source/gitlab.com/gitlab-development-kit/gitlab/db/fixtures/development/36_achievements.rb

Generating ahievements
..............
OK
lee@Lees-MBP gitlab % gdk psql                           
psql (12.13)
Type "help" for help.

gitlabhq_development=# select * from achievements;
 id | namespace_id |          created_at           |          updated_at           |         name         | avatar | description | revokeable 
----+--------------+-------------------------------+-------------------------------+----------------------+--------+-------------+------------
 42 |           22 | 2022-12-26 20:08:19.802557+00 | 2022-12-26 20:08:19.802557+00 | revoked              |        |             | f
 43 |           22 | 2022-12-26 20:08:19.806917+00 | 2022-12-26 20:08:19.806917+00 | first mr             |        |             | f
 44 |           22 | 2022-12-26 20:08:19.81519+00  | 2022-12-26 20:08:19.81519+00  | hero                 |        |             | f
 45 |           22 | 2022-12-26 20:08:19.832249+00 | 2022-12-26 20:08:19.832249+00 | leading organization |        |             | f
(4 rows)

gitlabhq_development=# select * from user_achievements;
 id | achievement_id | user_id | awarded_by_user_id | revoked_by_user_id |          created_at           |          updated_at           |          revoked_at           
----+----------------+---------+--------------------+--------------------+-------------------------------+-------------------------------+-------------------------------
 20 |             42 |      43 |                 19 |                 19 | 2022-12-26 20:08:19.847941+00 | 2022-12-26 20:08:19.847941+00 | 2022-12-26 20:08:19.837107+00
 21 |             42 |      44 |                 19 |                 19 | 2022-12-26 20:08:19.857479+00 | 2022-12-26 20:08:19.857479+00 | 2022-12-26 20:08:19.85296+00
 22 |             43 |      44 |                 19 |                    | 2022-12-26 20:08:19.86771+00  | 2022-12-26 20:08:19.86771+00  | 
 23 |             42 |      46 |                 19 |                 19 | 2022-12-26 20:08:19.873158+00 | 2022-12-26 20:08:19.873158+00 | 2022-12-26 20:08:19.870341+00
 24 |             43 |      46 |                 19 |                    | 2022-12-26 20:08:19.881737+00 | 2022-12-26 20:08:19.881737+00 | 
 25 |             44 |      46 |                 19 |                    | 2022-12-26 20:08:19.892662+00 | 2022-12-26 20:08:19.892662+00 | 
 26 |             42 |      47 |                 19 |                 19 | 2022-12-26 20:08:19.899362+00 | 2022-12-26 20:08:19.899362+00 | 2022-12-26 20:08:19.895338+00
 27 |             43 |      47 |                 19 |                    | 2022-12-26 20:08:19.906181+00 | 2022-12-26 20:08:19.906181+00 | 
 28 |             44 |      47 |                 19 |                    | 2022-12-26 20:08:19.914131+00 | 2022-12-26 20:08:19.914131+00 | 
 29 |             45 |      47 |                 19 |                    | 2022-12-26 20:08:19.928664+00 | 2022-12-26 20:08:19.928664+00 | 
(10 rows)
Get a users achievements
query a {
  user(username: "root") {
    userAchievements {
      nodes {
        id
        achievement {
          id
          name
        }
      }
    }
  }
}
Get a group's achievements and the users who've been awarded them
query b {
  namespace(fullPath: "flightjs") {
    achievements {
      nodes {
        id
        name
        userAchievements {
          nodes {
            id
            user {
              username
            }
          }
        }
      }
    }
  }
}
Award an achievement
mutation {
  achievementsAward(input: {
    achievementId: "gid://gitlab/Achievements::Achievement/61",
    userId: "gid://gitlab/User/1" }) {
    userAchievement {
      id
      achievement {
        id
        name
      }
      user {
        id
        username
        name
      }
      awardedByUser {
        username
      }
      revokedByUser {
        username
      }
      createdAt
      updatedAt
      revokedAt
    }
    errors
  }
}

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Lee Tickett

Merge request reports

Loading