text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.isComposeType = isComposeType;
  exports.isComposeOutputType = isComposeOutputType;
  exports.isComposeInputType = isComposeInputType;
  exports.isNamedTypeComposer = isNamedTypeComposer;
  exports.isTypeComposer = isTypeComposer;
  exports.getGraphQLType = getGraphQLType;
  exports.getComposeTypeName = getComposeTypeName;
  exports.unwrapTC = unwrapTC;
  exports.unwrapInputTC = unwrapInputTC;
  exports.unwrapOutputTC = unwrapOutputTC;
  exports.changeUnwrappedTC = changeUnwrappedTC;
  
  var _graphql = require("../graphql");
  
  var _is = require("./is");
  
  var _misc = require("./misc");
  
  var _ObjectTypeComposer = require("../ObjectTypeComposer");
  
  var _InputTypeComposer = require("../InputTypeComposer");
  
  var _ScalarTypeComposer = require("../ScalarTypeComposer");
  
  var _EnumTypeComposer = require("../EnumTypeComposer");
  
  var _InterfaceTypeComposer = require("../InterfaceTypeComposer");
  
  var _UnionTypeComposer = require("../UnionTypeComposer");
  
  var _Resolver = require("../Resolver");
  
  var _NonNullComposer = require("../NonNullComposer");
  
  var _ListComposer = require("../ListComposer");
  
  var _ThunkComposer = require("../ThunkComposer");
  
  /* eslint-disable no-use-before-define */
  function isComposeType(type) {
    return (0, _graphql.isType)(type) || Array.isArray(type) && isComposeType(type[0]) || type instanceof _ObjectTypeComposer.ObjectTypeComposer || type instanceof _InputTypeComposer.InputTypeComposer || type instanceof _InterfaceTypeComposer.InterfaceTypeComposer || type instanceof _EnumTypeComposer.EnumTypeComposer || type instanceof _UnionTypeComposer.UnionTypeComposer || type instanceof _ScalarTypeComposer.ScalarTypeComposer || type instanceof _Resolver.Resolver;
  }
  
  function isComposeOutputType(type) {
    return (0, _graphql.isOutputType)(type) || Array.isArray(type) && isComposeOutputType(type[0]) || type instanceof _ObjectTypeComposer.ObjectTypeComposer || type instanceof _InterfaceTypeComposer.InterfaceTypeComposer || type instanceof _EnumTypeComposer.EnumTypeComposer || type instanceof _UnionTypeComposer.UnionTypeComposer || type instanceof _ScalarTypeComposer.ScalarTypeComposer || type instanceof _Resolver.Resolver;
  }
  
  function isComposeInputType(type) {
    return (0, _graphql.isInputType)(type) || Array.isArray(type) && isComposeInputType(type[0]) || type instanceof _InputTypeComposer.InputTypeComposer || type instanceof _EnumTypeComposer.EnumTypeComposer || type instanceof _ScalarTypeComposer.ScalarTypeComposer;
  }
  
  function isNamedTypeComposer(type) {
    return type instanceof _ObjectTypeComposer.ObjectTypeComposer || type instanceof _InputTypeComposer.InputTypeComposer || type instanceof _ScalarTypeComposer.ScalarTypeComposer || type instanceof _EnumTypeComposer.EnumTypeComposer || type instanceof _InterfaceTypeComposer.InterfaceTypeComposer || type instanceof _UnionTypeComposer.UnionTypeComposer;
  }
  
  function isTypeComposer(type) {
    return isNamedTypeComposer(type) || type instanceof _ListComposer.ListComposer || type instanceof _NonNullComposer.NonNullComposer || type instanceof _ThunkComposer.ThunkComposer;
  }
  
  function getGraphQLType(anyType) {
    let type = anyType; // extract type from ObjectTypeComposer, InputTypeComposer, EnumTypeComposer and Resolver
  
    if (type && (0, _is.isFunction)(type.getType)) {
      type = type.getType();
    }
  
    if (!(0, _graphql.isType)(type)) {
      throw new Error(`You provide incorrect type for 'getGraphQLType' method: ${(0, _misc.inspect)(type)}`);
    }
  
    return type;
  }
  
  function getComposeTypeName(type) {
    if (typeof type === 'string') {
      if (/^[_a-zA-Z][_a-zA-Z0-9]*$/.test(type)) {
        // single type name
        return type;
      } else {
        // parse type name from `type Name { f: Int }`
        const docNode = (0, _graphql.parse)(type);
  
        if (docNode.definitions[0] && docNode.definitions[0].name && typeof docNode.definitions[0].name.value === 'string') {
          return docNode.definitions[0].name.value;
        }
      }
  
      throw new Error(`Cannot get type name from string: ${(0, _misc.inspect)(type)}`);
    } else if ((0, _is.isFunction)(type)) {
      return getComposeTypeName(type());
    } else {
      try {
        const gqlType = getGraphQLType(type);
  
        if (typeof gqlType.name === 'string') {
          return gqlType.name;
        }
      } catch (e) {
        throw new Error(`Cannot get type name from ${(0, _misc.inspect)(type)}`);
      }
    }
  
    throw new Error(`Cannot get type name from ${(0, _misc.inspect)(type)}`);
  }
  
  function unwrapTC(anyTC) {
    if (anyTC instanceof _NonNullComposer.NonNullComposer || anyTC instanceof _ListComposer.ListComposer || anyTC instanceof _ThunkComposer.ThunkComposer) {
      const unwrappedTC = anyTC.getUnwrappedTC();
      return unwrapTC(unwrappedTC);
    }
  
    return anyTC;
  }
  
  function unwrapInputTC(inputTC) {
    return unwrapTC(inputTC);
  }
  
  function unwrapOutputTC(outputTC) {
    return unwrapTC(outputTC);
  }
  
  function changeUnwrappedTC(anyTC, cb) {
    let tc = anyTC;
    const wrappers = [];
  
    while (tc instanceof _ListComposer.ListComposer || tc instanceof _NonNullComposer.NonNullComposer || tc instanceof _ThunkComposer.ThunkComposer) {
      if (tc instanceof _ThunkComposer.ThunkComposer) {
        tc = tc.getUnwrappedTC();
      } else {
        wrappers.unshift(tc.constructor);
        tc = tc.ofType;
      }
    } // call callback for TC
  
  
    tc = cb(tc);
  
    if (tc) {
      // wrap TypeComposer back
      tc = wrappers.reduce((type, Wrapper) => new Wrapper(type), tc);
    }
  
    return tc;
  }