import { map } from 'rxjs/operators';
import { createInvalidGraphQLQueryResponseError, dataOrThrowErrors, gql, queryGraphQL } from '../backend/graphql';
/**
 * Fetches commits.
 */
export function fetchCommits(repo, rev, args) {
    return queryGraphQL(gql `
            query FetchCommits($repo: ID!, $rev: String!, $first: Int, $currentPath: String, $query: String) {
                node(id: $repo) {
                    ... on Repository {
                        commit(rev: $rev) {
                            ancestors(first: $first, query: $query, path: $currentPath) {
                                nodes {
                                    oid
                                    abbreviatedOID
                                    message
                                    author {
                                        person {
                                            avatarURL
                                            name
                                            email
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        `, Object.assign({}, args, { repo, rev })).pipe(map(dataOrThrowErrors), map(data => {
        if (!data.node || !data.node.commit) {
            throw createInvalidGraphQLQueryResponseError('FetchCommits');
        }
        return data.node.commit.ancestors;
    }));
}
//# sourceMappingURL=backend.js.map