<commit_before>'use strict';

const { GraphQLNonNull, GraphQLList } = require('graphql');

// `data` argument
const getDataArgument = function (def, opts) {
  // Only for mutation commands, but not delete
  const hasData = dataCommandTypes.includes(def.command.type);
  if (!hasData) { return {}; }

  const type = getDataObjectType(def, opts);

  // Retrieves description before wrapping in modifers
  const { description } = type;

  return { data: { type, description } };
};

const getDataObjectType = function ({ command }, { dataObjectType }) {
  // Add required and array modifiers
  const type = new GraphQLNonNull(dataObjectType);

  // Only multiple with createMany or replaceMany
  const isMultiple = command.multiple &&
    multipleDataCommandTypes.includes(command.type);

  if (isMultiple) {
    return new GraphQLNonNull(new GraphQLList(type));
  }

  return type;
};

const dataCommandTypes = ['create', 'replace', 'patch'];
const multipleDataCommandTypes = ['create', 'replace'];

module.exports = {
  getDataArgument,
};<commit_msg>Fix args.data requiredness in GraphQL schema<commit_after>'use strict';

const { GraphQLNonNull, GraphQLList } = require('graphql');

// `data` argument
const getDataArgument = function (def, opts) {
  // Only for mutation commands, but not delete
  const hasData = dataCommandTypes.includes(def.command.type);
  if (!hasData) { return {}; }

  const type = getDataObjectType(def, opts);

  // Retrieves description before wrapping in modifers
  const { description } = type;

  return { data: { type, description } };
};

const getDataObjectType = function ({ command }, { dataObjectType }) {
  // Only multiple with createMany or replaceMany
  const isMultiple = command.multiple &&
    multipleDataCommandTypes.includes(command.type);

  // Add required and array modifiers
  if (isMultiple) {
    return new GraphQLNonNull(new GraphQLList(dataObjectType));
  }

  return new GraphQLNonNull(dataObjectType);
};

const dataCommandTypes = ['create', 'replace', 'patch'];
const multipleDataCommandTypes = ['create', 'replace'];

module.exports = {
  getDataArgument,
};
{'fraction_non_alphanumeric': 0.11939594148183105, 'fraction_numerical': 0.0, 'mean_word_length': 4.549738219895288, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6444129', 'n_tokens_mistral': 602, 'n_tokens_neox': 596, 'n_words': 174}