sourcegraph / sourcegraph-public-snapshot

Code AI platform with Code Search & Cody
https://sourcegraph.com
Other
10.12k stars 1.29k forks source link

insights: add support for language stats insights to graphql #35316

Open chwarwick opened 2 years ago

chwarwick commented 2 years ago

Currently graphql only provides metadata about the language stats (pie chart) insight, which the webapp then uses to form a search query and tabulate the results in client.

Add the capability for an insightView to run the search query and return a series for each language returned with a single "current" datapoint.

Out of scope: Tracking multiple datapoints over time addressed in this issue

Example:

query GetInsightView($id: ID){
  insightViews(id: $id) {
    nodes {
      ...InsightDataNode
      __typename
    }
    __typename
  }
}

fragment InsightDataNode on InsightView {
  id
  dataSeries {
    ...InsightDataSeries
    __typename
  }
  __typename
}

fragment InsightDataSeries on InsightsSeries {
  seriesId
  label
  points {
    dateTime
    value
    __typename
  }
  __typename
}

Response:

{
  "data": {
    "insightViews": {
      "nodes": [
        {
          "id": "{VIEW_ID}",
          "dataSeries": [
            {
              "seriesId": "Go",
              "label": "Go",
              "points": [
                {
                  "dateTime": "2021-11-22T00:00:00Z",
                  "value": 6000,
                  "__typename": "InsightDataPoint"
                }
              ],
              "__typename": "InsightsSeries"
            },
            {
              "seriesId": "TypeScript",
              "label": "TypeScript",
              "points": [
                {
                  "dateTime": "2021-11-22T00:00:00Z",
                  "value": 2500,
                  "__typename": "InsightDataPoint"
                }
              ],
              "__typename": "InsightsSeries"
            },
            {
              "seriesId": "Java",
              "label": "Java",
              "points": [
                {
                  "dateTime": "2021-11-22T00:00:00Z",
                  "value": 3000,
                  "__typename": "InsightDataPoint"
                }
              ],
              "__typename": "InsightsSeries"
            }
          ],
          "__typename": "InsightView"
        }
      ],
      "__typename": "InsightViewConnection"
    }
  }
}
sourcegraph-bot-2 commented 2 years ago

Heads up @joelkw @felixfbecker @vovakulikov @unclejustin - the "team/code-insights" label was applied to this issue.