text: import * as autoBind from 'auto-bind';
  import { DEFAULT_SCALARS } from './scalars';
  import { toPascalCase, DeclarationBlock, buildScalars } from './utils';
  import { OperationVariablesToObject } from './variables-to-object';
  import { BaseVisitor } from './base-visitor';
  function getRootType(operation, schema) {
      switch (operation) {
          case 'query':
              return schema.getQueryType();
          case 'mutation':
              return schema.getMutationType();
          case 'subscription':
              return schema.getSubscriptionType();
      }
  }
  export class BaseDocumentsVisitor extends BaseVisitor {
      constructor(rawConfig, additionalConfig, _schema, scalars = DEFAULT_SCALARS) {
          super(rawConfig, {
              addTypename: !rawConfig.skipTypename,
              ...(additionalConfig || {}),
          }, buildScalars(_schema, scalars));
          this._schema = _schema;
          this._unnamedCounter = 1;
          autoBind(this);
          this._variablesTransfomer = new OperationVariablesToObject(this.scalars, this.convertName, this.config.namespacedImportName);
      }
      setSelectionSetHandler(handler) {
          this._selectionSetToObject = handler;
      }
      setDeclarationBlockConfig(config) {
          this._declarationBlockConfig = config;
      }
      setVariablesTransformer(variablesTransfomer) {
          this._variablesTransfomer = variablesTransfomer;
      }
      convertName(node, options) {
          const useTypesPrefix = options && typeof options.useTypesPrefix === 'boolean' ? options.useTypesPrefix : true;
          return (useTypesPrefix ? this._parsedConfig.typesPrefix : '') + this._parsedConfig.convert(node, options);
      }
      get schema() {
          return this._schema;
      }
      get addTypename() {
          return this._parsedConfig.addTypename;
      }
      handleAnonymouseOperation(node) {
          const name = node.name && node.name.value;
          if (name) {
              return this.convertName(node, {
                  useTypesPrefix: false,
              });
          }
          return this.convertName(this._unnamedCounter++ + '', {
              prefix: 'Unnamed_',
              suffix: '_',
              useTypesPrefix: false,
          });
      }
      FragmentDefinition(node) {
          const fragmentRootType = this._schema.getType(node.typeCondition.name.value);
          const selectionSet = this._selectionSetToObject.createNext(fragmentRootType, node.selectionSet);
          return new DeclarationBlock(this._declarationBlockConfig)
              .export()
              .asKind('type')
              .withName(this.convertName(node, {
              useTypesPrefix: true,
              suffix: 'Fragment',
          }))
              .withContent(selectionSet.string).string;
      }
      OperationDefinition(node) {
          const name = this.handleAnonymouseOperation(node);
          const operationRootType = getRootType(node.operation, this._schema);
          if (!operationRootType) {
              throw new Error(`Unable to find root schema type for operation type "${node.operation}"!`);
          }
          const selectionSet = this._selectionSetToObject.createNext(operationRootType, node.selectionSet);
          const visitedOperationVariables = this._variablesTransfomer.transform(node.variableDefinitions);
          const operationResult = new DeclarationBlock(this._declarationBlockConfig)
              .export()
              .asKind('type')
              .withName(this.convertName(name, {
              suffix: toPascalCase(node.operation),
          }))
              .withContent(selectionSet.string).string;
          const operationVariables = new DeclarationBlock(this._declarationBlockConfig)
              .export()
              .asKind('type')
              .withName(this.convertName(name, {
              suffix: toPascalCase(node.operation) + 'Variables',
          }))
              .withBlock(visitedOperationVariables).string;
          return [operationVariables, operationResult].filter(r => r).join('\n\n');
      }
  }
  //# sourceMappingURL=base-documents-visitor.js.map