<commit_before>/* @flow strict */
/* eslint-disable class-methods-use-this */

import deprecate from './utils/deprecate';
import { TypeStorage } from './TypeStorage';
import { TypeMapper } from './TypeMapper';
import { ObjectTypeComposer, type ObjectTypeComposerDefinition } from './ObjectTypeComposer';
import { InputTypeComposer, type InputTypeComposerDefinition } from './InputTypeComposer';
import { ScalarTypeComposer, type ScalarTypeComposerDefinition } from './ScalarTypeComposer';
import { EnumTypeComposer, type EnumTypeComposerDefinition } from './EnumTypeComposer';
import {
  InterfaceTypeComposer,
  type InterfaceTypeComposerDefinition,
} from './InterfaceTypeComposer';
import { UnionTypeComposer, type UnionTypeComposerDefinition } from './UnionTypeComposer';
import { ListComposer } from './ListComposer';
import { NonNullComposer } from './NonNullComposer';
import { ThunkComposer } from './ThunkComposer';
import { Resolver, type ResolverDefinition } from './Resolver';
import { isFunction } from './utils/is';
import { inspect, forEachKey } from './utils/misc';
import {
  getGraphQLType,
  isTypeComposer,
  isNamedTypeComposer,
  isComposeType,
  getComposeTypeName,
  type AnyType,
  type NamedTypeComposer,
} from './utils/typeHelpers';
import {
  GraphQLSchema,
  GraphQLObjectType,
  GraphQLInputObjectType,
  GraphQLInterfaceType,
  GraphQLUnionType,
  GraphQLEnumType,
  GraphQLDirective,
  GraphQLSkipDirective,
  GraphQLIncludeDirective,
  GraphQLDeprecatedDirective,
  GraphQLScalarType,
  GraphQLNonNull,
  GraphQLList,
  type GraphQLType,
  type GraphQLNamedType,
  type SchemaDefinitionNode,
  type GraphQLResolveInfo,
} from './graphql';
import DefaultDirective from './directive/default';

type ExtraSchemaConfig = {
  types?: GraphQLNamedType[] | null,
  directives?: GraphQLDirective[] | null,
  astNode?: SchemaDefinitionNode | null,
};

type GraphQLToolsResolveMethods<TContext> = {
  [typeName: string]: {
    [fieldName: string]: (
      source: any,
      args: Object,
      context: TContext,
      info: GraphQLResolveInfo
    ) => any,
  },
};

export const BUILT_IN_DIRECTIVES = [
  GraphQLSkipDirective,
  GraphQLIncludeDirective,
  GraphQLDeprecatedDirective,
  DefaultDirective,
];

export class SchemaComposer<TContext> extends TypeStorage<any, NamedTypeComposer<TContext>> {
  typeMapper: TypeMapper<TContext>;
  _schemaMustHaveTypes: Array<AnyType<TContext>> = [];
  _directives: Array<GraphQLDirective> = BUILT_IN_DIRECTIVES;

  constructor(schema?: GraphQLSchema): SchemaComposer<TContext> {
    super();
    this.typeMapper = new TypeMapper(this);

    if (schema instanceof GraphQLSchema) {
      forEachKey(schema.getTypeMap(), (v, k) => {
        // skip internal types
        if (k.startsWith('__')) return;
        // under the hood adds types to type storage
        this.typeMapper.convertGraphQLTypeToComposer(v);
      });
      const q = schema.getQueryType();
      if (q) this.set('Query', this.get(q));
      const m = schema.getMutationType();
      if (m) this.set('Mutation', this.get(m));<commit_msg>fix: don't mutate built-in directives<commit_after>/* @flow strict */
/* eslint-disable class-methods-use-this */

import deprecate from './utils/deprecate';
import { TypeStorage } from './TypeStorage';
import { TypeMapper } from './TypeMapper';
import { ObjectTypeComposer, type ObjectTypeComposerDefinition } from './ObjectTypeComposer';
import { InputTypeComposer, type InputTypeComposerDefinition } from './InputTypeComposer';
import { ScalarTypeComposer, type ScalarTypeComposerDefinition } from './ScalarTypeComposer';
import { EnumTypeComposer, type EnumTypeComposerDefinition } from './EnumTypeComposer';
import {
  InterfaceTypeComposer,
  type InterfaceTypeComposerDefinition,
} from './InterfaceTypeComposer';
import { UnionTypeComposer, type UnionTypeComposerDefinition } from './UnionTypeComposer';
import { ListComposer } from './ListComposer';
import { NonNullComposer } from './NonNullComposer';
import { ThunkComposer } from './ThunkComposer';
import { Resolver, type ResolverDefinition } from './Resolver';
import { isFunction } from './utils/is';
import { inspect, forEachKey } from './utils/misc';
import {
  getGraphQLType,
  isTypeComposer,
  isNamedTypeComposer,
  isComposeType,
  getComposeTypeName,
  type AnyType,
  type NamedTypeComposer,
} from './utils/typeHelpers';
import {
  GraphQLSchema,
  GraphQLObjectType,
  GraphQLInputObjectType,
  GraphQLInterfaceType,
  GraphQLUnionType,
  GraphQLEnumType,
  GraphQLDirective,
  GraphQLSkipDirective,
  GraphQLIncludeDirective,
  GraphQLDeprecatedDirective,
  GraphQLScalarType,
  GraphQLNonNull,
  GraphQLList,
  type GraphQLType,
  type GraphQLNamedType,
  type SchemaDefinitionNode,
  type GraphQLResolveInfo,
} from './graphql';
import DefaultDirective from './directive/default';

type ExtraSchemaConfig = {
  types?: GraphQLNamedType[] | null,
  directives?: GraphQLDirective[] | null,
  astNode?: SchemaDefinitionNode | null,
};

type GraphQLToolsResolveMethods<TContext> = {
  [typeName: string]: {
    [fieldName: string]: (
      source: any,
      args: Object,
      context: TContext,
      info: GraphQLResolveInfo
    ) => any,
  },
};

export const BUILT_IN_DIRECTIVES = [
  GraphQLSkipDirective,
  GraphQLIncludeDirective,
  GraphQLDeprecatedDirective,
  DefaultDirective,
];

export class SchemaComposer<TContext> extends TypeStorage<any, NamedTypeComposer<TContext>> {
  typeMapper: TypeMapper<TContext>;
  _schemaMustHaveTypes: Array<AnyType<TContext>> = [];
  _directives: Array<GraphQLDirective> = [...BUILT_IN_DIRECTIVES];

  constructor(schema?: GraphQLSchema): SchemaComposer<TContext> {
    super();
    this.typeMapper = new TypeMapper(this);

    if (schema instanceof GraphQLSchema) {
      forEachKey(schema.getTypeMap(), (v, k) => {
        // skip internal types
        if (k.startsWith('__')) return;
        // under the hood adds types to type storage
        this.typeMapper.convertGraphQLTypeToComposer(v);
      });
      const q = schema.getQueryType();
      if (q) this.set('Query', this.get(q));
      const m = schema.getMutationType();
      if (m) this.set('Mutation', this.get(m));
{'fraction_non_alphanumeric': 0.11231590872309435, 'fraction_numerical': 0.0, 'mean_word_length': 4.727525486561631, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, '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': '6776188', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1851, 'n_words': 421}