Skip to content

Insights: persist search context filters and resolve in the GraphQL

Administrator requested to merge insights/store-context-filters into main

Created by: coury-clark

Stacked on https://github.com/sourcegraph/sourcegraph/pull/33815

Adds db -> resolver plumbing for search contexts, and the necessary db migration to add the column.

Test plan

With filter overrides and no defaults:

query insightview {
  insightViews(
    id: "aW5zaWdodF92aWV3OiIyN2lLSmJZcTNraWs3UXNWbENJOTczQTVrM2ki"
    filters: { searchContexts: ["@dev/srcall"], excludeRepoRegex: "testing" }
  ) {
    nodes {
      id
      presentation {
        ... on LineChartInsightViewPresentation {
          title
        }
      }
      appliedFilters {
        excludeRepoRegex
        includeRepoRegex
        searchContexts
      }
      defaultFilters {
        excludeRepoRegex
        includeRepoRegex
        searchContexts
      }
      dataSeriesDefinitions {
        ... on SearchInsightDataSeriesDefinition {
          query
        }
      }
    }
  }
}
{
  "data": {
    "insightViews": {
      "nodes": [
        {
          "id": "aW5zaWdodF92aWV3OiIyN2lLSmJZcTNraWs3UXNWbENJOTczQTVrM2ki",
          "presentation": {
            "title": "go versions jit"
          },
          "appliedFilters": {
            "excludeRepoRegex": "testing",
            "includeRepoRegex": null,
            "searchContexts": ["@dev/srcall"]
          },
          "defaultFilters": {
            "excludeRepoRegex": "",
            "includeRepoRegex": "",
            "searchContexts": []
          },
          "dataSeriesDefinitions": [
            {
              "query": "file:go\\.mod$ go\\s*(\\d\\.\\d+) patterntype:regexp"
            }
          ]
        }
      ]
    }
  }
}

With defaults:

query insightview {
  insightViews(id: "aW5zaWdodF92aWV3OiIyN2lLSmJZcTNraWs3UXNWbENJOTczQTVrM2ki") {
    nodes {
      id
      presentation {
        ... on LineChartInsightViewPresentation {
          title
        }
      }
      appliedFilters {
        excludeRepoRegex
        includeRepoRegex
        searchContexts
      }
      defaultFilters {
        excludeRepoRegex
        includeRepoRegex
        searchContexts
      }
      dataSeriesDefinitions {
        ... on SearchInsightDataSeriesDefinition {
          query
        }
      }
    }
  }
}
{
  "data": {
    "insightViews": {
      "nodes": [
        {
          "id": "aW5zaWdodF92aWV3OiIyN2lLSmJZcTNraWs3UXNWbENJOTczQTVrM2ki",
          "presentation": {
            "title": "go versions jit"
          },
          "appliedFilters": {
            "excludeRepoRegex": "",
            "includeRepoRegex": "",
            "searchContexts": ["'@dev/srcall'"]
          },
          "defaultFilters": {
            "excludeRepoRegex": "",
            "includeRepoRegex": "",
            "searchContexts": ["'@dev/srcall'"]
          },
          "dataSeriesDefinitions": [
            {
              "query": "file:go\\.mod$ go\\s*(\\d\\.\\d+) patterntype:regexp"
            }
          ]
        }
      ]
    }
  }
}

Merge request reports

Loading