<commit_before>const uuidV4 = require('uuid/v4');
import gql from "graphql-tag/index";
import * as _ from "lodash";

import {MutationOptions} from "apollo-client";
import {ApolloQueryResult} from "apollo-client";
import {ObservableQuery} from "apollo-client";

import {EDMConnection} from "../edmKit/connection";
import EDMFile from "./file_tracking";

export class EDMQueries {

    public static configQuery(connection: EDMConnection,
                              variables = {}): ObservableQuery {
        const query = gql`query MeQuery {
                              currentClient {
                                id
                                attributes
                                  sources {
                                  id
                                  name
                                  destinations {
                                    id
                                    base
                                    host {
                                      id
                                    }
                                  }
                                }
                                hosts {
                                  id
                                  settings
                                  name
                                }
                              }
                            }`;
        return connection.watchQuery({
            query: query,
            variables: variables,
        });
    }

    public static checkFileQuery(file: EDMFile, source_name: string) {
        return gql`query checkFile {
                      currentClient {
                        sources(id: "${source_name}") {
                          file(id: "${file._id}") {
                            status
                            stats
                          }
                        }
                      }
                    }`;
    }

    public static createOrUpdateFile(
        file: EDMFile,
        source_name: string,
        mutation_id?: string) : MutationOptions {

        if (mutation_id == null) {
            mutation_id = uuidV4();
        }

        const mutation = gql`
        mutation createOrUpdateFile($input: CreateOrUpdateFileInput!) {
         createOrUpdateFile(input: $input) {
            clientMutationId
            file {
                filepath
                file_transfers {
                    id
                    status
                    bytes_transferred
                    destination {
                        host_id
                    }
                }
            }
         }
        }`;
        const vars = {
            "input": {
                "clientMutationId": mutation_id,
                "source": {"name": source_name},
                // "file": file.getGqlVariables(),
                "file": EDMQueries.getEDMFileGqlVariables(file),
            }
        };

        return {
            mutation: mutation,
            variables: vars
        } as MutationOptions;
    }

    public static getEDMFileGqlVariables(file: EDMFile) {
        let variables = _.pick(file.stats, ['size', 'mtime', 'atime', 'ctime', 'birthtime', 'mode']);
        variables['filepath'] = file.filepath;
        return variables;
    }

    public static registerFileWithServer(
                                  connection: EDMConnection,
                                  file: EDMFile,
                                  source_name: string,
                                  mutation_id?: string): Promise<ApolloQueryResult> {

        const mutation = EDMQueries.createOrUpdateFile(
            file,
            source_name,
            mutation_id);

        return connection.mutate(mutation);
            // .then((value) => {
            //         console.log(JSON.stringify(value));
            //         return value;
            // });
    }

    public static updateFileTransfer(connection: EDMConnection,
                                     transfer: EDMCachedFileTransfer): Promise<ApolloQueryResult> {
        const query = gql`
        mutation updateFileTransfer($input: UpdateFileTransferInput!) {
         updateFileTransfer(input: $input) {
            clientMutationId
            file_transfers {
                id
                status
                bytes_transferred
            }
         }
        }
        `;
        const mutation = {
            mutation: query,
            variables: {
                id: transfer.id,
                bytes_transferred: transfer.bytes_transferred,
                status: transfer.status,
            }
        } as MutationOptions;

        return connection.mutate(mutation);
    }
}<commit_msg>Update queries to support pagination, use hostId not host{id}.<commit_after>const uuidV4 = require('uuid/v4');
import gql from "graphql-tag/index";
import * as _ from "lodash";

import {MutationOptions} from "apollo-client";
import {ApolloQueryResult} from "apollo-client";
import {ObservableQuery} from "apollo-client";

import {EDMConnection} from "../edmKit/connection";
import EDMFile from "./file_tracking";

export class EDMQueries {

    public static configQuery(connection: EDMConnection,
                              variables = {}): ObservableQuery {
        const query = gql`query MeQuery {
                              currentClient {
                                id
                                attributes
                                  sources {
                                  id
                                  name
                                  destinations {
                                    id
                                    base
                                    hostId
                                  }
                                }
                                hosts {
                                  id
                                  settings
                                  name
                                }
                              }
                            }`;
        return connection.watchQuery({
            query: query,
            variables: variables,
        });
    }

    public static checkFileQuery(file: EDMFile, source_name: string) {
        return gql`query checkFile {
                      currentClient {
                        sources(id: "${source_name}") {
                          file(id: "${file._id}") {
                            status
                            stats
                          }
                        }
                      }
                    }`;
    }

    public static createOrUpdateFile(
        file: EDMFile,
        source_name: string,
        mutation_id?: string) : MutationOptions {

        if (mutation_id == null) {
            mutation_id = uuidV4();
        }

        const mutation = gql`
            mutation createOrUpdateFile($input: CreateOrUpdateFileInput!) {
                createOrUpdateFile(input: $input) {
                 clientMutationId
                    file {
                      filepath
                      fileTransfers(first: 999) {
                        edges {
                          node {
                            id
                            status
                            bytesTransferred
                            destination {
                              hostId
                            }
                          }
                        }
                      }
                    }
                  }
              }`;
        const vars = {
            "input": {
                "clientMutationId": mutation_id,
                "source": {"name": source_name},
                // "file": file.getGqlVariables(),
                "file": EDMQueries.getEDMFileGqlVariables(file),
            }
        };

        return {
            mutation: mutation,
            variables: vars
        } as MutationOptions;
    }

    public static getEDMFileGqlVariables(file: EDMFile) {
        let variables = _.pick(file.stats, ['size', 'mtime', 'atime', 'ctime', 'birthtime', 'mode']);
        variables['filepath'] = file.filepath;
        return variables;
    }

    public static registerFileWithServer(
                                  connection: EDMConnection,
                                  file: EDMFile,
                                  source_name: string,
                                  mutation_id?: string): Promise<ApolloQueryResult> {

        const mutation = EDMQueries.createOrUpdateFile(
            file,
            source_name,
            mutation_id);

        return connection.mutate(mutation);
            // .then((value) => {
            //         console.log(JSON.stringify(value));
            //         return value;
            // });
    }

    public static updateFileTransfer(connection: EDMConnection,
                                     transfer: EDMCachedFileTransfer): Promise<ApolloQueryResult> {
        const query = gql`
        mutation updateFileTransfer($input: UpdateFileTransferInput!) {
         updateFileTransfer(input: $input) {
          clientMutationId
          fileTransfers(first: 999) {
            edges {
              node {
                status
                bytesTransferred
                destination {
                  hostId
                }
              }
            }
          }
         }
        }
        `;
        const mutation = {
            mutation: query,
            variables: {
                id: transfer.id,
                bytes_transferred: transfer.bytes_transferred,
                status: transfer.status,
            }
        } as MutationOptions;

        return connection.mutate(mutation);
    }
}

{'fraction_non_alphanumeric': 0.07459159560258913, 'fraction_numerical': 0.0012329189355799856, 'mean_word_length': 0.9267616785431513, 'pattern_counts': {'":': 12, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2085335', 'n_tokens_mistral': 2243, 'n_tokens_neox': 2107, 'n_words': 430}