text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  function isScalarValue(value) {
      return ['StringValue', 'BooleanValue', 'EnumValue'].indexOf(value.kind) > -1;
  }
  exports.isScalarValue = isScalarValue;
  function isNumberValue(value) {
      return ['IntValue', 'FloatValue'].indexOf(value.kind) > -1;
  }
  exports.isNumberValue = isNumberValue;
  function isStringValue(value) {
      return value.kind === 'StringValue';
  }
  function isBooleanValue(value) {
      return value.kind === 'BooleanValue';
  }
  function isIntValue(value) {
      return value.kind === 'IntValue';
  }
  function isFloatValue(value) {
      return value.kind === 'FloatValue';
  }
  function isVariable(value) {
      return value.kind === 'Variable';
  }
  function isObjectValue(value) {
      return value.kind === 'ObjectValue';
  }
  function isListValue(value) {
      return value.kind === 'ListValue';
  }
  function isEnumValue(value) {
      return value.kind === 'EnumValue';
  }
  function valueToObjectRepresentation(argObj, name, value, variables) {
      if (isIntValue(value) || isFloatValue(value)) {
          argObj[name.value] = Number(value.value);
      }
      else if (isBooleanValue(value) || isStringValue(value)) {
          argObj[name.value] = value.value;
      }
      else if (isObjectValue(value)) {
          var nestedArgObj_1 = {};
          value.fields.map(function (obj) {
              return valueToObjectRepresentation(nestedArgObj_1, obj.name, obj.value, variables);
          });
          argObj[name.value] = nestedArgObj_1;
      }
      else if (isVariable(value)) {
          var variableValue = (variables || {})[value.name.value];
          argObj[name.value] = variableValue;
      }
      else if (isListValue(value)) {
          argObj[name.value] = value.values.map(function (listValue) {
              var nestedArgArrayObj = {};
              valueToObjectRepresentation(nestedArgArrayObj, name, listValue, variables);
              return nestedArgArrayObj[name.value];
          });
      }
      else if (isEnumValue(value)) {
          argObj[name.value] = value.value;
      }
      else {
          throw new Error("The inline argument \"" + name.value + "\" of kind \"" + value
              .kind + "\" is not supported.\n                    Use variables instead of inline arguments to overcome this limitation.");
      }
  }
  exports.valueToObjectRepresentation = valueToObjectRepresentation;
  function storeKeyNameFromField(field, variables) {
      var directivesObj = null;
      if (field.directives) {
          directivesObj = {};
          field.directives.forEach(function (directive) {
              directivesObj[directive.name.value] = {};
              if (directive.arguments) {
                  directive.arguments.forEach(function (_a) {
                      var name = _a.name, value = _a.value;
                      return valueToObjectRepresentation(directivesObj[directive.name.value], name, value, variables);
                  });
              }
          });
      }
      var argObj = null;
      if (field.arguments && field.arguments.length) {
          argObj = {};
          field.arguments.forEach(function (_a) {
              var name = _a.name, value = _a.value;
              return valueToObjectRepresentation(argObj, name, value, variables);
          });
      }
      return getStoreKeyName(field.name.value, argObj, directivesObj);
  }
  exports.storeKeyNameFromField = storeKeyNameFromField;
  function getStoreKeyName(fieldName, args, directives) {
      if (directives &&
          directives['connection'] &&
          directives['connection']['key']) {
          if (directives['connection']['filter'] &&
              directives['connection']['filter'].length > 0) {
              var filterKeys = directives['connection']['filter']
                  ? directives['connection']['filter']
                  : [];
              filterKeys.sort();
              var queryArgs_1 = args;
              var filteredArgs_1 = {};
              filterKeys.forEach(function (key) {
                  filteredArgs_1[key] = queryArgs_1[key];
              });
              return directives['connection']['key'] + "(" + JSON.stringify(filteredArgs_1) + ")";
          }
          else {
              return directives['connection']['key'];
          }
      }
      if (args) {
          var stringifiedArgs = JSON.stringify(args);
          return fieldName + "(" + stringifiedArgs + ")";
      }
      return fieldName;
  }
  exports.getStoreKeyName = getStoreKeyName;
  function argumentsObjectFromField(field, variables) {
      if (field.arguments && field.arguments.length) {
          var argObj_1 = {};
          field.arguments.forEach(function (_a) {
              var name = _a.name, value = _a.value;
              return valueToObjectRepresentation(argObj_1, name, value, variables);
          });
          return argObj_1;
      }
      return null;
  }
  exports.argumentsObjectFromField = argumentsObjectFromField;
  function resultKeyNameFromField(field) {
      return field.alias ? field.alias.value : field.name.value;
  }
  exports.resultKeyNameFromField = resultKeyNameFromField;
  function isField(selection) {
      return selection.kind === 'Field';
  }
  exports.isField = isField;
  function isInlineFragment(selection) {
      return selection.kind === 'InlineFragment';
  }
  exports.isInlineFragment = isInlineFragment;
  function isIdValue(idObject) {
      return idObject && idObject.type === 'id';
  }
  exports.isIdValue = isIdValue;
  function toIdValue(id, generated) {
      if (generated === void 0) { generated = false; }
      return {
          type: 'id',
          id: id,
          generated: generated,
      };
  }
  exports.toIdValue = toIdValue;
  function isJsonValue(jsonObject) {
      return (jsonObject != null &&
          typeof jsonObject === 'object' &&
          jsonObject.type === 'json');
  }
  exports.isJsonValue = isJsonValue;
  function defaultValueFromVariable(node) {
      throw new Error("Variable nodes are not supported by valueFromNode");
  }
  function valueFromNode(node, onVariable) {
      if (onVariable === void 0) { onVariable = defaultValueFromVariable; }
      switch (node.kind) {
          case 'Variable':
              return onVariable(node);
          case 'NullValue':
              return null;
          case 'IntValue':
              return parseInt(node.value);
          case 'FloatValue':
              return parseFloat(node.value);
          case 'ListValue':
              return node.values.map(function (v) { return valueFromNode(v, onVariable); });
          case 'ObjectValue': {
              var value = {};
              for (var _i = 0, _a = node.fields; _i < _a.length; _i++) {
                  var field = _a[_i];
                  value[field.name.value] = valueFromNode(field.value, onVariable);
              }
              return value;
          }
          default:
              return node.value;
      }
  }
  exports.valueFromNode = valueFromNode;
  //# sourceMappingURL=storeUtils.js.map