<commit_before>export const Symbols = {
  ARGUMENTS: Symbol('arguments'),
};

export default function astToBody(ast) {
  const fieldNodes = ast.fieldNodes;

  const body = extractSelectionSet(ast.fieldNodes[0].selectionSet);

  return body;
}

function extractSelectionSet(set) {
  let body = {};
  set.selections.forEach(el => {
    if (!el.selectionSet) {
      body[el.name.value] = 1;
    } else {
      body[el.name.value] = extractSelectionSet(el.selectionSet);
      if (el.arguments.length) {
        let argumentMap = {};
        el.arguments.forEach(arg => {
          if (arg.value.kind === "ObjectValue") {
            argumentMap[arg.name.value] = arg.value.fields.reduce((acc, field) => {
              acc[field.name.value] = field.value.value;
              return acc;
            }, {});
          } else {
            argumentMap[arg.name.value] = arg.value.value;
          }
        });

        body[el.name.value][Symbols.ARGUMENTS] = argumentMap;
      }
    }
  });

  return body;
}<commit_msg>fix: extract input types arguments recursively<commit_after>export const Symbols = {
  ARGUMENTS: Symbol('arguments'),
};

export default function astToBody(ast) {
  const fieldNodes = ast.fieldNodes;

  const body = extractSelectionSet(ast.fieldNodes[0].selectionSet);

  return body;
}

function extractArguments(args) {
  if (!Array.isArray(args) || args.length === 0) {
    return {};
  }

  return args.reduce((acc, field) => {
    acc[field.name.value] =
      field.value.kind === 'ObjectValue'
        ? extractArguments(field.value.fields)
        : field.value.value;

    return acc;
  }, {});
}

function extractSelectionSet(set) {
  let body = {};
  set.selections.forEach((el) => {
    if (!el.selectionSet) {
      body[el.name.value] = 1;
    } else {
      body[el.name.value] = extractSelectionSet(el.selectionSet);
      body[el.name.value][Symbols.ARGUMENTS] = extractArguments(el.arguments);
    }
  });

  return body;
}
{'fraction_non_alphanumeric': 0.14831804281345565, 'fraction_numerical': 0.0025484199796126403, 'mean_word_length': 2.775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '1435885', 'n_tokens_mistral': 629, 'n_tokens_neox': 614, 'n_words': 106}