<commit_before>import { parse } from 'graphql/language';
import { addDefinition, createTypeFetcher } from 'olymp-graphql/server';
import { get } from 'lodash';

const fetch = createTypeFetcher(
  (node, value) =>
    node.kind !== 'NamedType' && node.name && node.name.value === value,
);

export default (ast, node) => {
  const getArgument = field => {
    // if field ist required
    if (get(field, 'type.kind') === 'NonNullType') {
      field.type = get(field, 'type.type');
    }

    const value = get(field, 'type.type.name.value');
    if (field.type.kind === 'ListType' && value && value === 'String') {
      addDefinition(
        ast,
        parse(`
        input ${value}Query {
          in: [${value}],
          nin: [${value}],
          null: Boolean
        }
      `).definitions[0],
      );
      return `${field.name.value}: ${value}Query`;
    }
    if (!field.type.name) {
      return null;
    }
    const fieldType = fetch(ast, field.type.name.value);
    if (['Date', 'DateTime'].includes(field.type.name.value)) {
      addDefinition(
        ast,
        parse(`
        input DateQuery {
          eq: DateTime,<commit_msg>small fix<commit_after>import { parse } from 'graphql/language';
import { addDefinition, createTypeFetcher } from 'olymp-graphql/server';
import { get } from 'lodash';

const fetch = createTypeFetcher(
  (node, value) =>
    node.kind !== 'NamedType' && node.name && node.name.value === value,
);

export default (ast, node) => {
  const getArgument = f => {
    const field = { ...f }; // DO NOT CHANGE!!!

    // if field ist required
    if (get(field, 'type.kind') === 'NonNullType') {
      field.type = get(field, 'type.type');
    }

    const value = get(field, 'type.type.name.value');
    if (field.type.kind === 'ListType' && value && value === 'String') {
      addDefinition(
        ast,
        parse(`
        input ${value}Query {
          in: [${value}],
          nin: [${value}],
          null: Boolean
        }
      `).definitions[0],
      );
      return `${field.name.value}: ${value}Query`;
    }
    if (!field.type.name) {
      return null;
    }
    const fieldType = fetch(ast, field.type.name.value);
    if (['Date', 'DateTime'].includes(field.type.name.value)) {
      addDefinition(
        ast,
        parse(`
        input DateQuery {
          eq: DateTime,
{'fraction_non_alphanumeric': 0.17225286380992788, 'fraction_numerical': 0.0008485362749257531, 'mean_word_length': 2.3685714285714288, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '132464', 'n_tokens_mistral': 743, 'n_tokens_neox': 744, 'n_words': 174}