Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

feat: extend graphql User with evaluateFeatureFlag operation#60828

Merged
bahrmichael merged 10 commits into
mainfrom
bahrmichael/59169
Mar 6, 2024
Merged

feat: extend graphql User with evaluateFeatureFlag operation#60828
bahrmichael merged 10 commits into
mainfrom
bahrmichael/59169

Conversation

@bahrmichael

@bahrmichael bahrmichael commented Mar 4, 2024

Copy link
Copy Markdown
Contributor

This PR closes #59169 by extending the GraphQL User schema with the evaluateFeatureFlag function.

This function takes the name of a feature flag, and returns if this feature flag is active for the given user.

It's different to the existing root-level evaluateFeatureFlag as it does not evaluate for the calling user, but for any users that the user requests data for.

Example usage:

{
  users {
    nodes {
      username
      flagWithOverrides:evaluateFeatureFlag(flagName: "test-flag-secret")
      nonExistent:evaluateFeatureFlag(flagName: "non-existent-flag")
    }
  }
  currentUser {
    username
    evaluateFeatureFlag(flagName: "test-flag")
  }
}

This may yield (depending on your flags and overrides)

{
  "data": {
    "users": {
      "nodes": [
        {
          "username": "test",
          "flagWithOverrides": false,
          "nonExistent": null
        },
        {
          "username": "bahrmichael",
          "flagWithOverrides": true,
          "nonExistent": null
        },
        {
          "username": "sourcegraph",
          "flagWithOverrides": true,
          "nonExistent": null
        },
        {
          "username": "michael-2",
          "flagWithOverrides": false,
          "nonExistent": null
        }
      ]
    },
    "currentUser": {
      "username": "sourcegraph",
      "evaluateFeatureFlag": true
    }
  }
}

Test plan

  • Added new tests in user_tests.go to verify if the new field works from the User and Users schema.
  • The SQL query function is covered by feature_flags_test.go#testUserFlags.
  • Manual testing in the UI to verify if overrides work as expected (see example result pasted above).

@cla-bot cla-bot Bot added the cla-signed label Mar 4, 2024
@bahrmichael bahrmichael changed the title feat: extend graphql user schema with feature flag overrides feat: extend graphql user with evaluateFeatureFlag operation Mar 6, 2024
@bahrmichael bahrmichael marked this pull request as ready for review March 6, 2024 15:16
@bahrmichael

bahrmichael commented Mar 6, 2024

Copy link
Copy Markdown
Contributor Author

Open questions:

  • Documentation? -> Mostly self explaining, and added docstring
  • Changelog? -> That's added now
  • I've only run the tests that I added locally (and some additional tests from the same package). Are there more tests that I need to run locally which don't run in CI?

@bahrmichael bahrmichael changed the title feat: extend graphql user with evaluateFeatureFlag operation feat: extend graphql User with evaluateFeatureFlag operation Mar 6, 2024

@camdencheek camdencheek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Wasn't expecting this one to be quite so straightforward. Looks great to me, and thanks for the tests!

@airamare01 airamare01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Thanks Michael

@bahrmichael bahrmichael enabled auto-merge (squash) March 6, 2024 15:55
@bahrmichael bahrmichael merged commit e9ef9d8 into main Mar 6, 2024
@bahrmichael bahrmichael deleted the bahrmichael/59169 branch March 6, 2024 16:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use GraphQl to collect users and feature flags set

3 participants