import { map } from 'rxjs/operators';
import { gql, queryGraphQL } from '../../../backend/graphql';
import { createAggregateError } from '../../../util/errors';
import { memoizeObservable } from '../../../util/memoize';
export const fetchBlameFile2 = memoizeObservable((ctx) => queryGraphQL(gql `
                query BlameFile(
                    $repoPath: String!
                    $commitID: String!
                    $filePath: String!
                    $startLine: Int!
                    $endLine: Int!
                ) {
                    repository(name: $repoPath) {
                        commit(rev: $commitID) {
                            blob(path: $filePath) {
                                blame(startLine: $startLine, endLine: $endLine) {
                                    startLine
                                    endLine
                                    startByte
                                    endByte
                                    rev
                                    author {
                                        person {
                                            name
                                            email
                                        }
                                        date
                                    }
                                    message
                                    commit {
                                        url
                                    }
                                }
                            }
                        }
                    }
                }
            `, {
    repoPath: ctx.repoPath,
    commitID: ctx.commitID,
    filePath: ctx.filePath,
    startLine: ctx.line,
    endLine: ctx.line,
}).pipe(map(result => {
    if (!result.data ||
        !result.data.repository ||
        !result.data.repository.commit ||
        !result.data.repository.commit.blob ||
        !result.data.repository.commit.blob.blame) {
        throw createAggregateError(result.errors);
    }
    return result.data.repository.commit.blob.blame;
})), ({ line }) => line.toString());
//# sourceMappingURL=backend.js.map