Introduce codeSuggestionsContexts field to CurrentUser GraphQL type

What does this MR do and why?

Related to #512976 (closed)

We are introducing the Imports additional context to Code Suggestions as part of our focus area to improve quality. To allow for a graceful rollout to users, this additional context will be introduced behind a Feature Flag, which the GitLab Language Server can check through the GraphQL API.

This MR introduces the codeSuggestionsContexts field to the CurrentUser GraphQL type. The new field indicates which additional context categories are available for the user in Code Suggestions.

  • The repository_xray context (which has already been introduced) is available as long as the user has access to code suggestions
  • The open_tabs context (which has already been introduced) is available as long as the user has access to code suggestions
  • The imports context is toggled by a Feature Flag introduced in this MR

While only imports is needed for the related issue, we need to reflect the domain and return all the additional context categories for the new field.

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

N/A

How to set up and validate locally

Setup

  1. Make sure you have Duo Code Suggestions enabled on your GDK. You can follow either instruction depending on whether your GDK is on Self-Managed or SaaS mode.

    Alternatively, you can change the GlobalPolicy code to have it return true for the access_code_suggestions permission.

  2. Make sure that the ai_duo_code_suggestions_switch Feature Flag is enabled.

Test

Test the following query on your GDK's GraphQL explorer (e.g. http://gdk.test:3000/-/graphql-explorer)

query {
  currentUser {
    codeSuggestionsContexts
  }
}

Before - on master branch

You should get an error:

{
  "errors": [
    {
      "graphQLErrors": [
        {
          "message": "Field 'codeSuggestionsContexts' doesn't exist on type 'CurrentUser'",
        }
      ]
    }
  ]
}

After - on 512976-graphql-code-suggestions-features branch

With the code_suggestions_include_context_imports FF disabled

The codeSuggestionsContexts field should have the value ['repository_xray', 'open_tabs']:

{
  "data": {
    "currentUser": {
      "codeSuggestionsContexts": [
        "repository_xray",
        "open_tabs"
      ]
    }
  }
}

With the code_suggestions_include_context_imports FF enabled

The codeSuggestionsContexts field should have an additional item - imports:

{
  "data": {
    "currentUser": {
      "codeSuggestionsContexts": [
        "repository_xray",
        "open_tabs",
        "imports"
      ]
    }
  }
}
Edited by Pam Artiaga

Merge request reports

Loading