<commit_before>
import {
  GraphQLBoolean,
  GraphQLList,
  GraphQLInt,
  GraphQLNonNull,
  GraphQLObjectType,
  GraphQLInputObjectType,
  GraphQLSchema,
  GraphQLString,
  GraphQLID,
  GraphQLEnumType
} from 'graphql';

import {
  connectionArgs,
  connectionDefinitions,
  connectionFromArray,
  fromGlobalId,
  globalIdField,
  mutationWithClientMutationId,
  nodeDefinitions,
} from 'graphql-relay';

import {
  GroupCall
} from './models';

import moment from 'moment';
import Promise from 'bluebird';
import Maestro from '../maestro';
import thinky from './thinky';


var {nodeInterface, nodeField} = nodeDefinitions(
  (globalId) => {
    var {type, id} = fromGlobalId(globalId);
    if (type === 'GroupCall')
      return GroupCall.get(id);
    else if (type === 'Viewer')
      return getViewer();
    else
      return null;
  },
  (obj) => {
    if (obj instanceof GroupCall)
      return GraphQLGroupCall;
    else
      return GraphQLViewer;
  }
);

function getViewer() {
  return {id: '1'}
}

 var GraphQLGroupCall = new GraphQLObjectType({
  name: "GroupCall",
  description: 'A group call',
  fields: () => ({
    id: globalIdField('GroupCall'),
    name: { type: GraphQLString },
    scheduledTime: { type: GraphQLInt },
    maxSignups: { type: GraphQLInt }
  }),
  interfaces: [nodeInterface]
});

var {
  connectionType: GraphQLGroupCallConnection,
} = connectionDefinitions({
  name: 'GroupCall',
  nodeType: GraphQLGroupCall
});


var GraphQLViewer = new GraphQLObjectType({
  name: 'Viewer',
  fields: () => ({
    id: globalIdField('Viewer'),
    groupCallList: {
      type: GraphQLGroupCallConnection,
      args: {
       upcoming: {
          type: GraphQLBoolean,
          defaultValue: null
        },
        ...connectionArgs,
      },
      resolve: async (viewer, {first, upcoming}) => {
        let r = thinky.r;
        let queryFilter = {};
        if (upcoming)
          queryFilter = (row) => row('scheduledTime').gt(new Date());
        else if (upcoming == false)
          queryFilter = (row) => row('scheduledTime').le(new Date());

        var calls = await r.table(GroupCall.getTableName())
          .orderBy('scheduledTime')
          .filter(queryFilter)
          .limit(first)

        return connectionFromArray(calls, {first});
      }
    },
    groupCall: {
      type: GraphQLGroupCall,
      args: {
        id: { type: new GraphQLNonNull(GraphQLString) }
      },
      resolve: async (viewer, {id}) => {
        let localID = fromGlobalId(id).id;
        var call = await GroupCall.get(localID);
        return call;
      }
    }
  }),
  interfaces: [nodeInterface]
})

var GraphQLGroupCallInput = new GraphQLInputObjectType({
  name: 'GroupCallInput',
  fields: {
    name: { type: new GraphQLNonNull(GraphQLString) },
    scheduledTime: { type: new GraphQLNonNull(GraphQLInt) },
    maxSignups: { type: new GraphQLNonNull(GraphQLInt) },
    duration: { type: new GraphQLNonNull(GraphQLInt) }
  }
})

var GraphQLBatchCreateGroupCallMutation = mutationWithClientMutationId({
  name: 'BatchCreateGroupCall',
  inputFields: {
    groupCallList: { type: new GraphQLNonNull(new GraphQLList(GraphQLGroupCallInput)) }
  },
  outputFields: {
    viewer: {
      type: GraphQLViewer,
      resolve: () => {
        return getViewer();
      }
    }
  },
  mutateAndGetPayload: async ({topic, groupCallList}) => {
    var promises = [];
    var maestro = new Maestro('PWC0PU44ZPOHAI9L', '60aedf735b2b6f7cf83f34c8b560ac9b', 'http://myaccount.maestroconference.com/_access');
    for (let index = 0; index < groupCallList.length; index++) {
      let groupCall = groupCallList[index];
      let response = await maestro.createConferenceCall(groupCall.name, groupCall.maxSignups, moment(groupCall.scheduledTime).format("YYYY.MM.DD HH:MM:SS"), groupCall.duration)

      promises.push(GroupCall.save({
        name: groupCall.name,
        scheduledTime: groupCall.scheduledTime,
        maxSignups: groupCall.maxSignups,
        duration: groupCall.duration,
        maestroConferenceUID: 'test',//response.value.UID,
        signups: []
      }));
    };

    await Promise.all(promises);

    return {};
  }
});

