<commit_before>const _ = require('lodash');
const utils = require('./utils');
const objection = require('objection');
const graphqlRoot = require('graphql');

const jsonSchemaUtils = require('./jsonSchema');
const defaultArgFactories = require('./argFactories');

const { GraphQLObjectType, GraphQLSchema, GraphQLList } = graphqlRoot;


// Default arguments that are excluded from the relation arguments.
const OMIT_FROM_RELATION_ARGS = [
  // We cannot use `range` in the relation arguments since the relations are fetched
  // for multiple objects at a time. Limiting the result set would limit the combined
  // result, and not the individual model's relation.
  'range',
];

const GRAPHQL_META_FIELDS = [
  '__typename',
];

// GraphQL AST node types.
const KIND_FRAGMENT_SPREAD = 'FragmentSpread';
const KIND_VARIABLE = 'Variable';

class SchemaBuilder {
  constructor() {
    this.models = {};
    this.typeCache = {};
    this.filterIndex = 1;
    this.argFactories = [];
    this.enableSelectFiltering = true;
    this.defaultArgNameMap = {
      eq: 'Eq',
      gt: 'Gt',
      gte: 'Gte',
      lt: 'Lt',
      lte: 'Lte',
      like: 'Like',
      isNull: 'IsNull',
      likeNoCase: 'LikeNoCase',
      in: 'In',
      notIn: 'NotIn',
      orderBy: 'orderBy',
      orderByDesc: 'orderByDesc',
      range: 'range',
      limit: 'limit',
      offset: 'offset',
    };
  }

  model(modelClass, opt) {
    opt = opt || {};

    if (!modelClass.jsonSchema) {
      throw new Error('modelClass must have a jsonSchema');
    }

    this.models[modelClass.tableName] = {
      modelClass,
      fields: null,
      args: null,
      opt,
    };

    return this;
  }

  allModels(models) {
    models.forEach(model => this.model(model));
    return this;
  }

  defaultArgNames(defaultArgNameMap) {
    this.defaultArgNameMap = Object.assign({}, this.defaultArgNameMap, defaultArgNameMap);
    return this;
  }

  argFactory(argFactory) {
    this.argFactories.push(argFactory);
    return this;
  }

  selectFiltering(enable) {
    this.enableSelectFiltering = !!enable;
    return this;
  }

  extendWithMutations(mutations) {
    if (!(mutations instanceof GraphQLObjectType || mutations instanceof Function)) {
      throw new TypeError('mutations should be a function or an object of type GraphQLObjectType');
    }

    this.mutation = mutations;
    return this;
  }

  extendWithMiddleware(middleware) {
    if (!(middleware instanceof Function)) {
      throw new TypeError('auth middleware should be a function');
    }

    this.middleware = middleware;
    return this;
  }

  extendWithSubscriptions(subscriptions) {
    if (!(subscriptions instanceof GraphQLObjectType || subscriptions instanceof Function)) {
      throw new TypeError('subscriptions should be a function or an object of type GraphQLObjectType');
    }

    this.subscription = subscriptions;
    return this;
  }

  setBuilderOptions(options) {
    this.builderOptions = options;
    return this;
  }
<commit_msg>error text fix<commit_after>const _ = require('lodash');
const utils = require('./utils');
const objection = require('objection');
const graphqlRoot = require('graphql');

const jsonSchemaUtils = require('./jsonSchema');
const defaultArgFactories = require('./argFactories');

const { GraphQLObjectType, GraphQLSchema, GraphQLList } = graphqlRoot;


// Default arguments that are excluded from the relation arguments.
const OMIT_FROM_RELATION_ARGS = [
  // We cannot use `range` in the relation arguments since the relations are fetched
  // for multiple objects at a time. Limiting the result set would limit the combined
  // result, and not the individual model's relation.
  'range',
];

const GRAPHQL_META_FIELDS = [
  '__typename',
];

// GraphQL AST node types.
const KIND_FRAGMENT_SPREAD = 'FragmentSpread';
const KIND_VARIABLE = 'Variable';

class SchemaBuilder {
  constructor() {
    this.models = {};
    this.typeCache = {};
    this.filterIndex = 1;
    this.argFactories = [];
    this.enableSelectFiltering = true;
    this.defaultArgNameMap = {
      eq: 'Eq',
      gt: 'Gt',
      gte: 'Gte',
      lt: 'Lt',
      lte: 'Lte',
      like: 'Like',
      isNull: 'IsNull',
      likeNoCase: 'LikeNoCase',
      in: 'In',
      notIn: 'NotIn',
      orderBy: 'orderBy',
      orderByDesc: 'orderByDesc',
      range: 'range',
      limit: 'limit',
      offset: 'offset',
    };
  }

  model(modelClass, opt) {
    opt = opt || {};

    if (!modelClass.jsonSchema) {
      throw new Error('modelClass must have a jsonSchema');
    }

    this.models[modelClass.tableName] = {
      modelClass,
      fields: null,
      args: null,
      opt,
    };

    return this;
  }

  allModels(models) {
    models.forEach(model => this.model(model));
    return this;
  }

  defaultArgNames(defaultArgNameMap) {
    this.defaultArgNameMap = Object.assign({}, this.defaultArgNameMap, defaultArgNameMap);
    return this;
  }

  argFactory(argFactory) {
    this.argFactories.push(argFactory);
    return this;
  }

  selectFiltering(enable) {
    this.enableSelectFiltering = !!enable;
    return this;
  }

  extendWithMutations(mutations) {
    if (!(mutations instanceof GraphQLObjectType || mutations instanceof Function)) {
      throw new TypeError('mutations should be a function or an object of type GraphQLObjectType');
    }

    this.mutation = mutations;
    return this;
  }

  extendWithMiddleware(middleware) {
    if (!(middleware instanceof Function)) {
      throw new TypeError('middleware should be a function');
    }

    this.middleware = middleware;
    return this;
  }

  extendWithSubscriptions(subscriptions) {
    if (!(subscriptions instanceof GraphQLObjectType || subscriptions instanceof Function)) {
      throw new TypeError('subscriptions should be a function or an object of type GraphQLObjectType');
    }

    this.subscription = subscriptions;
    return this;
  }

  setBuilderOptions(options) {
    this.builderOptions = options;
    return this;
  }

{'fraction_non_alphanumeric': 0.11362879040319894, 'fraction_numerical': 0.0003332222592469177, 'mean_word_length': 3.2454031117397455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2930545', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1773, 'n_words': 477}