import { map } from 'rxjs/operators';
import { gql, queryGraphQL } from '../backend/graphql';
import { createAggregateError } from '../util/errors';
/**
 * Fetches symbols.
 */
export function fetchSymbols(repo, rev, args) {
    return queryGraphQL(gql `
            query Symbols($repo: ID!, $rev: String!, $first: Int, $query: String) {
                node(id: $repo) {
                    ... on Repository {
                        commit(rev: $rev) {
                            symbols(first: $first, query: $query) {
                                pageInfo {
                                    hasNextPage
                                }
                                nodes {
                                    name
                                    containerName
                                    kind
                                    language
                                    location {
                                        resource {
                                            path
                                        }
                                        range {
                                            start {
                                                line
                                                character
                                            }
                                            end {
                                                line
                                                character
                                            }
                                        }
                                    }
                                    url
                                }
                            }
                        }
                    }
                }
            }
        `, Object.assign({}, args, { repo, rev })).pipe(map(({ data, errors }) => {
        if (!data ||
            !data.node ||
            !data.node.commit ||
            !data.node.commit.symbols ||
            !data.node.commit.symbols.nodes) {
            throw createAggregateError(errors);
        }
        return data.node.commit.symbols;
    }));
}
//# sourceMappingURL=backend.js.map