text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  var graphql_1 = require("graphql");
  function extractFragmentReplacements(resolvers) {
      var fragmentReplacements = {};
      for (var typeName in resolvers) {
          var fieldResolvers = resolvers[typeName];
          for (var fieldName in fieldResolvers) {
              var fieldResolver = fieldResolvers[fieldName];
              if (typeof fieldResolver === 'object' && 'fragment' in fieldResolver) {
                  // parse & set fragment
                  var fragment = parseFragmentToInlineFragment(fieldResolver.fragment);
                  var remoteTypeName = fragment.typeCondition.name.value;
                  // lazy init type level for fragmentReplacements
                  fragmentReplacements[remoteTypeName] = fragmentReplacements[remoteTypeName] || {};
                  fragmentReplacements[remoteTypeName][fieldName] = fragment;
              }
          }
      }
      return fragmentReplacements;
  }
  exports.extractFragmentReplacements = extractFragmentReplacements;
  function parseFragmentToInlineFragment(definitions) {
      var document = graphql_1.parse(definitions);
      for (var _i = 0, _a = document.definitions; _i < _a.length; _i++) {
          var definition = _a[_i];
          if (definition.kind === graphql_1.Kind.FRAGMENT_DEFINITION) {
              return {
                  kind: graphql_1.Kind.INLINE_FRAGMENT,
                  typeCondition: definition.typeCondition,
                  selectionSet: definition.selectionSet,
              };
          }
      }
      throw new Error('Could not parse fragment');
  }
  //# sourceMappingURL=fragmentReplacements.js.map