<commit_before>import { set } from 'lodash';
import faker from 'faker';
import { getDirectiveValue } from '../utils';

export default {
  name: 'fake',
  description: 'Fakes a field.',
  resolveStatic: {
    enter(node, directive, { ast, resolvers, ancestors }) {
      if (process.env.FAKE) {
        return;
      }
      if (node.kind === 'ObjectTypeDefinition') {
        const isMany = getDirectiveValue(node, 'fake', 'many');
        const isOne = getDirectiveValue(node, 'fake', 'one');
        if (isMany) {
          set(resolvers, `RootQuery.${isMany}`, (source, args) =>
            Array(...{ length: 100 }).map(Number.call, Number),
          );
        }
        if (isOne) {
          set(resolvers, `RootQuery.${isOne}`, (source, args) => ({}));
        }
      } else {
        const isList = node.type.kind === 'ListType';
        const name = getDirectiveValue(node, 'fake', 'type');
        const leftType = ancestors[ancestors.length - 1].name.value;
        const leftField = node.name.value;
        if (name) {
          const [category, field] = name.split('.');
          set(resolvers, `${leftType}.${leftField}`, (source, args) =>
            faker[category][field](),
          );
        } else if (isList) {
          set(resolvers, `${leftType}.${leftField}`, (source, args) =>
            Array(...{ length: 10 }).map(Number.call, Number),
          );
        } else {
          set(resolvers, `${leftType}.${leftField}`, (source, args) => ({}));
        }
      }
    },
  },
};<commit_msg>random items in faker<commit_after>import { set } from 'lodash';
import faker from 'faker';
import { getDirectiveValue } from '../utils';

export default {
  name: 'fake',
  description: 'Fakes a field.',
  resolveStatic: {
    enter(node, directive, { ast, resolvers, ancestors }) {
      if (process.env.FAKE) {
        return;
      }
      if (node.kind === 'ObjectTypeDefinition') {
        const isMany = getDirectiveValue(node, 'fake', 'many');
        const isOne = getDirectiveValue(node, 'fake', 'one');
        if (isMany) {
          set(resolvers, `RootQuery.${isMany}`, (source, args) =>
            Array(...{ length: Math.random() * (100 - 20) + 20 }).map(
              Number.call,
              Number,
            ),
          );
        }
        if (isOne) {
          set(resolvers, `RootQuery.${isOne}`, (source, args) => ({}));
        }
      } else {
        const isList = node.type.kind === 'ListType';
        const name = getDirectiveValue(node, 'fake', 'type');
        const leftType = ancestors[ancestors.length - 1].name.value;
        const leftField = node.name.value;
        if (name) {
          const [category, field] = name.split('.');
          set(resolvers, `${leftType}.${leftField}`, (source, args) =>
            faker[category][field](),
          );
        } else if (isList) {
          set(resolvers, `${leftType}.${leftField}`, (source, args) =>
            Array(...{ length: Math.random() * (10 - 3) + 3 }).map(
              Number.call,
              Number,
            ),
          );
        } else {
          set(resolvers, `${leftType}.${leftField}`, (source, args) => ({}));
        }
      }
    },
  },
};
{'fraction_non_alphanumeric': 0.17886178861788618, 'fraction_numerical': 0.005628517823639775, 'mean_word_length': 2.0293560606060606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '131', 'n_tokens_mistral': 1009, 'n_tokens_neox': 994, 'n_words': 219}