Something went wrong with your query -- new error code


#1

Error: Something went wrong while executing your query. Please include F07B:3E57:735303:FE5B1C:5A98417C when reporting this issue.:

Here is my query. The first part is a query for fetching the proper cursor for the last commit, and the second part passes that cursor as a variable to a new query. Maybe overall there’s a more efficient way to access a repo’s first commit?

I’m using npm lib https://www.npmjs.com/package/graphql-request. I think it has something to do with using ‘before’ because when I try the query for the first item in history with no value for pagination, it works.

    client.request(`{
      repository(owner: "${owner}", name: "${repo}") {
        ref(qualifiedName: "master") {
          target {
            ... on Commit {
              history(first: 1) {
                pageInfo {
                  endCursor
                }
              }
            }
          }
        }
      }
      }`)
      .then(res => {
        const variable = { before: res.repository.ref.target.history.pageInfo.endCursor}
        const query = `query firstCommit($before: String!){
          repository(owner: "${owner}", name: "${repo}"){
            defaultBranchRef{
              target{
                ...on Commit{
                  history(last: 1 before: $before) {
                    edges {
                      node {
                        id
                      }
                    }
                    nodes {
                      message
                      authoredDate
                      author {
                        avatarUrl
                        date
                        email
                        name
                      }
                    }
                  }
                }
              }
            }
          }
        }
        `
        return client.request(query, variable)

#2

If you’re just trying to access a repo’s first commit, you could use this query:

query{
  repository(owner:"owner", name:"name"){
    defaultBranchRef{
      target{
        ... on Commit{
          oid
        }
      }
    }
  }
}

Does this work for you?


#4

Incredible, thank you so much. So is this the default selection for Commit? If u have a second, could you explain why this works?


#5

Yeah! So if you look at the API docs for Ref.target, you’ll see it returns a GitObject, which is a generic polymorphic interface representing “some git object”. If you want to access the underlying specific object type, you need to use the spread operator (...). In our case, we know our ref is pointing at a commit, so ... on Commit allows us to make selections on the Commit object.

If we weren’t sure what our ref was pointing at, we could do something like this:

target {
 ... on Commit {
    oid
  }
  ... on Tag {
    oid
  }
  ... on Tree {
    entries {
      name
    }
  }
}

It’s a little confusing, but this syntax lets us handle polymorphic relationships in GraphQL :slight_smile:
Let me know if you have any more questions!


#6

Awesome, I understand the spread operator decently well but is it just that the specific Commit accessed through the ref for that repo returns the first commit, rather than the last, I guess this makes sense because its the originating commit? Because Commit could theoretically represent any commit, no?


#7

That happens because in my example, I’m using defaultBranchRef, which is most likely master and pointing at the latest commit in the master branch. Thus when we grab the target from this ref, it resolves to the latest commit :slight_smile:


#8

Ah yes so your query returns the latest commit but I want the first commit.


#9

Ahh sorry, I misunderstood your question! It’s a bit confusing because the history connection is actually reversed, the first entry is actually the most recent commit in the history.

We don’t support back-pagination on the Commit history connection without a before argument for performance reasons. That means in a big repository, you can’t find the first commit without making {number of commits}/100 queries.

We’re looking into better ways to address this use-case, but for now, you could create a ref pointing at the initial commit and use the Repository.ref field.

{
  repository(owner:"owner", name:"repo-name"){
    ref(qualifiedName: "refs/heads/initial-commit-branch"){
      target{
        ... on Commit{
          oid
        }
      }
    }
  }
}

@echjordan Will this work for you?