`StatusContext` should be a list of nodes, not a node

Hi!

I’m interested in knowing whether it’s possible to fetch all the statuses for all the contexts for a given reference using the GQL API.

The query that I’m currently doing is the following:

{
  repository(owner: "owner", name: "name") {
    pullRequests(headRefName: "head-ref", last: 1) {
      nodes {
        id
        commits(first: 10) {
          nodes {
            commit {
              oid
              status {
                contexts {
                  context
                  createdAt
                  id
                  description
                  state
                }
              }
            }
          }
        }
      }
    }
  }
}

This query returns a single status for each status context, and those are the last ones for each:

{
  "data": {
    "repository": {
      "pullRequests": {
        "nodes": [
          {
            "id": "some-id",
            "commits": {
              "nodes": [
                {
                  "commit": {
                    "oid": "some-oid",
                    "status": {
                      "contexts": [
                        {
                          "context": "context-1",
                          "createdAt": "2021-07-06T21:28:26Z",
                          "id": "***",
                          "description": "Your tests passed!",
                          "state": "SUCCESS"
                        },
                        {
                          "context": "context-2",
                          "createdAt": "2021-07-06T21:25:26Z",
                          "id": "***",
                          "description": "Your tests passed!",
                          "state": "SUCCESS"
                        },
                      ]
                    }
                  }
                }
              ]
            }
          }
        ]
      }
    }
  }
}

On the other hand, if I use the REST API with this query:

curl -i -u se7entyse7en:$(cat token) https://api.github.com/repos/owner/name/commits/some-oid/statuses

where some-oid is the corresponding retrieved with the GQL API, the output contains ALL the statuses. In particular, I can see all the statuses of context-1 and context-2 that happened before those that are returned by the GQL API.

It seems a limitation of the GQL schema given that StatusContext is a node instead of being a list of nodes. Basically, I expect StatusContext to be of type [Status!]! where Status represents a single status for the given context.

Am I missing something? Is this something expected to be changed in the future? Is the REST API the only option?

Thanks.

10 Likes

Friendly ping :slight_smile:. Does anyone know something about the topic?

Cross-posted the question on StackOverflow: graphql - Github GrapQL API returns only the last StatusContext for each context - Stack Overflow

I opened a support ticket and this is the expected behavior indeed, there are no plans for changing it. The only solution is to use the REST API.