var RootMutation = new GraphQLObjectType({
  name: 'RootMutation',
  fields: () => ({
    batchCreateGroupCall: GraphQLBatchCreateGroupCallMutation<commit_msg>Create maestro calls in UTC<commit_after>
import {
  GraphQLBoolean,
  GraphQLList,
  GraphQLInt,
  GraphQLNonNull,
  GraphQLObjectType,
  GraphQLInputObjectType,
  GraphQLSchema,
  GraphQLString,
  GraphQLID,
  GraphQLEnumType
} from 'graphql';

import {
  connectionArgs,
  connectionDefinitions,
  connectionFromArray,
  fromGlobalId,
  globalIdField,
  mutationWithClientMutationId,
  nodeDefinitions,
} from 'graphql-relay';

import {
  GroupCall
} from './models';

import moment from 'moment';
import Promise from 'bluebird';
import Maestro from '../maestro';
import thinky from './thinky';


var {nodeInterface, nodeField} = nodeDefinitions(
  (globalId) => {
    var {type, id} = fromGlobalId(globalId);
    if (type === 'GroupCall')
      return GroupCall.get(id);
    else if (type === 'Viewer')
      return getViewer();
    else
      return null;
  },
  (obj) => {
    if (obj instanceof GroupCall)
      return GraphQLGroupCall;
    else
      return GraphQLViewer;
  }
);

function getViewer() {
  return {id: '1'}
}

 var GraphQLGroupCall = new GraphQLObjectType({
  name: "GroupCall",
  description: 'A group call',
  fields: () => ({
    id: globalIdField('GroupCall'),
    name: { type: GraphQLString },
    scheduledTime: { type: GraphQLInt },
    maxSignups: { type: GraphQLInt }
  }),
  interfaces: [nodeInterface]
});

var {
  connectionType: GraphQLGroupCallConnection,
} = connectionDefinitions({
  name: 'GroupCall',
  nodeType: GraphQLGroupCall
});


var GraphQLViewer = new GraphQLObjectType({
  name: 'Viewer',
  fields: () => ({
    id: globalIdField('Viewer'),
    groupCallList: {
      type: GraphQLGroupCallConnection,
      args: {
       upcoming: {
          type: GraphQLBoolean,
          defaultValue: null
        },
        ...connectionArgs,
      },
      resolve: async (viewer, {first, upcoming}) => {
        let r = thinky.r;
        let queryFilter = {};
        if (upcoming)
          queryFilter = (row) => row('scheduledTime').gt(new Date());
        else if (upcoming == false)
          queryFilter = (row) => row('scheduledTime').le(new Date());

        var calls = await r.table(GroupCall.getTableName())
          .orderBy('scheduledTime')
          .filter(queryFilter)
          .limit(first)

        return connectionFromArray(calls, {first});
      }
    },
    groupCall: {
      type: GraphQLGroupCall,
      args: {
        id: { type: new GraphQLNonNull(GraphQLString) }
      },
      resolve: async (viewer, {id}) => {
        let localID = fromGlobalId(id).id;
        var call = await GroupCall.get(localID);
        return call;
      }
    }
  }),
  interfaces: [nodeInterface]
})

var GraphQLGroupCallInput = new GraphQLInputObjectType({
  name: 'GroupCallInput',
  fields: {
    name: { type: new GraphQLNonNull(GraphQLString) },
    scheduledTime: { type: new GraphQLNonNull(GraphQLInt) },
    maxSignups: { type: new GraphQLNonNull(GraphQLInt) },
    duration: { type: new GraphQLNonNull(GraphQLInt) }
  }
})

var GraphQLBatchCreateGroupCallMutation = mutationWithClientMutationId({
  name: 'BatchCreateGroupCall',
  inputFields: {
    groupCallList: { type: new GraphQLNonNull(new GraphQLList(GraphQLGroupCallInput)) }
  },
  outputFields: {
    viewer: {
      type: GraphQLViewer,
      resolve: () => {
        return getViewer();
      }
    }
  },
  mutateAndGetPayload: async ({topic, groupCallList}) => {
    var promises = [];
    var maestro = new Maestro('PWC0PU44ZPOHAI9L', '60aedf735b2b6f7cf83f34c8b560ac9b', 'http://myaccount.maestroconference.com/_access');
    for (let index = 0; index < groupCallList.length; index++) {
      let groupCall = groupCallList[index];
      let response = await maestro.createConferenceCall(groupCall.name, groupCall.maxSignups, moment(groupCall.scheduledTime).utc().format("YYYY.MM.DD HH:MM:SS"), groupCall.duration)

      promises.push(GroupCall.save({
        name: groupCall.name,
        scheduledTime: groupCall.scheduledTime,
        maxSignups: groupCall.maxSignups,
        duration: groupCall.duration,
        maestroConferenceUID: 'test',//response.value.UID,
        signups: []
      }));
    };

    await Promise.all(promises);

    return {};
  }
});

var RootMutation = new GraphQLObjectType({
  name: 'RootMutation',
  fields: () => ({
    batchCreateGroupCall: GraphQLBatchCreateGroupCallMutation
{'fraction_non_alphanumeric': 0.12635587352873298, 'fraction_numerical': 0.005308100623124856, 'mean_word_length': 3.170837343599615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3798613', 'n_tokens_mistral': 2761, 'n_tokens_neox': 2763, 'n_words': 573}