Socket
Socket
Sign inDemoInstall

apollo-utilities

Package Overview
Dependencies
Maintainers
4
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-utilities - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

1731

lib/bundle.cjs.js

@@ -1,1007 +0,1128 @@

'use strict';
exports.__esModule = true;
exports.addTypenameToDocument = addTypenameToDocument;
exports.argumentsObjectFromField = argumentsObjectFromField;
exports.assign = assign;
exports.buildQueryFromSelectionSet = buildQueryFromSelectionSet;
exports.checkDocument = checkDocument;
exports.cloneDeep = cloneDeep;
exports.createFragmentMap = createFragmentMap;
exports.getDefaultValues = getDefaultValues;
exports.getDirectiveInfoFromField = getDirectiveInfoFromField;
exports.getDirectiveNames = getDirectiveNames;
exports.getDirectivesFromDocument = getDirectivesFromDocument;
exports.getEnv = getEnv;
exports.getFragmentDefinition = getFragmentDefinition;
exports.getFragmentDefinitions = getFragmentDefinitions;
exports.getFragmentQueryDocument = getFragmentQueryDocument;
exports.getInclusionDirectives = getInclusionDirectives;
exports.getMainDefinition = getMainDefinition;
exports.getMutationDefinition = getMutationDefinition;
exports.getOperationDefinition = getOperationDefinition;
exports.getOperationDefinitionOrDie = getOperationDefinitionOrDie;
exports.getOperationName = getOperationName;
exports.getQueryDefinition = getQueryDefinition;
exports.getStoreKeyName = getStoreKeyName;
exports.graphQLResultHasError = graphQLResultHasError;
exports.hasClientExports = hasClientExports;
exports.hasDirectives = hasDirectives;
exports.isDevelopment = isDevelopment;
exports.isEnv = isEnv;
exports.isEqual = isEqual;
exports.isField = isField;
exports.isIdValue = isIdValue;
exports.isInlineFragment = isInlineFragment;
exports.isJsonValue = isJsonValue;
exports.isNumberValue = isNumberValue;
exports.isProduction = isProduction;
exports.isScalarValue = isScalarValue;
exports.isTest = isTest;
exports.maybeDeepFreeze = maybeDeepFreeze;
exports.mergeDeep = mergeDeep;
exports.mergeDeepArray = mergeDeepArray;
exports.removeArgumentsFromDocument = removeArgumentsFromDocument;
exports.removeClientSetsFromDocument = removeClientSetsFromDocument;
exports.removeConnectionDirectiveFromDocument = removeConnectionDirectiveFromDocument;
exports.removeDirectivesFromDocument = removeDirectivesFromDocument;
exports.removeFragmentSpreadFromDocument = removeFragmentSpreadFromDocument;
exports.resultKeyNameFromField = resultKeyNameFromField;
exports.shouldInclude = shouldInclude;
exports.storeKeyNameFromField = storeKeyNameFromField;
exports.stripSymbols = stripSymbols;
exports.toIdValue = toIdValue;
exports.tryFunctionOrLogError = tryFunctionOrLogError;
exports.valueFromNode = valueFromNode;
exports.valueToObjectRepresentation = valueToObjectRepresentation;
exports.variablesInOperation = variablesInOperation;
exports.warnOnceInDevelopment = warnOnceInDevelopment;
exports.canUseWeakMap = void 0;
Object.defineProperty(exports, '__esModule', { value: true });
var _visitor = require("graphql/language/visitor");
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var _tsInvariant = require("ts-invariant");
var visitor = require('graphql/language/visitor');
var tsInvariant = require('ts-invariant');
var tslib = require('tslib');
var stringify = _interopDefault(require('fast-json-stable-stringify'));
var _tslib = require("tslib");
var _fastJsonStableStringify = _interopRequireDefault(require("fast-json-stable-stringify"));
var _lodash = _interopRequireDefault(require("lodash.isequal"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isScalarValue(value) {
return ['StringValue', 'BooleanValue', 'EnumValue'].indexOf(value.kind) > -1;
return ['StringValue', 'BooleanValue', 'EnumValue'].indexOf(value.kind) > -1;
}
function isNumberValue(value) {
return ['IntValue', 'FloatValue'].indexOf(value.kind) > -1;
return ['IntValue', 'FloatValue'].indexOf(value.kind) > -1;
}
function isStringValue(value) {
return value.kind === 'StringValue';
return value.kind === 'StringValue';
}
function isBooleanValue(value) {
return value.kind === 'BooleanValue';
return value.kind === 'BooleanValue';
}
function isIntValue(value) {
return value.kind === 'IntValue';
return value.kind === 'IntValue';
}
function isFloatValue(value) {
return value.kind === 'FloatValue';
return value.kind === 'FloatValue';
}
function isVariable(value) {
return value.kind === 'Variable';
return value.kind === 'Variable';
}
function isObjectValue(value) {
return value.kind === 'ObjectValue';
return value.kind === 'ObjectValue';
}
function isListValue(value) {
return value.kind === 'ListValue';
return value.kind === 'ListValue';
}
function isEnumValue(value) {
return value.kind === 'EnumValue';
return value.kind === 'EnumValue';
}
function isNullValue(value) {
return value.kind === 'NullValue';
return value.kind === 'NullValue';
}
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 if (isNullValue(value)) {
argObj[name.value] = null;
}
else {
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(17) : new tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
'is not supported. Use variables instead of inline arguments to ' +
'overcome this limitation.');
}
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 if (isNullValue(value)) {
argObj[name.value] = null;
} else {
throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(17) : new _tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" + 'is not supported. Use variables instead of inline arguments to ' + 'overcome this limitation.');
}
}
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 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);
}
});
}
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);
}
var KNOWN_DIRECTIVES = [
'connection',
'include',
'skip',
'client',
'rest',
'export',
];
var KNOWN_DIRECTIVES = ['connection', 'include', 'skip', 'client', 'rest', 'export'];
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 (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'];
}
var completeFieldName = fieldName;
if (args) {
var stringifiedArgs = stringify(args);
completeFieldName += "(" + stringifiedArgs + ")";
}
if (directives) {
Object.keys(directives).forEach(function (key) {
if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
return;
if (directives[key] && Object.keys(directives[key]).length) {
completeFieldName += "@" + key + "(" + JSON.stringify(directives[key]) + ")";
}
else {
completeFieldName += "@" + key;
}
});
}
return completeFieldName;
}
var completeFieldName = fieldName;
if (args) {
var stringifiedArgs = (0, _fastJsonStableStringify.default)(args);
completeFieldName += "(" + stringifiedArgs + ")";
}
if (directives) {
Object.keys(directives).forEach(function (key) {
if (KNOWN_DIRECTIVES.indexOf(key) !== -1) return;
if (directives[key] && Object.keys(directives[key]).length) {
completeFieldName += "@" + key + "(" + JSON.stringify(directives[key]) + ")";
} else {
completeFieldName += "@" + key;
}
});
}
return completeFieldName;
}
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;
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;
}
function resultKeyNameFromField(field) {
return field.alias ? field.alias.value : field.name.value;
return field.alias ? field.alias.value : field.name.value;
}
function isField(selection) {
return selection.kind === 'Field';
return selection.kind === 'Field';
}
function isInlineFragment(selection) {
return selection.kind === 'InlineFragment';
return selection.kind === 'InlineFragment';
}
function isIdValue(idObject) {
return idObject &&
idObject.type === 'id' &&
typeof idObject.generated === 'boolean';
return idObject && idObject.type === 'id' && typeof idObject.generated === 'boolean';
}
function toIdValue(idConfig, generated) {
if (generated === void 0) { generated = false; }
return tslib.__assign({ type: 'id', generated: generated }, (typeof idConfig === 'string'
? { id: idConfig, typename: undefined }
: idConfig));
if (generated === void 0) {
generated = false;
}
return (0, _tslib.__assign)({
type: 'id',
generated: generated
}, typeof idConfig === 'string' ? {
id: idConfig,
typename: undefined
} : idConfig);
}
function isJsonValue(jsonObject) {
return (jsonObject != null &&
typeof jsonObject === 'object' &&
jsonObject.type === 'json');
return jsonObject != null && typeof jsonObject === 'object' && jsonObject.type === 'json';
}
function defaultValueFromVariable(node) {
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(18) : new tsInvariant.InvariantError("Variable nodes are not supported by valueFromNode");
throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(18) : new _tsInvariant.InvariantError("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, 10);
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;
if (onVariable === void 0) {
onVariable = defaultValueFromVariable;
}
switch (node.kind) {
case 'Variable':
return onVariable(node);
case 'NullValue':
return null;
case 'IntValue':
return parseInt(node.value, 10);
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);
}
default:
return node.value;
}
return value;
}
default:
return node.value;
}
}
function getDirectiveInfoFromField(field, variables) {
if (field.directives && field.directives.length) {
var directiveObj_1 = {};
field.directives.forEach(function (directive) {
directiveObj_1[directive.name.value] = argumentsObjectFromField(directive, variables);
});
return directiveObj_1;
}
return null;
if (field.directives && field.directives.length) {
var directiveObj_1 = {};
field.directives.forEach(function (directive) {
directiveObj_1[directive.name.value] = argumentsObjectFromField(directive, variables);
});
return directiveObj_1;
}
return null;
}
function shouldInclude(selection, variables) {
if (variables === void 0) { variables = {}; }
return getInclusionDirectives(selection.directives).every(function (_a) {
var directive = _a.directive, ifArgument = _a.ifArgument;
var evaledValue = false;
if (ifArgument.value.kind === 'Variable') {
evaledValue = variables[ifArgument.value.name.value];
process.env.NODE_ENV === "production" ? tsInvariant.invariant(evaledValue !== void 0, 1) : tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.");
}
else {
evaledValue = ifArgument.value.value;
}
return directive.name.value === 'skip' ? !evaledValue : evaledValue;
});
if (variables === void 0) {
variables = {};
}
return getInclusionDirectives(selection.directives).every(function (_a) {
var directive = _a.directive,
ifArgument = _a.ifArgument;
var evaledValue = false;
if (ifArgument.value.kind === 'Variable') {
evaledValue = variables[ifArgument.value.name.value];
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(evaledValue !== void 0, 1) : (0, _tsInvariant.invariant)(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.");
} else {
evaledValue = ifArgument.value.value;
}
return directive.name.value === 'skip' ? !evaledValue : evaledValue;
});
}
function getDirectiveNames(doc) {
var names = [];
visitor.visit(doc, {
Directive: function (node) {
names.push(node.name.value);
},
});
return names;
var names = [];
(0, _visitor.visit)(doc, {
Directive: function (node) {
names.push(node.name.value);
}
});
return names;
}
function hasDirectives(names, doc) {
return getDirectiveNames(doc).some(function (name) { return names.indexOf(name) > -1; });
return getDirectiveNames(doc).some(function (name) {
return names.indexOf(name) > -1;
});
}
function hasClientExports(document) {
return (document &&
hasDirectives(['client'], document) &&
hasDirectives(['export'], document));
return document && hasDirectives(['client'], document) && hasDirectives(['export'], document);
}
function isInclusionDirective(_a) {
var value = _a.name.value;
return value === 'skip' || value === 'include';
var value = _a.name.value;
return value === 'skip' || value === 'include';
}
function getInclusionDirectives(directives) {
return directives ? directives.filter(isInclusionDirective).map(function (directive) {
var directiveArguments = directive.arguments;
var directiveName = directive.name.value;
process.env.NODE_ENV === "production" ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 2) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
var ifArgument = directiveArguments[0];
process.env.NODE_ENV === "production" ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 3) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.");
var ifValue = ifArgument.value;
process.env.NODE_ENV === "production" ? tsInvariant.invariant(ifValue &&
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 4) : tsInvariant.invariant(ifValue &&
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.");
return { directive: directive, ifArgument: ifArgument };
}) : [];
return directives ? directives.filter(isInclusionDirective).map(function (directive) {
var directiveArguments = directive.arguments;
var directiveName = directive.name.value;
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(directiveArguments && directiveArguments.length === 1, 2) : (0, _tsInvariant.invariant)(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
var ifArgument = directiveArguments[0];
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(ifArgument.name && ifArgument.name.value === 'if', 3) : (0, _tsInvariant.invariant)(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.");
var ifValue = ifArgument.value;
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(ifValue && (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 4) : (0, _tsInvariant.invariant)(ifValue && (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.");
return {
directive: directive,
ifArgument: ifArgument
};
}) : [];
}
function getFragmentQueryDocument(document, fragmentName) {
var actualFragmentName = fragmentName;
var fragments = [];
document.definitions.forEach(function (definition) {
if (definition.kind === 'OperationDefinition') {
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(5) : new tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
'No operations are allowed when using a fragment as a query. Only fragments are allowed.');
}
if (definition.kind === 'FragmentDefinition') {
fragments.push(definition);
}
});
if (typeof actualFragmentName === 'undefined') {
process.env.NODE_ENV === "production" ? tsInvariant.invariant(fragments.length === 1, 6) : tsInvariant.invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
actualFragmentName = fragments[0].name.value;
var actualFragmentName = fragmentName;
var fragments = [];
document.definitions.forEach(function (definition) {
if (definition.kind === 'OperationDefinition') {
throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(5) : new _tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " + 'No operations are allowed when using a fragment as a query. Only fragments are allowed.');
}
var query = tslib.__assign({}, document, { definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'FragmentSpread',
name: {
kind: 'Name',
value: actualFragmentName,
},
},
],
},
}
].concat(document.definitions) });
return query;
if (definition.kind === 'FragmentDefinition') {
fragments.push(definition);
}
});
if (typeof actualFragmentName === 'undefined') {
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(fragments.length === 1, 6) : (0, _tsInvariant.invariant)(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
actualFragmentName = fragments[0].name.value;
}
var query = (0, _tslib.__assign)({}, document, {
definitions: [{
kind: 'OperationDefinition',
operation: 'query',
selectionSet: {
kind: 'SelectionSet',
selections: [{
kind: 'FragmentSpread',
name: {
kind: 'Name',
value: actualFragmentName
}
}]
}
}].concat(document.definitions)
});
return query;
}
function assign(target) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
}
sources.forEach(function (source) {
if (typeof source === 'undefined' || source === null) {
return;
}
sources.forEach(function (source) {
if (typeof source === 'undefined' || source === null) {
return;
}
Object.keys(source).forEach(function (key) {
target[key] = source[key];
});
Object.keys(source).forEach(function (key) {
target[key] = source[key];
});
return target;
});
return target;
}
function getMutationDefinition(doc) {
checkDocument(doc);
var mutationDef = doc.definitions.filter(function (definition) {
return definition.kind === 'OperationDefinition' &&
definition.operation === 'mutation';
})[0];
process.env.NODE_ENV === "production" ? tsInvariant.invariant(mutationDef, 7) : tsInvariant.invariant(mutationDef, 'Must contain a mutation definition.');
return mutationDef;
checkDocument(doc);
var mutationDef = doc.definitions.filter(function (definition) {
return definition.kind === 'OperationDefinition' && definition.operation === 'mutation';
})[0];
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(mutationDef, 7) : (0, _tsInvariant.invariant)(mutationDef, 'Must contain a mutation definition.');
return mutationDef;
}
function checkDocument(doc) {
process.env.NODE_ENV === "production" ? tsInvariant.invariant(doc && doc.kind === 'Document', 8) : tsInvariant.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
var operations = doc.definitions
.filter(function (d) { return d.kind !== 'FragmentDefinition'; })
.map(function (definition) {
if (definition.kind !== 'OperationDefinition') {
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(9) : new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
}
return definition;
});
process.env.NODE_ENV === "production" ? tsInvariant.invariant(operations.length <= 1, 10) : tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations");
return doc;
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(doc && doc.kind === 'Document', 8) : (0, _tsInvariant.invariant)(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
var operations = doc.definitions.filter(function (d) {
return d.kind !== 'FragmentDefinition';
}).map(function (definition) {
if (definition.kind !== 'OperationDefinition') {
throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(9) : new _tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
}
return definition;
});
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(operations.length <= 1, 10) : (0, _tsInvariant.invariant)(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations");
return doc;
}
function getOperationDefinition(doc) {
checkDocument(doc);
return doc.definitions.filter(function (definition) { return definition.kind === 'OperationDefinition'; })[0];
checkDocument(doc);
return doc.definitions.filter(function (definition) {
return definition.kind === 'OperationDefinition';
})[0];
}
function getOperationDefinitionOrDie(document) {
var def = getOperationDefinition(document);
process.env.NODE_ENV === "production" ? tsInvariant.invariant(def, 11) : tsInvariant.invariant(def, "GraphQL document is missing an operation");
return def;
var def = getOperationDefinition(document);
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(def, 11) : (0, _tsInvariant.invariant)(def, "GraphQL document is missing an operation");
return def;
}
function getOperationName(doc) {
return (doc.definitions
.filter(function (definition) {
return definition.kind === 'OperationDefinition' && definition.name;
})
.map(function (x) { return x.name.value; })[0] || null);
return doc.definitions.filter(function (definition) {
return definition.kind === 'OperationDefinition' && definition.name;
}).map(function (x) {
return x.name.value;
})[0] || null;
}
function getFragmentDefinitions(doc) {
return doc.definitions.filter(function (definition) { return definition.kind === 'FragmentDefinition'; });
return doc.definitions.filter(function (definition) {
return definition.kind === 'FragmentDefinition';
});
}
function getQueryDefinition(doc) {
var queryDef = getOperationDefinition(doc);
process.env.NODE_ENV === "production" ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 12) : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.');
return queryDef;
var queryDef = getOperationDefinition(doc);
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(queryDef && queryDef.operation === 'query', 12) : (0, _tsInvariant.invariant)(queryDef && queryDef.operation === 'query', 'Must contain a query definition.');
return queryDef;
}
function getFragmentDefinition(doc) {
process.env.NODE_ENV === "production" ? tsInvariant.invariant(doc.kind === 'Document', 13) : tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
process.env.NODE_ENV === "production" ? tsInvariant.invariant(doc.definitions.length <= 1, 14) : tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.');
var fragmentDef = doc.definitions[0];
process.env.NODE_ENV === "production" ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 15) : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.');
return fragmentDef;
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(doc.kind === 'Document', 13) : (0, _tsInvariant.invariant)(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(doc.definitions.length <= 1, 14) : (0, _tsInvariant.invariant)(doc.definitions.length <= 1, 'Fragment must have exactly one definition.');
var fragmentDef = doc.definitions[0];
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(fragmentDef.kind === 'FragmentDefinition', 15) : (0, _tsInvariant.invariant)(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.');
return fragmentDef;
}
function getMainDefinition(queryDoc) {
checkDocument(queryDoc);
var fragmentDefinition;
for (var _i = 0, _a = queryDoc.definitions; _i < _a.length; _i++) {
var definition = _a[_i];
if (definition.kind === 'OperationDefinition') {
var operation = definition.operation;
if (operation === 'query' ||
operation === 'mutation' ||
operation === 'subscription') {
return definition;
}
}
if (definition.kind === 'FragmentDefinition' && !fragmentDefinition) {
fragmentDefinition = definition;
}
checkDocument(queryDoc);
var fragmentDefinition;
for (var _i = 0, _a = queryDoc.definitions; _i < _a.length; _i++) {
var definition = _a[_i];
if (definition.kind === 'OperationDefinition') {
var operation = definition.operation;
if (operation === 'query' || operation === 'mutation' || operation === 'subscription') {
return definition;
}
}
if (fragmentDefinition) {
return fragmentDefinition;
if (definition.kind === 'FragmentDefinition' && !fragmentDefinition) {
fragmentDefinition = definition;
}
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(16) : new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.');
}
if (fragmentDefinition) {
return fragmentDefinition;
}
throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(16) : new _tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.');
}
function createFragmentMap(fragments) {
if (fragments === void 0) { fragments = []; }
var symTable = {};
fragments.forEach(function (fragment) {
symTable[fragment.name.value] = fragment;
});
return symTable;
if (fragments === void 0) {
fragments = [];
}
var symTable = {};
fragments.forEach(function (fragment) {
symTable[fragment.name.value] = fragment;
});
return symTable;
}
function getDefaultValues(definition) {
if (definition &&
definition.variableDefinitions &&
definition.variableDefinitions.length) {
var defaultValues = definition.variableDefinitions
.filter(function (_a) {
var defaultValue = _a.defaultValue;
return defaultValue;
})
.map(function (_a) {
var variable = _a.variable, defaultValue = _a.defaultValue;
var defaultValueObj = {};
valueToObjectRepresentation(defaultValueObj, variable.name, defaultValue);
return defaultValueObj;
});
return assign.apply(void 0, [{}].concat(defaultValues));
}
return {};
if (definition && definition.variableDefinitions && definition.variableDefinitions.length) {
var defaultValues = definition.variableDefinitions.filter(function (_a) {
var defaultValue = _a.defaultValue;
return defaultValue;
}).map(function (_a) {
var variable = _a.variable,
defaultValue = _a.defaultValue;
var defaultValueObj = {};
valueToObjectRepresentation(defaultValueObj, variable.name, defaultValue);
return defaultValueObj;
});
return assign.apply(void 0, [{}].concat(defaultValues));
}
return {};
}
function variablesInOperation(operation) {
var names = new Set();
if (operation.variableDefinitions) {
for (var _i = 0, _a = operation.variableDefinitions; _i < _a.length; _i++) {
var definition = _a[_i];
names.add(definition.variable.name.value);
}
var names = new Set();
if (operation.variableDefinitions) {
for (var _i = 0, _a = operation.variableDefinitions; _i < _a.length; _i++) {
var definition = _a[_i];
names.add(definition.variable.name.value);
}
return names;
}
return names;
}
function filterInPlace(array, test, context) {
var target = 0;
array.forEach(function (elem, i) {
if (test.call(this, elem, i, array)) {
array[target++] = elem;
}
}, context);
array.length = target;
return array;
var target = 0;
array.forEach(function (elem, i) {
if (test.call(this, elem, i, array)) {
array[target++] = elem;
}
}, context);
array.length = target;
return array;
}
var TYPENAME_FIELD = {
kind: 'Field',
name: {
kind: 'Name',
value: '__typename',
},
kind: 'Field',
name: {
kind: 'Name',
value: '__typename'
}
};
function isEmpty(op, fragments) {
return op.selectionSet.selections.every(function (selection) {
return selection.kind === 'FragmentSpread' &&
isEmpty(fragments[selection.name.value], fragments);
});
return op.selectionSet.selections.every(function (selection) {
return selection.kind === 'FragmentSpread' && isEmpty(fragments[selection.name.value], fragments);
});
}
function nullIfDocIsEmpty(doc) {
return isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc)))
? null
: doc;
return isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc))) ? null : doc;
}
function getDirectiveMatcher(directives) {
return function directiveMatcher(directive) {
return directives.some(function (dir) {
return (dir.name && dir.name === directive.name.value) ||
(dir.test && dir.test(directive));
});
};
return function directiveMatcher(directive) {
return directives.some(function (dir) {
return dir.name && dir.name === directive.name.value || dir.test && dir.test(directive);
});
};
}
function removeDirectivesFromDocument(directives, doc) {
var variablesInUse = Object.create(null);
var variablesToRemove = [];
var fragmentSpreadsInUse = Object.create(null);
var fragmentSpreadsToRemove = [];
var modifiedDoc = nullIfDocIsEmpty(visitor.visit(doc, {
Variable: {
enter: function (node, _key, parent) {
if (parent.kind !== 'VariableDefinition') {
variablesInUse[node.name.value] = true;
var variablesInUse = Object.create(null);
var variablesToRemove = [];
var fragmentSpreadsInUse = Object.create(null);
var fragmentSpreadsToRemove = [];
var modifiedDoc = nullIfDocIsEmpty((0, _visitor.visit)(doc, {
Variable: {
enter: function (node, _key, parent) {
if (parent.kind !== 'VariableDefinition') {
variablesInUse[node.name.value] = true;
}
}
},
Field: {
enter: function (node) {
if (directives && node.directives) {
var shouldRemoveField = directives.some(function (directive) {
return directive.remove;
});
if (shouldRemoveField && node.directives && node.directives.some(getDirectiveMatcher(directives))) {
if (node.arguments) {
node.arguments.forEach(function (arg) {
if (arg.value.kind === 'Variable') {
variablesToRemove.push({
name: arg.value.name.value
});
}
},
},
Field: {
enter: function (node) {
if (directives && node.directives) {
var shouldRemoveField = directives.some(function (directive) { return directive.remove; });
if (shouldRemoveField &&
node.directives &&
node.directives.some(getDirectiveMatcher(directives))) {
if (node.arguments) {
node.arguments.forEach(function (arg) {
if (arg.value.kind === 'Variable') {
variablesToRemove.push({
name: arg.value.name.value,
});
}
});
}
if (node.selectionSet) {
getAllFragmentSpreadsFromSelectionSet(node.selectionSet).forEach(function (frag) {
fragmentSpreadsToRemove.push({
name: frag.name.value,
});
});
}
return null;
}
}
},
},
FragmentSpread: {
enter: function (node) {
fragmentSpreadsInUse[node.name.value] = true;
},
},
Directive: {
enter: function (node) {
if (getDirectiveMatcher(directives)(node)) {
return null;
}
},
},
}));
if (modifiedDoc &&
filterInPlace(variablesToRemove, function (v) { return !variablesInUse[v.name]; }).length) {
modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);
});
}
if (node.selectionSet) {
getAllFragmentSpreadsFromSelectionSet(node.selectionSet).forEach(function (frag) {
fragmentSpreadsToRemove.push({
name: frag.name.value
});
});
}
return null;
}
}
}
},
FragmentSpread: {
enter: function (node) {
fragmentSpreadsInUse[node.name.value] = true;
}
},
Directive: {
enter: function (node) {
if (getDirectiveMatcher(directives)(node)) {
return null;
}
}
}
if (modifiedDoc &&
filterInPlace(fragmentSpreadsToRemove, function (fs) { return !fragmentSpreadsInUse[fs.name]; })
.length) {
modifiedDoc = removeFragmentSpreadFromDocument(fragmentSpreadsToRemove, modifiedDoc);
}
return modifiedDoc;
}));
if (modifiedDoc && filterInPlace(variablesToRemove, function (v) {
return !variablesInUse[v.name];
}).length) {
modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);
}
if (modifiedDoc && filterInPlace(fragmentSpreadsToRemove, function (fs) {
return !fragmentSpreadsInUse[fs.name];
}).length) {
modifiedDoc = removeFragmentSpreadFromDocument(fragmentSpreadsToRemove, modifiedDoc);
}
return modifiedDoc;
}
function addTypenameToDocument(doc) {
return visitor.visit(checkDocument(doc), {
SelectionSet: {
enter: function (node, _key, parent) {
if (parent &&
parent.kind === 'OperationDefinition') {
return;
}
var selections = node.selections;
if (!selections) {
return;
}
var skip = selections.some(function (selection) {
return (isField(selection) &&
(selection.name.value === '__typename' ||
selection.name.value.lastIndexOf('__', 0) === 0));
});
if (skip) {
return;
}
var field = parent;
if (isField(field) &&
field.directives &&
field.directives.some(function (d) { return d.name.value === 'export'; })) {
return;
}
return tslib.__assign({}, node, { selections: selections.concat([TYPENAME_FIELD]) });
},
},
});
return (0, _visitor.visit)(checkDocument(doc), {
SelectionSet: {
enter: function (node, _key, parent) {
if (parent && parent.kind === 'OperationDefinition') {
return;
}
var selections = node.selections;
if (!selections) {
return;
}
var skip = selections.some(function (selection) {
return isField(selection) && (selection.name.value === '__typename' || selection.name.value.lastIndexOf('__', 0) === 0);
});
if (skip) {
return;
}
var field = parent;
if (isField(field) && field.directives && field.directives.some(function (d) {
return d.name.value === 'export';
})) {
return;
}
return (0, _tslib.__assign)({}, node, {
selections: selections.concat([TYPENAME_FIELD])
});
}
}
});
}
var connectionRemoveConfig = {
test: function (directive) {
var willRemove = directive.name.value === 'connection';
if (willRemove) {
if (!directive.arguments ||
!directive.arguments.some(function (arg) { return arg.name.value === 'key'; })) {
process.env.NODE_ENV === "production" || tsInvariant.invariant.warn('Removing an @connection directive even though it does not have a key. ' +
'You may want to use the key parameter to specify a store key.');
}
}
return willRemove;
},
test: function (directive) {
var willRemove = directive.name.value === 'connection';
if (willRemove) {
if (!directive.arguments || !directive.arguments.some(function (arg) {
return arg.name.value === 'key';
})) {
process.env.NODE_ENV === "production" || _tsInvariant.invariant.warn('Removing an @connection directive even though it does not have a key. ' + 'You may want to use the key parameter to specify a store key.');
}
}
return willRemove;
}
};
function removeConnectionDirectiveFromDocument(doc) {
return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
}
function hasDirectivesInSelectionSet(directives, selectionSet, nestedCheck) {
if (nestedCheck === void 0) { nestedCheck = true; }
return (selectionSet &&
selectionSet.selections &&
selectionSet.selections.some(function (selection) {
return hasDirectivesInSelection(directives, selection, nestedCheck);
}));
if (nestedCheck === void 0) {
nestedCheck = true;
}
return selectionSet && selectionSet.selections && selectionSet.selections.some(function (selection) {
return hasDirectivesInSelection(directives, selection, nestedCheck);
});
}
function hasDirectivesInSelection(directives, selection, nestedCheck) {
if (nestedCheck === void 0) { nestedCheck = true; }
if (!isField(selection)) {
return true;
}
if (!selection.directives) {
return false;
}
return (selection.directives.some(getDirectiveMatcher(directives)) ||
(nestedCheck &&
hasDirectivesInSelectionSet(directives, selection.selectionSet, nestedCheck)));
if (nestedCheck === void 0) {
nestedCheck = true;
}
if (!isField(selection)) {
return true;
}
if (!selection.directives) {
return false;
}
return selection.directives.some(getDirectiveMatcher(directives)) || nestedCheck && hasDirectivesInSelectionSet(directives, selection.selectionSet, nestedCheck);
}
function getDirectivesFromDocument(directives, doc) {
checkDocument(doc);
var parentPath;
return nullIfDocIsEmpty(visitor.visit(doc, {
SelectionSet: {
enter: function (node, _key, _parent, path) {
var currentPath = path.join('-');
if (!parentPath ||
currentPath === parentPath ||
!currentPath.startsWith(parentPath)) {
if (node.selections) {
var selectionsWithDirectives = node.selections.filter(function (selection) { return hasDirectivesInSelection(directives, selection); });
if (hasDirectivesInSelectionSet(directives, node, false)) {
parentPath = currentPath;
}
return tslib.__assign({}, node, { selections: selectionsWithDirectives });
}
else {
return null;
}
}
},
},
}));
checkDocument(doc);
var parentPath;
return nullIfDocIsEmpty((0, _visitor.visit)(doc, {
SelectionSet: {
enter: function (node, _key, _parent, path) {
var currentPath = path.join('-');
if (!parentPath || currentPath === parentPath || !currentPath.startsWith(parentPath)) {
if (node.selections) {
var selectionsWithDirectives = node.selections.filter(function (selection) {
return hasDirectivesInSelection(directives, selection);
});
if (hasDirectivesInSelectionSet(directives, node, false)) {
parentPath = currentPath;
}
return (0, _tslib.__assign)({}, node, {
selections: selectionsWithDirectives
});
} else {
return null;
}
}
}
}
}));
}
function getArgumentMatcher(config) {
return function argumentMatcher(argument) {
return config.some(function (aConfig) {
return argument.value &&
argument.value.kind === 'Variable' &&
argument.value.name &&
(aConfig.name === argument.value.name.value ||
(aConfig.test && aConfig.test(argument)));
});
};
return function argumentMatcher(argument) {
return config.some(function (aConfig) {
return argument.value && argument.value.kind === 'Variable' && argument.value.name && (aConfig.name === argument.value.name.value || aConfig.test && aConfig.test(argument));
});
};
}
function removeArgumentsFromDocument(config, doc) {
var argMatcher = getArgumentMatcher(config);
return nullIfDocIsEmpty(visitor.visit(doc, {
OperationDefinition: {
enter: function (node) {
return tslib.__assign({}, node, { variableDefinitions: node.variableDefinitions.filter(function (varDef) {
return !config.some(function (arg) { return arg.name === varDef.variable.name.value; });
}) });
},
},
Field: {
enter: function (node) {
var shouldRemoveField = config.some(function (argConfig) { return argConfig.remove; });
if (shouldRemoveField) {
var argMatchCount_1 = 0;
node.arguments.forEach(function (arg) {
if (argMatcher(arg)) {
argMatchCount_1 += 1;
}
});
if (argMatchCount_1 === 1) {
return null;
}
}
},
},
Argument: {
enter: function (node) {
if (argMatcher(node)) {
return null;
}
},
},
}));
}
function removeFragmentSpreadFromDocument(config, doc) {
function enter(node) {
if (config.some(function (def) { return def.name === node.name.value; })) {
var argMatcher = getArgumentMatcher(config);
return nullIfDocIsEmpty((0, _visitor.visit)(doc, {
OperationDefinition: {
enter: function (node) {
return (0, _tslib.__assign)({}, node, {
variableDefinitions: node.variableDefinitions.filter(function (varDef) {
return !config.some(function (arg) {
return arg.name === varDef.variable.name.value;
});
})
});
}
},
Field: {
enter: function (node) {
var shouldRemoveField = config.some(function (argConfig) {
return argConfig.remove;
});
if (shouldRemoveField) {
var argMatchCount_1 = 0;
node.arguments.forEach(function (arg) {
if (argMatcher(arg)) {
argMatchCount_1 += 1;
}
});
if (argMatchCount_1 === 1) {
return null;
}
}
}
},
Argument: {
enter: function (node) {
if (argMatcher(node)) {
return null;
}
}
}
return nullIfDocIsEmpty(visitor.visit(doc, {
FragmentSpread: { enter: enter },
FragmentDefinition: { enter: enter },
}));
}));
}
function removeFragmentSpreadFromDocument(config, doc) {
function enter(node) {
if (config.some(function (def) {
return def.name === node.name.value;
})) {
return null;
}
}
return nullIfDocIsEmpty((0, _visitor.visit)(doc, {
FragmentSpread: {
enter: enter
},
FragmentDefinition: {
enter: enter
}
}));
}
function getAllFragmentSpreadsFromSelectionSet(selectionSet) {
var allFragments = [];
selectionSet.selections.forEach(function (selection) {
if ((isField(selection) || isInlineFragment(selection)) &&
selection.selectionSet) {
getAllFragmentSpreadsFromSelectionSet(selection.selectionSet).forEach(function (frag) { return allFragments.push(frag); });
}
else if (selection.kind === 'FragmentSpread') {
allFragments.push(selection);
}
});
return allFragments;
var allFragments = [];
selectionSet.selections.forEach(function (selection) {
if ((isField(selection) || isInlineFragment(selection)) && selection.selectionSet) {
getAllFragmentSpreadsFromSelectionSet(selection.selectionSet).forEach(function (frag) {
return allFragments.push(frag);
});
} else if (selection.kind === 'FragmentSpread') {
allFragments.push(selection);
}
});
return allFragments;
}
function buildQueryFromSelectionSet(document) {
var definition = getMainDefinition(document);
var definitionOperation = definition.operation;
if (definitionOperation === 'query') {
return document;
var definition = getMainDefinition(document);
var definitionOperation = definition.operation;
if (definitionOperation === 'query') {
return document;
}
var modifiedDoc = (0, _visitor.visit)(document, {
OperationDefinition: {
enter: function (node) {
return (0, _tslib.__assign)({}, node, {
operation: 'query'
});
}
}
var modifiedDoc = visitor.visit(document, {
OperationDefinition: {
enter: function (node) {
return tslib.__assign({}, node, { operation: 'query' });
},
},
});
return modifiedDoc;
});
return modifiedDoc;
}
function removeClientSetsFromDocument(document) {
checkDocument(document);
var modifiedDoc = removeDirectivesFromDocument([
{
test: function (directive) { return directive.name.value === 'client'; },
remove: true,
},
], document);
if (modifiedDoc) {
modifiedDoc = visitor.visit(modifiedDoc, {
FragmentDefinition: {
enter: function (node) {
if (node.selectionSet) {
var isTypenameOnly = node.selectionSet.selections.every(function (selection) {
return isField(selection) && selection.name.value === '__typename';
});
if (isTypenameOnly) {
return null;
}
}
},
},
});
}
return modifiedDoc;
checkDocument(document);
var modifiedDoc = removeDirectivesFromDocument([{
test: function (directive) {
return directive.name.value === 'client';
},
remove: true
}], document);
if (modifiedDoc) {
modifiedDoc = (0, _visitor.visit)(modifiedDoc, {
FragmentDefinition: {
enter: function (node) {
if (node.selectionSet) {
var isTypenameOnly = node.selectionSet.selections.every(function (selection) {
return isField(selection) && selection.name.value === '__typename';
});
if (isTypenameOnly) {
return null;
}
}
}
}
});
}
return modifiedDoc;
}
var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
navigator.product === 'ReactNative');
var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' && navigator.product === 'ReactNative');
exports.canUseWeakMap = canUseWeakMap;
var toString = Object.prototype.toString;
var toString = Object.prototype.toString;
function cloneDeep(value) {
return cloneDeepHelper(value, new Map());
return cloneDeepHelper(value, new Map());
}
function cloneDeepHelper(val, seen) {
switch (toString.call(val)) {
case "[object Array]": {
if (seen.has(val))
return seen.get(val);
var copy_1 = val.slice(0);
seen.set(val, copy_1);
copy_1.forEach(function (child, i) {
copy_1[i] = cloneDeepHelper(child, seen);
});
return copy_1;
}
case "[object Object]": {
if (seen.has(val))
return seen.get(val);
var copy_2 = Object.create(Object.getPrototypeOf(val));
seen.set(val, copy_2);
Object.keys(val).forEach(function (key) {
copy_2[key] = cloneDeepHelper(val[key], seen);
});
return copy_2;
}
default:
return val;
}
switch (toString.call(val)) {
case "[object Array]":
{
if (seen.has(val)) return seen.get(val);
var copy_1 = val.slice(0);
seen.set(val, copy_1);
copy_1.forEach(function (child, i) {
copy_1[i] = cloneDeepHelper(child, seen);
});
return copy_1;
}
case "[object Object]":
{
if (seen.has(val)) return seen.get(val);
var copy_2 = Object.create(Object.getPrototypeOf(val));
seen.set(val, copy_2);
Object.keys(val).forEach(function (key) {
copy_2[key] = cloneDeepHelper(val[key], seen);
});
return copy_2;
}
default:
return val;
}
}
function getEnv() {
if (typeof process !== 'undefined' && process.env.NODE_ENV) {
return process.env.NODE_ENV;
}
return 'development';
if (typeof process !== 'undefined' && process.env.NODE_ENV) {
return process.env.NODE_ENV;
}
return 'development';
}
function isEnv(env) {
return getEnv() === env;
return getEnv() === env;
}
function isProduction() {
return isEnv('production') === true;
return isEnv('production') === true;
}
function isDevelopment() {
return isEnv('development') === true;
return isEnv('development') === true;
}
function isTest() {
return isEnv('test') === true;
return isEnv('test') === true;
}
function tryFunctionOrLogError(f) {
try {
return f();
try {
return f();
} catch (e) {
if (console.error) {
console.error(e);
}
catch (e) {
if (console.error) {
console.error(e);
}
}
}
}
function graphQLResultHasError(result) {
return result.errors && result.errors.length;
return result.errors && result.errors.length;
}
function isEqual(a, b) {
if (a === b) {
return true;
}
if (a instanceof Date && b instanceof Date) {
return a.getTime() === b.getTime();
}
if (a != null &&
typeof a === 'object' &&
b != null &&
typeof b === 'object') {
for (var key in a) {
if (Object.prototype.hasOwnProperty.call(a, key)) {
if (!Object.prototype.hasOwnProperty.call(b, key)) {
return false;
}
if (!isEqual(a[key], b[key])) {
return false;
}
}
}
for (var key in b) {
if (Object.prototype.hasOwnProperty.call(b, key) &&
!Object.prototype.hasOwnProperty.call(a, key)) {
return false;
}
}
return true;
}
return false;
return (0, _lodash.default)(a, b);
}
function deepFreeze(o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach(function (prop) {
if (o[prop] !== null &&
(typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
!Object.isFrozen(o[prop])) {
deepFreeze(o[prop]);
}
});
return o;
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach(function (prop) {
if (o[prop] !== null && (typeof o[prop] === 'object' || typeof o[prop] === 'function') && !Object.isFrozen(o[prop])) {
deepFreeze(o[prop]);
}
});
return o;
}
function maybeDeepFreeze(obj) {
if (isDevelopment() || isTest()) {
var symbolIsPolyfilled = typeof Symbol === 'function' && typeof Symbol('') === 'string';
if (!symbolIsPolyfilled) {
return deepFreeze(obj);
}
if (isDevelopment() || isTest()) {
var symbolIsPolyfilled = typeof Symbol === 'function' && typeof Symbol('') === 'string';
if (!symbolIsPolyfilled) {
return deepFreeze(obj);
}
return obj;
}
return obj;
}
var hasOwnProperty = Object.prototype.hasOwnProperty;
function mergeDeep() {
var sources = [];
for (var _i = 0; _i < arguments.length; _i++) {
sources[_i] = arguments[_i];
}
return mergeDeepArray(sources);
var sources = [];
for (var _i = 0; _i < arguments.length; _i++) {
sources[_i] = arguments[_i];
}
return mergeDeepArray(sources);
}
function mergeDeepArray(sources) {
var target = sources[0] || {};
var count = sources.length;
if (count > 1) {
var pastCopies = [];
target = shallowCopyForMerge(target, pastCopies);
for (var i = 1; i < count; ++i) {
target = mergeHelper(target, sources[i], pastCopies);
}
var target = sources[0] || {};
var count = sources.length;
if (count > 1) {
var pastCopies = [];
target = shallowCopyForMerge(target, pastCopies);
for (var i = 1; i < count; ++i) {
target = mergeHelper(target, sources[i], pastCopies);
}
return target;
}
return target;
}
function isObject(obj) {
return obj !== null && typeof obj === 'object';
return obj !== null && typeof obj === 'object';
}
function mergeHelper(target, source, pastCopies) {
if (isObject(source) && isObject(target)) {
if (Object.isExtensible && !Object.isExtensible(target)) {
target = shallowCopyForMerge(target, pastCopies);
if (isObject(source) && isObject(target)) {
if (Object.isExtensible && !Object.isExtensible(target)) {
target = shallowCopyForMerge(target, pastCopies);
}
Object.keys(source).forEach(function (sourceKey) {
var sourceValue = source[sourceKey];
if (hasOwnProperty.call(target, sourceKey)) {
var targetValue = target[sourceKey];
if (sourceValue !== targetValue) {
target[sourceKey] = mergeHelper(shallowCopyForMerge(targetValue, pastCopies), sourceValue, pastCopies);
}
Object.keys(source).forEach(function (sourceKey) {
var sourceValue = source[sourceKey];
if (hasOwnProperty.call(target, sourceKey)) {
var targetValue = target[sourceKey];
if (sourceValue !== targetValue) {
target[sourceKey] = mergeHelper(shallowCopyForMerge(targetValue, pastCopies), sourceValue, pastCopies);
}
}
else {
target[sourceKey] = sourceValue;
}
});
return target;
}
return source;
} else {
target[sourceKey] = sourceValue;
}
});
return target;
}
return source;
}
function shallowCopyForMerge(value, pastCopies) {
if (value !== null &&
typeof value === 'object' &&
pastCopies.indexOf(value) < 0) {
if (Array.isArray(value)) {
value = value.slice(0);
}
else {
value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
}
pastCopies.push(value);
if (value !== null && typeof value === 'object' && pastCopies.indexOf(value) < 0) {
if (Array.isArray(value)) {
value = value.slice(0);
} else {
value = (0, _tslib.__assign)({
__proto__: Object.getPrototypeOf(value)
}, value);
}
return value;
pastCopies.push(value);
}
return value;
}
var haveWarned = Object.create({});
function warnOnceInDevelopment(msg, type) {
if (type === void 0) { type = 'warn'; }
if (!isProduction() && !haveWarned[msg]) {
if (!isTest()) {
haveWarned[msg] = true;
}
if (type === 'error') {
console.error(msg);
}
else {
console.warn(msg);
}
if (type === void 0) {
type = 'warn';
}
if (!isProduction() && !haveWarned[msg]) {
if (!isTest()) {
haveWarned[msg] = true;
}
if (type === 'error') {
console.error(msg);
} else {
console.warn(msg);
}
}
}
function stripSymbols(data) {
return JSON.parse(JSON.stringify(data));
return JSON.parse(JSON.stringify(data));
}
exports.addTypenameToDocument = addTypenameToDocument;
exports.argumentsObjectFromField = argumentsObjectFromField;
exports.assign = assign;
exports.buildQueryFromSelectionSet = buildQueryFromSelectionSet;
exports.canUseWeakMap = canUseWeakMap;
exports.checkDocument = checkDocument;
exports.cloneDeep = cloneDeep;
exports.createFragmentMap = createFragmentMap;
exports.getDefaultValues = getDefaultValues;
exports.getDirectiveInfoFromField = getDirectiveInfoFromField;
exports.getDirectiveNames = getDirectiveNames;
exports.getDirectivesFromDocument = getDirectivesFromDocument;
exports.getEnv = getEnv;
exports.getFragmentDefinition = getFragmentDefinition;
exports.getFragmentDefinitions = getFragmentDefinitions;
exports.getFragmentQueryDocument = getFragmentQueryDocument;
exports.getInclusionDirectives = getInclusionDirectives;
exports.getMainDefinition = getMainDefinition;
exports.getMutationDefinition = getMutationDefinition;
exports.getOperationDefinition = getOperationDefinition;
exports.getOperationDefinitionOrDie = getOperationDefinitionOrDie;
exports.getOperationName = getOperationName;
exports.getQueryDefinition = getQueryDefinition;
exports.getStoreKeyName = getStoreKeyName;
exports.graphQLResultHasError = graphQLResultHasError;
exports.hasClientExports = hasClientExports;
exports.hasDirectives = hasDirectives;
exports.isDevelopment = isDevelopment;
exports.isEnv = isEnv;
exports.isEqual = isEqual;
exports.isField = isField;
exports.isIdValue = isIdValue;
exports.isInlineFragment = isInlineFragment;
exports.isJsonValue = isJsonValue;
exports.isNumberValue = isNumberValue;
exports.isProduction = isProduction;
exports.isScalarValue = isScalarValue;
exports.isTest = isTest;
exports.maybeDeepFreeze = maybeDeepFreeze;
exports.mergeDeep = mergeDeep;
exports.mergeDeepArray = mergeDeepArray;
exports.removeArgumentsFromDocument = removeArgumentsFromDocument;
exports.removeClientSetsFromDocument = removeClientSetsFromDocument;
exports.removeConnectionDirectiveFromDocument = removeConnectionDirectiveFromDocument;
exports.removeDirectivesFromDocument = removeDirectivesFromDocument;
exports.removeFragmentSpreadFromDocument = removeFragmentSpreadFromDocument;
exports.resultKeyNameFromField = resultKeyNameFromField;
exports.shouldInclude = shouldInclude;
exports.storeKeyNameFromField = storeKeyNameFromField;
exports.stripSymbols = stripSymbols;
exports.toIdValue = toIdValue;
exports.tryFunctionOrLogError = tryFunctionOrLogError;
exports.valueFromNode = valueFromNode;
exports.valueToObjectRepresentation = valueToObjectRepresentation;
exports.variablesInOperation = variablesInOperation;
exports.warnOnceInDevelopment = warnOnceInDevelopment;
//# sourceMappingURL=bundle.cjs.js.map

@@ -1,1 +0,1 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("graphql/language/visitor"),t=require("ts-invariant"),r=require("tslib"),i=e(require("fast-json-stable-stringify"));function o(e){return["StringValue","BooleanValue","EnumValue"].indexOf(e.kind)>-1}function u(e){return["IntValue","FloatValue"].indexOf(e.kind)>-1}function a(e){return"StringValue"===e.kind}function c(e){return"BooleanValue"===e.kind}function f(e){return"IntValue"===e.kind}function l(e){return"FloatValue"===e.kind}function s(e){return"Variable"===e.kind}function v(e){return"ObjectValue"===e.kind}function p(e){return"ListValue"===e.kind}function m(e){return"EnumValue"===e.kind}function d(e){return"NullValue"===e.kind}function g(e,n,r,i){if(f(r)||l(r))e[n.value]=Number(r.value);else if(c(r)||a(r))e[n.value]=r.value;else if(v(r)){var o={};r.fields.map(function(e){return g(o,e.name,e.value,i)}),e[n.value]=o}else if(s(r)){var u=(i||{})[r.name.value];e[n.value]=u}else if(p(r))e[n.value]=r.values.map(function(e){var t={};return g(t,n,e,i),t[n.value]});else if(m(r))e[n.value]=r.value;else{if(!d(r))throw new t.InvariantError(17);e[n.value]=null}}function y(e,n){var t=null;e.directives&&(t={},e.directives.forEach(function(e){t[e.name.value]={},e.arguments&&e.arguments.forEach(function(r){var i=r.name,o=r.value;return g(t[e.name.value],i,o,n)})}));var r=null;return e.arguments&&e.arguments.length&&(r={},e.arguments.forEach(function(e){var t=e.name,i=e.value;return g(r,t,i,n)})),b(e.name.value,r,t)}var h=["connection","include","skip","client","rest","export"];function b(e,n,t){if(t&&t.connection&&t.connection.key){if(t.connection.filter&&t.connection.filter.length>0){var r=t.connection.filter?t.connection.filter:[];r.sort();var o=n,u={};return r.forEach(function(e){u[e]=o[e]}),t.connection.key+"("+JSON.stringify(u)+")"}return t.connection.key}var a=e;if(n){var c=i(n);a+="("+c+")"}return t&&Object.keys(t).forEach(function(e){-1===h.indexOf(e)&&(t[e]&&Object.keys(t[e]).length?a+="@"+e+"("+JSON.stringify(t[e])+")":a+="@"+e)}),a}function x(e,n){if(e.arguments&&e.arguments.length){var t={};return e.arguments.forEach(function(e){var r=e.name,i=e.value;return g(t,r,i,n)}),t}return null}function O(e){return e.alias?e.alias.value:e.name.value}function D(e){return"Field"===e.kind}function k(e){return"InlineFragment"===e.kind}function F(e){return e&&"id"===e.type&&"boolean"==typeof e.generated}function j(e,n){return void 0===n&&(n=!1),r.__assign({type:"id",generated:n},"string"==typeof e?{id:e,typename:void 0}:e)}function S(e){return null!=e&&"object"==typeof e&&"json"===e.type}function E(e){throw new t.InvariantError(18)}function V(e,n){switch(void 0===n&&(n=E),e.kind){case"Variable":return n(e);case"NullValue":return null;case"IntValue":return parseInt(e.value,10);case"FloatValue":return parseFloat(e.value);case"ListValue":return e.values.map(function(e){return V(e,n)});case"ObjectValue":for(var t={},r=0,i=e.fields;r<i.length;r++){var o=i[r];t[o.name.value]=V(o.value,n)}return t;default:return e.value}}function _(e,n){if(e.directives&&e.directives.length){var t={};return e.directives.forEach(function(e){t[e.name.value]=x(e,n)}),t}return null}function w(e,n){return void 0===n&&(n={}),A(e.directives).every(function(e){var r=e.directive,i=e.ifArgument,o=!1;return"Variable"===i.value.kind?(o=n[i.value.name.value],t.invariant(void 0!==o,1)):o=i.value.value,"skip"===r.name.value?!o:o})}function I(e){var t=[];return n.visit(e,{Directive:function(e){t.push(e.name.value)}}),t}function N(e,n){return I(n).some(function(n){return e.indexOf(n)>-1})}function q(e){return e&&N(["client"],e)&&N(["export"],e)}function P(e){var n=e.name.value;return"skip"===n||"include"===n}function A(e){return e?e.filter(P).map(function(e){var n=e.arguments;e.name.value;t.invariant(n&&1===n.length,2);var r=n[0];t.invariant(r.name&&"if"===r.name.value,3);var i=r.value;return t.invariant(i&&("Variable"===i.kind||"BooleanValue"===i.kind),4),{directive:e,ifArgument:r}}):[]}function M(e,n){var i=n,o=[];return e.definitions.forEach(function(e){if("OperationDefinition"===e.kind)throw new t.InvariantError(5);"FragmentDefinition"===e.kind&&o.push(e)}),void 0===i&&(t.invariant(1===o.length,6),i=o[0].name.value),r.__assign({},e,{definitions:[{kind:"OperationDefinition",operation:"query",selectionSet:{kind:"SelectionSet",selections:[{kind:"FragmentSpread",name:{kind:"Name",value:i}}]}}].concat(e.definitions)})}function T(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];return n.forEach(function(n){null!=n&&Object.keys(n).forEach(function(t){e[t]=n[t]})}),e}function J(e){L(e);var n=e.definitions.filter(function(e){return"OperationDefinition"===e.kind&&"mutation"===e.operation})[0];return t.invariant(n,7),n}function L(e){t.invariant(e&&"Document"===e.kind,8);var n=e.definitions.filter(function(e){return"FragmentDefinition"!==e.kind}).map(function(e){if("OperationDefinition"!==e.kind)throw new t.InvariantError(9);return e});return t.invariant(n.length<=1,10),e}function Q(e){return L(e),e.definitions.filter(function(e){return"OperationDefinition"===e.kind})[0]}function z(e){var n=Q(e);return t.invariant(n,11),n}function B(e){return e.definitions.filter(function(e){return"OperationDefinition"===e.kind&&e.name}).map(function(e){return e.name.value})[0]||null}function C(e){return e.definitions.filter(function(e){return"FragmentDefinition"===e.kind})}function K(e){var n=Q(e);return t.invariant(n&&"query"===n.operation,12),n}function R(e){t.invariant("Document"===e.kind,13),t.invariant(e.definitions.length<=1,14);var n=e.definitions[0];return t.invariant("FragmentDefinition"===n.kind,15),n}function W(e){var n;L(e);for(var r=0,i=e.definitions;r<i.length;r++){var o=i[r];if("OperationDefinition"===o.kind){var u=o.operation;if("query"===u||"mutation"===u||"subscription"===u)return o}"FragmentDefinition"!==o.kind||n||(n=o)}if(n)return n;throw new t.InvariantError(16)}function H(e){void 0===e&&(e=[]);var n={};return e.forEach(function(e){n[e.name.value]=e}),n}function U(e){if(e&&e.variableDefinitions&&e.variableDefinitions.length){var n=e.variableDefinitions.filter(function(e){return e.defaultValue}).map(function(e){var n=e.variable,t=e.defaultValue,r={};return g(r,n.name,t),r});return T.apply(void 0,[{}].concat(n))}return{}}function G(e){var n=new Set;if(e.variableDefinitions)for(var t=0,r=e.variableDefinitions;t<r.length;t++){var i=r[t];n.add(i.variable.name.value)}return n}function X(e,n,t){var r=0;return e.forEach(function(t,i){n.call(this,t,i,e)&&(e[r++]=t)},t),e.length=r,e}var Y={kind:"Field",name:{kind:"Name",value:"__typename"}};function Z(e,n){return e.selectionSet.selections.every(function(e){return"FragmentSpread"===e.kind&&Z(n[e.name.value],n)})}function $(e){return Z(Q(e)||R(e),H(C(e)))?null:e}function ee(e){return function(n){return e.some(function(e){return e.name&&e.name===n.name.value||e.test&&e.test(n)})}}function ne(e,t){var r=Object.create(null),i=[],o=Object.create(null),u=[],a=$(n.visit(t,{Variable:{enter:function(e,n,t){"VariableDefinition"!==t.kind&&(r[e.name.value]=!0)}},Field:{enter:function(n){if(e&&n.directives&&(e.some(function(e){return e.remove})&&n.directives&&n.directives.some(ee(e))))return n.arguments&&n.arguments.forEach(function(e){"Variable"===e.value.kind&&i.push({name:e.value.name.value})}),n.selectionSet&&se(n.selectionSet).forEach(function(e){u.push({name:e.name.value})}),null}},FragmentSpread:{enter:function(e){o[e.name.value]=!0}},Directive:{enter:function(n){if(ee(e)(n))return null}}}));return a&&X(i,function(e){return!r[e.name]}).length&&(a=fe(i,a)),a&&X(u,function(e){return!o[e.name]}).length&&(a=le(u,a)),a}function te(e){return n.visit(L(e),{SelectionSet:{enter:function(e,n,t){if(!t||"OperationDefinition"!==t.kind){var i=e.selections;if(i)if(!i.some(function(e){return D(e)&&("__typename"===e.name.value||0===e.name.value.lastIndexOf("__",0))})){var o=t;if(!(D(o)&&o.directives&&o.directives.some(function(e){return"export"===e.name.value})))return r.__assign({},e,{selections:i.concat([Y])})}}}}})}var re={test:function(e){var n="connection"===e.name.value;return n&&(!e.arguments||e.arguments.some(function(e){return"key"===e.name.value})),n}};function ie(e){return ne([re],L(e))}function oe(e,n,t){return void 0===t&&(t=!0),n&&n.selections&&n.selections.some(function(n){return ue(e,n,t)})}function ue(e,n,t){return void 0===t&&(t=!0),!D(n)||!!n.directives&&(n.directives.some(ee(e))||t&&oe(e,n.selectionSet,t))}function ae(e,t){var i;return L(t),$(n.visit(t,{SelectionSet:{enter:function(n,t,o,u){var a=u.join("-");if(!i||a===i||!a.startsWith(i)){if(n.selections){var c=n.selections.filter(function(n){return ue(e,n)});return oe(e,n,!1)&&(i=a),r.__assign({},n,{selections:c})}return null}}}}))}function ce(e){return function(n){return e.some(function(e){return n.value&&"Variable"===n.value.kind&&n.value.name&&(e.name===n.value.name.value||e.test&&e.test(n))})}}function fe(e,t){var i=ce(e);return $(n.visit(t,{OperationDefinition:{enter:function(n){return r.__assign({},n,{variableDefinitions:n.variableDefinitions.filter(function(n){return!e.some(function(e){return e.name===n.variable.name.value})})})}},Field:{enter:function(n){if(e.some(function(e){return e.remove})){var t=0;if(n.arguments.forEach(function(e){i(e)&&(t+=1)}),1===t)return null}}},Argument:{enter:function(e){if(i(e))return null}}}))}function le(e,t){function r(n){if(e.some(function(e){return e.name===n.name.value}))return null}return $(n.visit(t,{FragmentSpread:{enter:r},FragmentDefinition:{enter:r}}))}function se(e){var n=[];return e.selections.forEach(function(e){(D(e)||k(e))&&e.selectionSet?se(e.selectionSet).forEach(function(e){return n.push(e)}):"FragmentSpread"===e.kind&&n.push(e)}),n}function ve(e){return"query"===W(e).operation?e:n.visit(e,{OperationDefinition:{enter:function(e){return r.__assign({},e,{operation:"query"})}}})}function pe(e){L(e);var t=ne([{test:function(e){return"client"===e.name.value},remove:!0}],e);return t&&(t=n.visit(t,{FragmentDefinition:{enter:function(e){if(e.selectionSet&&e.selectionSet.selections.every(function(e){return D(e)&&"__typename"===e.name.value}))return null}}})),t}var me="function"==typeof WeakMap&&!("object"==typeof navigator&&"ReactNative"===navigator.product),de=Object.prototype.toString;function ge(e){return ye(e,new Map)}function ye(e,n){switch(de.call(e)){case"[object Array]":if(n.has(e))return n.get(e);var t=e.slice(0);return n.set(e,t),t.forEach(function(e,r){t[r]=ye(e,n)}),t;case"[object Object]":if(n.has(e))return n.get(e);var r=Object.create(Object.getPrototypeOf(e));return n.set(e,r),Object.keys(e).forEach(function(t){r[t]=ye(e[t],n)}),r;default:return e}}function he(){return"undefined"!=typeof process?"production":"development"}function be(e){return he()===e}function xe(){return!0===be("production")}function Oe(){return!0===be("development")}function De(){return!0===be("test")}function ke(e){try{return e()}catch(e){console.error&&console.error(e)}}function Fe(e){return e.errors&&e.errors.length}function je(e,n){if(e===n)return!0;if(e instanceof Date&&n instanceof Date)return e.getTime()===n.getTime();if(null!=e&&"object"==typeof e&&null!=n&&"object"==typeof n){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t)){if(!Object.prototype.hasOwnProperty.call(n,t))return!1;if(!je(e[t],n[t]))return!1}for(var t in n)if(Object.prototype.hasOwnProperty.call(n,t)&&!Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}return!1}function Se(e){return Object.freeze(e),Object.getOwnPropertyNames(e).forEach(function(n){null===e[n]||"object"!=typeof e[n]&&"function"!=typeof e[n]||Object.isFrozen(e[n])||Se(e[n])}),e}function Ee(e){if((Oe()||De())&&!("function"==typeof Symbol&&"string"==typeof Symbol("")))return Se(e);return e}var Ve=Object.prototype.hasOwnProperty;function _e(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return we(e)}function we(e){var n=e[0]||{},t=e.length;if(t>1){var r=[];n=qe(n,r);for(var i=1;i<t;++i)n=Ne(n,e[i],r)}return n}function Ie(e){return null!==e&&"object"==typeof e}function Ne(e,n,t){return Ie(n)&&Ie(e)?(Object.isExtensible&&!Object.isExtensible(e)&&(e=qe(e,t)),Object.keys(n).forEach(function(r){var i=n[r];if(Ve.call(e,r)){var o=e[r];i!==o&&(e[r]=Ne(qe(o,t),i,t))}else e[r]=i}),e):n}function qe(e,n){return null!==e&&"object"==typeof e&&n.indexOf(e)<0&&(e=Array.isArray(e)?e.slice(0):r.__assign({__proto__:Object.getPrototypeOf(e)},e),n.push(e)),e}var Pe=Object.create({});function Ae(e,n){void 0===n&&(n="warn"),xe()||Pe[e]||(De()||(Pe[e]=!0),"error"===n?console.error(e):console.warn(e))}function Me(e){return JSON.parse(JSON.stringify(e))}exports.addTypenameToDocument=te,exports.argumentsObjectFromField=x,exports.assign=T,exports.buildQueryFromSelectionSet=ve,exports.canUseWeakMap=me,exports.checkDocument=L,exports.cloneDeep=ge,exports.createFragmentMap=H,exports.getDefaultValues=U,exports.getDirectiveInfoFromField=_,exports.getDirectiveNames=I,exports.getDirectivesFromDocument=ae,exports.getEnv=he,exports.getFragmentDefinition=R,exports.getFragmentDefinitions=C,exports.getFragmentQueryDocument=M,exports.getInclusionDirectives=A,exports.getMainDefinition=W,exports.getMutationDefinition=J,exports.getOperationDefinition=Q,exports.getOperationDefinitionOrDie=z,exports.getOperationName=B,exports.getQueryDefinition=K,exports.getStoreKeyName=b,exports.graphQLResultHasError=Fe,exports.hasClientExports=q,exports.hasDirectives=N,exports.isDevelopment=Oe,exports.isEnv=be,exports.isEqual=je,exports.isField=D,exports.isIdValue=F,exports.isInlineFragment=k,exports.isJsonValue=S,exports.isNumberValue=u,exports.isProduction=xe,exports.isScalarValue=o,exports.isTest=De,exports.maybeDeepFreeze=Ee,exports.mergeDeep=_e,exports.mergeDeepArray=we,exports.removeArgumentsFromDocument=fe,exports.removeClientSetsFromDocument=pe,exports.removeConnectionDirectiveFromDocument=ie,exports.removeDirectivesFromDocument=ne,exports.removeFragmentSpreadFromDocument=le,exports.resultKeyNameFromField=O,exports.shouldInclude=w,exports.storeKeyNameFromField=y,exports.stripSymbols=Me,exports.toIdValue=j,exports.tryFunctionOrLogError=ke,exports.valueFromNode=V,exports.valueToObjectRepresentation=g,exports.variablesInOperation=G,exports.warnOnceInDevelopment=Ae;
exports.__esModule=!0,exports.addTypenameToDocument=function(n){return(0,e.visit)(h(n),{SelectionSet:{enter:function(e,n,r){if(!r||"OperationDefinition"!==r.kind){var i=e.selections;if(i){var o=i.some(function(e){return l(e)&&("__typename"===e.name.value||0===e.name.value.lastIndexOf("__",0))});if(!o){var u=r;if(!(l(u)&&u.directives&&u.directives.some(function(e){return"export"===e.name.value})))return(0,t.__assign)({},e,{selections:i.concat([S])})}}}}}})},exports.argumentsObjectFromField=f,exports.assign=x,exports.buildQueryFromSelectionSet=function(n){if("query"===k(n).operation)return n;return(0,e.visit)(n,{OperationDefinition:{enter:function(e){return(0,t.__assign)({},e,{operation:"query"})}}})},exports.checkDocument=h,exports.cloneDeep=function(e){return function e(n,t){switch(A.call(n)){case"[object Array]":if(t.has(n))return t.get(n);var r=n.slice(0);return t.set(n,r),r.forEach(function(n,i){r[i]=e(n,t)}),r;case"[object Object]":if(t.has(n))return t.get(n);var i=Object.create(Object.getPrototypeOf(n));return t.set(n,i),Object.keys(n).forEach(function(r){i[r]=e(n[r],t)}),i;default:return n}}(e,new Map)},exports.createFragmentMap=O,exports.getDefaultValues=function(e){if(e&&e.variableDefinitions&&e.variableDefinitions.length){var n=e.variableDefinitions.filter(function(e){var n=e.defaultValue;return n}).map(function(e){var n=e.variable,t=e.defaultValue,r={};return u(r,n.name,t),r});return x.apply(void 0,[{}].concat(n))}return{}},exports.getDirectiveInfoFromField=function(e,n){if(e.directives&&e.directives.length){var t={};return e.directives.forEach(function(e){t[e.name.value]=f(e,n)}),t}return null},exports.getDirectiveNames=m,exports.getDirectivesFromDocument=function(n,r){var i;return h(r),E((0,e.visit)(r,{SelectionSet:{enter:function(e,r,o,u){var a=u.join("-");if(!i||a===i||!a.startsWith(i)){if(e.selections){var c=e.selections.filter(function(e){return I(n,e)});return w(n,e,!1)&&(i=a),(0,t.__assign)({},e,{selections:c})}return null}}}}))},exports.getEnv=J,exports.getFragmentDefinition=D,exports.getFragmentDefinitions=b,exports.getFragmentQueryDocument=function(e,r){var i=r,o=[];e.definitions.forEach(function(e){if("OperationDefinition"===e.kind)throw new n.InvariantError(5);"FragmentDefinition"===e.kind&&o.push(e)}),void 0===i&&((0,n.invariant)(1===o.length,6),i=o[0].name.value);return(0,t.__assign)({},e,{definitions:[{kind:"OperationDefinition",operation:"query",selectionSet:{kind:"SelectionSet",selections:[{kind:"FragmentSpread",name:{kind:"Name",value:i}}]}}].concat(e.definitions)})},exports.getInclusionDirectives=g,exports.getMainDefinition=k,exports.getMutationDefinition=function(e){h(e);var t=e.definitions.filter(function(e){return"OperationDefinition"===e.kind&&"mutation"===e.operation})[0];return(0,n.invariant)(t,7),t},exports.getOperationDefinition=y,exports.getOperationDefinitionOrDie=function(e){var t=y(e);return(0,n.invariant)(t,11),t},exports.getOperationName=function(e){return e.definitions.filter(function(e){return"OperationDefinition"===e.kind&&e.name}).map(function(e){return e.name.value})[0]||null},exports.getQueryDefinition=function(e){var t=y(e);return(0,n.invariant)(t&&"query"===t.operation,12),t},exports.getStoreKeyName=c,exports.graphQLResultHasError=function(e){return e.errors&&e.errors.length},exports.hasClientExports=function(e){return e&&p(["client"],e)&&p(["export"],e)},exports.hasDirectives=p,exports.isDevelopment=Q,exports.isEnv=P,exports.isEqual=function(e,n){return(0,i.default)(e,n)},exports.isField=l,exports.isIdValue=function(e){return e&&"id"===e.type&&"boolean"==typeof e.generated},exports.isInlineFragment=s,exports.isJsonValue=function(e){return null!=e&&"object"==typeof e&&"json"===e.type},exports.isNumberValue=function(e){return["IntValue","FloatValue"].indexOf(e.kind)>-1},exports.isProduction=L,exports.isScalarValue=function(e){return["StringValue","BooleanValue","EnumValue"].indexOf(e.kind)>-1},exports.isTest=T,exports.maybeDeepFreeze=function(e){if(Q()||T()){var n="function"==typeof Symbol&&"string"==typeof Symbol("");if(!n)return function e(n){Object.freeze(n);Object.getOwnPropertyNames(n).forEach(function(t){null===n[t]||"object"!=typeof n[t]&&"function"!=typeof n[t]||Object.isFrozen(n[t])||e(n[t])});return n}(e)}return e},exports.mergeDeep=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return z(e)},exports.mergeDeepArray=z,exports.removeArgumentsFromDocument=N,exports.removeClientSetsFromDocument=function(n){h(n);var t=j([{test:function(e){return"client"===e.name.value},remove:!0}],n);t&&(t=(0,e.visit)(t,{FragmentDefinition:{enter:function(e){if(e.selectionSet){var n=e.selectionSet.selections.every(function(e){return l(e)&&"__typename"===e.name.value});if(n)return null}}}}));return t},exports.removeConnectionDirectiveFromDocument=function(e){return j([_],h(e))},exports.removeDirectivesFromDocument=j,exports.removeFragmentSpreadFromDocument=q,exports.resultKeyNameFromField=function(e){return e.alias?e.alias.value:e.name.value},exports.shouldInclude=function(e,t){void 0===t&&(t={});return g(e.directives).every(function(e){var r=e.directive,i=e.ifArgument,o=!1;return"Variable"===i.value.kind?(o=t[i.value.name.value],(0,n.invariant)(void 0!==o,1)):o=i.value.value,"skip"===r.name.value?!o:o})},exports.storeKeyNameFromField=function(e,n){var t=null;e.directives&&(t={},e.directives.forEach(function(e){t[e.name.value]={},e.arguments&&e.arguments.forEach(function(r){var i=r.name,o=r.value;return u(t[e.name.value],i,o,n)})}));var r=null;e.arguments&&e.arguments.length&&(r={},e.arguments.forEach(function(e){var t=e.name,i=e.value;return u(r,t,i,n)}));return c(e.name.value,r,t)},exports.stripSymbols=function(e){return JSON.parse(JSON.stringify(e))},exports.toIdValue=function(e,n){void 0===n&&(n=!1);return(0,t.__assign)({type:"id",generated:n},"string"==typeof e?{id:e,typename:void 0}:e)},exports.tryFunctionOrLogError=function(e){try{return e()}catch(e){console.error&&console.error(e)}},exports.valueFromNode=function e(n,t){void 0===t&&(t=v);switch(n.kind){case"Variable":return t(n);case"NullValue":return null;case"IntValue":return parseInt(n.value,10);case"FloatValue":return parseFloat(n.value);case"ListValue":return n.values.map(function(n){return e(n,t)});case"ObjectValue":for(var r={},i=0,o=n.fields;i<o.length;i++){var u=o[i];r[u.name.value]=e(u.value,t)}return r;default:return n.value}},exports.valueToObjectRepresentation=u,exports.variablesInOperation=function(e){var n=new Set;if(e.variableDefinitions)for(var t=0,r=e.variableDefinitions;t<r.length;t++){var i=r[t];n.add(i.variable.name.value)}return n},exports.warnOnceInDevelopment=function(e,n){void 0===n&&(n="warn");L()||R[e]||(T()||(R[e]=!0),"error"===n?console.error(e):console.warn(e))},exports.canUseWeakMap=void 0;var e=require("graphql/language/visitor"),n=require("ts-invariant"),t=require("tslib"),r=o(require("fast-json-stable-stringify")),i=o(require("lodash.isequal"));function o(e){return e&&e.__esModule?e:{default:e}}function u(e,t,r,i){if(function(e){return"IntValue"===e.kind}(r)||function(e){return"FloatValue"===e.kind}(r))e[t.value]=Number(r.value);else if(function(e){return"BooleanValue"===e.kind}(r)||function(e){return"StringValue"===e.kind}(r))e[t.value]=r.value;else if(function(e){return"ObjectValue"===e.kind}(r)){var o={};r.fields.map(function(e){return u(o,e.name,e.value,i)}),e[t.value]=o}else if(function(e){return"Variable"===e.kind}(r)){var a=(i||{})[r.name.value];e[t.value]=a}else if(function(e){return"ListValue"===e.kind}(r))e[t.value]=r.values.map(function(e){var n={};return u(n,t,e,i),n[t.value]});else if(function(e){return"EnumValue"===e.kind}(r))e[t.value]=r.value;else{if(!function(e){return"NullValue"===e.kind}(r))throw new n.InvariantError(17);e[t.value]=null}}var a=["connection","include","skip","client","rest","export"];function c(e,n,t){if(t&&t.connection&&t.connection.key){if(t.connection.filter&&t.connection.filter.length>0){var i=t.connection.filter?t.connection.filter:[];i.sort();var o=n,u={};return i.forEach(function(e){u[e]=o[e]}),t.connection.key+"("+JSON.stringify(u)+")"}return t.connection.key}var c=e;if(n){var f=(0,r.default)(n);c+="("+f+")"}return t&&Object.keys(t).forEach(function(e){-1===a.indexOf(e)&&(t[e]&&Object.keys(t[e]).length?c+="@"+e+"("+JSON.stringify(t[e])+")":c+="@"+e)}),c}function f(e,n){if(e.arguments&&e.arguments.length){var t={};return e.arguments.forEach(function(e){var r=e.name,i=e.value;return u(t,r,i,n)}),t}return null}function l(e){return"Field"===e.kind}function s(e){return"InlineFragment"===e.kind}function v(e){throw new n.InvariantError(18)}function m(n){var t=[];return(0,e.visit)(n,{Directive:function(e){t.push(e.name.value)}}),t}function p(e,n){return m(n).some(function(n){return e.indexOf(n)>-1})}function d(e){var n=e.name.value;return"skip"===n||"include"===n}function g(e){return e?e.filter(d).map(function(e){var t=e.arguments;e.name.value;(0,n.invariant)(t&&1===t.length,2);var r=t[0];(0,n.invariant)(r.name&&"if"===r.name.value,3);var i=r.value;return(0,n.invariant)(i&&("Variable"===i.kind||"BooleanValue"===i.kind),4),{directive:e,ifArgument:r}}):[]}function x(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];return n.forEach(function(n){null!=n&&Object.keys(n).forEach(function(t){e[t]=n[t]})}),e}function h(e){(0,n.invariant)(e&&"Document"===e.kind,8);var t=e.definitions.filter(function(e){return"FragmentDefinition"!==e.kind}).map(function(e){if("OperationDefinition"!==e.kind)throw new n.InvariantError(9);return e});return(0,n.invariant)(t.length<=1,10),e}function y(e){return h(e),e.definitions.filter(function(e){return"OperationDefinition"===e.kind})[0]}function b(e){return e.definitions.filter(function(e){return"FragmentDefinition"===e.kind})}function D(e){(0,n.invariant)("Document"===e.kind,13),(0,n.invariant)(e.definitions.length<=1,14);var t=e.definitions[0];return(0,n.invariant)("FragmentDefinition"===t.kind,15),t}function k(e){var t;h(e);for(var r=0,i=e.definitions;r<i.length;r++){var o=i[r];if("OperationDefinition"===o.kind){var u=o.operation;if("query"===u||"mutation"===u||"subscription"===u)return o}"FragmentDefinition"!==o.kind||t||(t=o)}if(t)return t;throw new n.InvariantError(16)}function O(e){void 0===e&&(e=[]);var n={};return e.forEach(function(e){n[e.name.value]=e}),n}function F(e,n,t){var r=0;return e.forEach(function(t,i){n.call(this,t,i,e)&&(e[r++]=t)},t),e.length=r,e}var S={kind:"Field",name:{kind:"Name",value:"__typename"}};function E(e){return function e(n,t){return n.selectionSet.selections.every(function(n){return"FragmentSpread"===n.kind&&e(t[n.name.value],t)})}(y(e)||D(e),O(b(e)))?null:e}function V(e){return function(n){return e.some(function(e){return e.name&&e.name===n.name.value||e.test&&e.test(n)})}}function j(n,t){var r=Object.create(null),i=[],o=Object.create(null),u=[],a=E((0,e.visit)(t,{Variable:{enter:function(e,n,t){"VariableDefinition"!==t.kind&&(r[e.name.value]=!0)}},Field:{enter:function(e){if(n&&e.directives&&(n.some(function(e){return e.remove})&&e.directives&&e.directives.some(V(n))))return e.arguments&&e.arguments.forEach(function(e){"Variable"===e.value.kind&&i.push({name:e.value.name.value})}),e.selectionSet&&function e(n){var t=[];n.selections.forEach(function(n){(l(n)||s(n))&&n.selectionSet?e(n.selectionSet).forEach(function(e){return t.push(e)}):"FragmentSpread"===n.kind&&t.push(n)});return t}(e.selectionSet).forEach(function(e){u.push({name:e.name.value})}),null}},FragmentSpread:{enter:function(e){o[e.name.value]=!0}},Directive:{enter:function(e){if(V(n)(e))return null}}}));return a&&F(i,function(e){return!r[e.name]}).length&&(a=N(i,a)),a&&F(u,function(e){return!o[e.name]}).length&&(a=q(u,a)),a}var _={test:function(e){var n="connection"===e.name.value;return n&&(!e.arguments||e.arguments.some(function(e){return"key"===e.name.value})),n}};function w(e,n,t){return void 0===t&&(t=!0),n&&n.selections&&n.selections.some(function(n){return I(e,n,t)})}function I(e,n,t){return void 0===t&&(t=!0),!l(n)||!!n.directives&&(n.directives.some(V(e))||t&&w(e,n.selectionSet,t))}function N(n,r){var i=function(e){return function(n){return e.some(function(e){return n.value&&"Variable"===n.value.kind&&n.value.name&&(e.name===n.value.name.value||e.test&&e.test(n))})}}(n);return E((0,e.visit)(r,{OperationDefinition:{enter:function(e){return(0,t.__assign)({},e,{variableDefinitions:e.variableDefinitions.filter(function(e){return!n.some(function(n){return n.name===e.variable.name.value})})})}},Field:{enter:function(e){if(n.some(function(e){return e.remove})){var t=0;if(e.arguments.forEach(function(e){i(e)&&(t+=1)}),1===t)return null}}},Argument:{enter:function(e){if(i(e))return null}}}))}function q(n,t){function r(e){if(n.some(function(n){return n.name===e.name.value}))return null}return E((0,e.visit)(t,{FragmentSpread:{enter:r},FragmentDefinition:{enter:r}}))}var M="function"==typeof WeakMap&&!("object"==typeof navigator&&"ReactNative"===navigator.product);exports.canUseWeakMap=M;var A=Object.prototype.toString;function J(){return"undefined"!=typeof process?"production":"development"}function P(e){return J()===e}function L(){return!0===P("production")}function Q(){return!0===P("development")}function T(){return!0===P("test")}var W=Object.prototype.hasOwnProperty;function z(e){var n=e[0]||{},t=e.length;if(t>1){var r=[];n=K(n,r);for(var i=1;i<t;++i)n=C(n,e[i],r)}return n}function B(e){return null!==e&&"object"==typeof e}function C(e,n,t){return B(n)&&B(e)?(Object.isExtensible&&!Object.isExtensible(e)&&(e=K(e,t)),Object.keys(n).forEach(function(r){var i=n[r];if(W.call(e,r)){var o=e[r];i!==o&&(e[r]=C(K(o,t),i,t))}else e[r]=i}),e):n}function K(e,n){return null!==e&&"object"==typeof e&&n.indexOf(e)<0&&(e=Array.isArray(e)?e.slice(0):(0,t.__assign)({__proto__:Object.getPrototypeOf(e)},e),n.push(e)),e}var R=Object.create({});

@@ -5,2 +5,3 @@ import { visit } from 'graphql/language/visitor';

import stringify from 'fast-json-stable-stringify';
import isEqualLodash from 'lodash.isequal';

@@ -815,31 +816,3 @@ function isScalarValue(value) {

function isEqual(a, b) {
if (a === b) {
return true;
}
if (a instanceof Date && b instanceof Date) {
return a.getTime() === b.getTime();
}
if (a != null &&
typeof a === 'object' &&
b != null &&
typeof b === 'object') {
for (var key in a) {
if (Object.prototype.hasOwnProperty.call(a, key)) {
if (!Object.prototype.hasOwnProperty.call(b, key)) {
return false;
}
if (!isEqual(a[key], b[key])) {
return false;
}
}
}
for (var key in b) {
if (Object.prototype.hasOwnProperty.call(b, key) &&
!Object.prototype.hasOwnProperty.call(a, key)) {
return false;
}
}
return true;
}
return false;
return isEqualLodash(a, b);
}

@@ -846,0 +819,0 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('graphql/language/visitor'), require('ts-invariant'), require('tslib'), require('fast-json-stable-stringify')) :
typeof define === 'function' && define.amd ? define(['exports', 'graphql/language/visitor', 'ts-invariant', 'tslib', 'fast-json-stable-stringify'], factory) :
(global = global || self, factory(global['apollo.utilities'] = {}, global.visitor, global.invariant, global.tslib, global.stringify));
}(this, function (exports, visitor, tsInvariant, tslib, stringify) { 'use strict';
if (typeof define === "function" && define.amd) {
define(["exports", "graphql/language/visitor", "ts-invariant", "tslib", "fast-json-stable-stringify", "lodash.isequal"], factory);
} else if (typeof exports !== "undefined") {
factory(exports, require("graphql/language/visitor"), require("ts-invariant"), require("tslib"), require("fast-json-stable-stringify"), require("lodash.isequal"));
} else {
var mod = {
exports: {}
};
factory(mod.exports, global.visitor, global.tsInvariant, global.tslib, global.fastJsonStableStringify, global.lodash);
global.unknown = mod.exports;
}
})(this, function (_exports, _visitor, _tsInvariant, _tslib, _fastJsonStableStringify, _lodash) {
stringify = stringify && stringify.hasOwnProperty('default') ? stringify['default'] : stringify;
_exports.__esModule = true;
_exports.addTypenameToDocument = addTypenameToDocument;
_exports.argumentsObjectFromField = argumentsObjectFromField;
_exports.assign = assign;
_exports.buildQueryFromSelectionSet = buildQueryFromSelectionSet;
_exports.checkDocument = checkDocument;
_exports.cloneDeep = cloneDeep;
_exports.createFragmentMap = createFragmentMap;
_exports.getDefaultValues = getDefaultValues;
_exports.getDirectiveInfoFromField = getDirectiveInfoFromField;
_exports.getDirectiveNames = getDirectiveNames;
_exports.getDirectivesFromDocument = getDirectivesFromDocument;
_exports.getEnv = getEnv;
_exports.getFragmentDefinition = getFragmentDefinition;
_exports.getFragmentDefinitions = getFragmentDefinitions;
_exports.getFragmentQueryDocument = getFragmentQueryDocument;
_exports.getInclusionDirectives = getInclusionDirectives;
_exports.getMainDefinition = getMainDefinition;
_exports.getMutationDefinition = getMutationDefinition;
_exports.getOperationDefinition = getOperationDefinition;
_exports.getOperationDefinitionOrDie = getOperationDefinitionOrDie;
_exports.getOperationName = getOperationName;
_exports.getQueryDefinition = getQueryDefinition;
_exports.getStoreKeyName = getStoreKeyName;
_exports.graphQLResultHasError = graphQLResultHasError;
_exports.hasClientExports = hasClientExports;
_exports.hasDirectives = hasDirectives;
_exports.isDevelopment = isDevelopment;
_exports.isEnv = isEnv;
_exports.isEqual = isEqual;
_exports.isField = isField;
_exports.isIdValue = isIdValue;
_exports.isInlineFragment = isInlineFragment;
_exports.isJsonValue = isJsonValue;
_exports.isNumberValue = isNumberValue;
_exports.isProduction = isProduction;
_exports.isScalarValue = isScalarValue;
_exports.isTest = isTest;
_exports.maybeDeepFreeze = maybeDeepFreeze;
_exports.mergeDeep = mergeDeep;
_exports.mergeDeepArray = mergeDeepArray;
_exports.removeArgumentsFromDocument = removeArgumentsFromDocument;
_exports.removeClientSetsFromDocument = removeClientSetsFromDocument;
_exports.removeConnectionDirectiveFromDocument = removeConnectionDirectiveFromDocument;
_exports.removeDirectivesFromDocument = removeDirectivesFromDocument;
_exports.removeFragmentSpreadFromDocument = removeFragmentSpreadFromDocument;
_exports.resultKeyNameFromField = resultKeyNameFromField;
_exports.shouldInclude = shouldInclude;
_exports.storeKeyNameFromField = storeKeyNameFromField;
_exports.stripSymbols = stripSymbols;
_exports.toIdValue = toIdValue;
_exports.tryFunctionOrLogError = tryFunctionOrLogError;
_exports.valueFromNode = valueFromNode;
_exports.valueToObjectRepresentation = valueToObjectRepresentation;
_exports.variablesInOperation = variablesInOperation;
_exports.warnOnceInDevelopment = warnOnceInDevelopment;
_exports.canUseWeakMap = void 0;
_fastJsonStableStringify = _interopRequireDefault(_fastJsonStableStringify);
_lodash = _interopRequireDefault(_lodash);
function isScalarValue(value) {
return ['StringValue', 'BooleanValue', 'EnumValue'].indexOf(value.kind) > -1;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isScalarValue(value) {
return ['StringValue', 'BooleanValue', 'EnumValue'].indexOf(value.kind) > -1;
}
function isNumberValue(value) {
return ['IntValue', 'FloatValue'].indexOf(value.kind) > -1;
}
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 isNullValue(value) {
return value.kind === 'NullValue';
}
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 if (isNullValue(value)) {
argObj[name.value] = null;
} else {
throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(17) : new _tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" + 'is not supported. Use variables instead of inline arguments to ' + 'overcome this limitation.');
}
function isNumberValue(value) {
return ['IntValue', 'FloatValue'].indexOf(value.kind) > -1;
}
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);
});
}
});
}
function isStringValue(value) {
return value.kind === 'StringValue';
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);
});
}
function isBooleanValue(value) {
return value.kind === 'BooleanValue';
return getStoreKeyName(field.name.value, argObj, directivesObj);
}
var KNOWN_DIRECTIVES = ['connection', 'include', 'skip', 'client', 'rest', 'export'];
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'];
}
}
function isIntValue(value) {
return value.kind === 'IntValue';
var completeFieldName = fieldName;
if (args) {
var stringifiedArgs = (0, _fastJsonStableStringify.default)(args);
completeFieldName += "(" + stringifiedArgs + ")";
}
function isFloatValue(value) {
return value.kind === 'FloatValue';
if (directives) {
Object.keys(directives).forEach(function (key) {
if (KNOWN_DIRECTIVES.indexOf(key) !== -1) return;
if (directives[key] && Object.keys(directives[key]).length) {
completeFieldName += "@" + key + "(" + JSON.stringify(directives[key]) + ")";
} else {
completeFieldName += "@" + key;
}
});
}
function isVariable(value) {
return value.kind === 'Variable';
return completeFieldName;
}
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;
}
function isObjectValue(value) {
return value.kind === 'ObjectValue';
return null;
}
function resultKeyNameFromField(field) {
return field.alias ? field.alias.value : field.name.value;
}
function isField(selection) {
return selection.kind === 'Field';
}
function isInlineFragment(selection) {
return selection.kind === 'InlineFragment';
}
function isIdValue(idObject) {
return idObject && idObject.type === 'id' && typeof idObject.generated === 'boolean';
}
function toIdValue(idConfig, generated) {
if (generated === void 0) {
generated = false;
}
function isListValue(value) {
return value.kind === 'ListValue';
return (0, _tslib.__assign)({
type: 'id',
generated: generated
}, typeof idConfig === 'string' ? {
id: idConfig,
typename: undefined
} : idConfig);
}
function isJsonValue(jsonObject) {
return jsonObject != null && typeof jsonObject === 'object' && jsonObject.type === 'json';
}
function defaultValueFromVariable(node) {
throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(18) : new _tsInvariant.InvariantError("Variable nodes are not supported by valueFromNode");
}
function valueFromNode(node, onVariable) {
if (onVariable === void 0) {
onVariable = defaultValueFromVariable;
}
function isEnumValue(value) {
return value.kind === 'EnumValue';
}
function isNullValue(value) {
return value.kind === 'NullValue';
}
function valueToObjectRepresentation(argObj, name, value, variables) {
if (isIntValue(value) || isFloatValue(value)) {
argObj[name.value] = Number(value.value);
switch (node.kind) {
case 'Variable':
return onVariable(node);
case 'NullValue':
return null;
case 'IntValue':
return parseInt(node.value, 10);
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;
}
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 if (isNullValue(value)) {
argObj[name.value] = null;
}
else {
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(17) : new tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
'is not supported. Use variables instead of inline arguments to ' +
'overcome this limitation.');
}
default:
return node.value;
}
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);
}
function getDirectiveInfoFromField(field, variables) {
if (field.directives && field.directives.length) {
var directiveObj_1 = {};
field.directives.forEach(function (directive) {
directiveObj_1[directive.name.value] = argumentsObjectFromField(directive, variables);
});
return directiveObj_1;
}
var KNOWN_DIRECTIVES = [
'connection',
'include',
'skip',
'client',
'rest',
'export',
];
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'];
}
}
var completeFieldName = fieldName;
if (args) {
var stringifiedArgs = stringify(args);
completeFieldName += "(" + stringifiedArgs + ")";
}
if (directives) {
Object.keys(directives).forEach(function (key) {
if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
return;
if (directives[key] && Object.keys(directives[key]).length) {
completeFieldName += "@" + key + "(" + JSON.stringify(directives[key]) + ")";
}
else {
completeFieldName += "@" + key;
}
});
}
return completeFieldName;
return null;
}
function shouldInclude(selection, variables) {
if (variables === void 0) {
variables = {};
}
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;
return getInclusionDirectives(selection.directives).every(function (_a) {
var directive = _a.directive,
ifArgument = _a.ifArgument;
var evaledValue = false;
if (ifArgument.value.kind === 'Variable') {
evaledValue = variables[ifArgument.value.name.value];
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(evaledValue !== void 0, 1) : (0, _tsInvariant.invariant)(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.");
} else {
evaledValue = ifArgument.value.value;
}
return directive.name.value === 'skip' ? !evaledValue : evaledValue;
});
}
function getDirectiveNames(doc) {
var names = [];
(0, _visitor.visit)(doc, {
Directive: function (node) {
names.push(node.name.value);
}
});
return names;
}
function hasDirectives(names, doc) {
return getDirectiveNames(doc).some(function (name) {
return names.indexOf(name) > -1;
});
}
function hasClientExports(document) {
return document && hasDirectives(['client'], document) && hasDirectives(['export'], document);
}
function isInclusionDirective(_a) {
var value = _a.name.value;
return value === 'skip' || value === 'include';
}
function getInclusionDirectives(directives) {
return directives ? directives.filter(isInclusionDirective).map(function (directive) {
var directiveArguments = directive.arguments;
var directiveName = directive.name.value;
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(directiveArguments && directiveArguments.length === 1, 2) : (0, _tsInvariant.invariant)(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
var ifArgument = directiveArguments[0];
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(ifArgument.name && ifArgument.name.value === 'if', 3) : (0, _tsInvariant.invariant)(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.");
var ifValue = ifArgument.value;
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(ifValue && (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 4) : (0, _tsInvariant.invariant)(ifValue && (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.");
return {
directive: directive,
ifArgument: ifArgument
};
}) : [];
}
function getFragmentQueryDocument(document, fragmentName) {
var actualFragmentName = fragmentName;
var fragments = [];
document.definitions.forEach(function (definition) {
if (definition.kind === 'OperationDefinition') {
throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(5) : new _tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " + 'No operations are allowed when using a fragment as a query. Only fragments are allowed.');
}
if (definition.kind === 'FragmentDefinition') {
fragments.push(definition);
}
});
if (typeof actualFragmentName === 'undefined') {
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(fragments.length === 1, 6) : (0, _tsInvariant.invariant)(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
actualFragmentName = fragments[0].name.value;
}
function resultKeyNameFromField(field) {
return field.alias ? field.alias.value : field.name.value;
}
function isField(selection) {
return selection.kind === 'Field';
}
function isInlineFragment(selection) {
return selection.kind === 'InlineFragment';
}
function isIdValue(idObject) {
return idObject &&
idObject.type === 'id' &&
typeof idObject.generated === 'boolean';
}
function toIdValue(idConfig, generated) {
if (generated === void 0) { generated = false; }
return tslib.__assign({ type: 'id', generated: generated }, (typeof idConfig === 'string'
? { id: idConfig, typename: undefined }
: idConfig));
}
function isJsonValue(jsonObject) {
return (jsonObject != null &&
typeof jsonObject === 'object' &&
jsonObject.type === 'json');
}
function defaultValueFromVariable(node) {
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(18) : new tsInvariant.InvariantError("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, 10);
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;
var query = (0, _tslib.__assign)({}, document, {
definitions: [{
kind: 'OperationDefinition',
operation: 'query',
selectionSet: {
kind: 'SelectionSet',
selections: [{
kind: 'FragmentSpread',
name: {
kind: 'Name',
value: actualFragmentName
}
default:
return node.value;
}]
}
}].concat(document.definitions)
});
return query;
}
function assign(target) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
}
function getDirectiveInfoFromField(field, variables) {
if (field.directives && field.directives.length) {
var directiveObj_1 = {};
field.directives.forEach(function (directive) {
directiveObj_1[directive.name.value] = argumentsObjectFromField(directive, variables);
});
return directiveObj_1;
sources.forEach(function (source) {
if (typeof source === 'undefined' || source === null) {
return;
}
Object.keys(source).forEach(function (key) {
target[key] = source[key];
});
});
return target;
}
function getMutationDefinition(doc) {
checkDocument(doc);
var mutationDef = doc.definitions.filter(function (definition) {
return definition.kind === 'OperationDefinition' && definition.operation === 'mutation';
})[0];
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(mutationDef, 7) : (0, _tsInvariant.invariant)(mutationDef, 'Must contain a mutation definition.');
return mutationDef;
}
function checkDocument(doc) {
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(doc && doc.kind === 'Document', 8) : (0, _tsInvariant.invariant)(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
var operations = doc.definitions.filter(function (d) {
return d.kind !== 'FragmentDefinition';
}).map(function (definition) {
if (definition.kind !== 'OperationDefinition') {
throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(9) : new _tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
}
return definition;
});
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(operations.length <= 1, 10) : (0, _tsInvariant.invariant)(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations");
return doc;
}
function getOperationDefinition(doc) {
checkDocument(doc);
return doc.definitions.filter(function (definition) {
return definition.kind === 'OperationDefinition';
})[0];
}
function getOperationDefinitionOrDie(document) {
var def = getOperationDefinition(document);
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(def, 11) : (0, _tsInvariant.invariant)(def, "GraphQL document is missing an operation");
return def;
}
function getOperationName(doc) {
return doc.definitions.filter(function (definition) {
return definition.kind === 'OperationDefinition' && definition.name;
}).map(function (x) {
return x.name.value;
})[0] || null;
}
function getFragmentDefinitions(doc) {
return doc.definitions.filter(function (definition) {
return definition.kind === 'FragmentDefinition';
});
}
function getQueryDefinition(doc) {
var queryDef = getOperationDefinition(doc);
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(queryDef && queryDef.operation === 'query', 12) : (0, _tsInvariant.invariant)(queryDef && queryDef.operation === 'query', 'Must contain a query definition.');
return queryDef;
}
function getFragmentDefinition(doc) {
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(doc.kind === 'Document', 13) : (0, _tsInvariant.invariant)(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(doc.definitions.length <= 1, 14) : (0, _tsInvariant.invariant)(doc.definitions.length <= 1, 'Fragment must have exactly one definition.');
var fragmentDef = doc.definitions[0];
process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(fragmentDef.kind === 'FragmentDefinition', 15) : (0, _tsInvariant.invariant)(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.');
return fragmentDef;
}
function getMainDefinition(queryDoc) {
checkDocument(queryDoc);
var fragmentDefinition;
for (var _i = 0, _a = queryDoc.definitions; _i < _a.length; _i++) {
var definition = _a[_i];
if (definition.kind === 'OperationDefinition') {
var operation = definition.operation;
if (operation === 'query' || operation === 'mutation' || operation === 'subscription') {
return definition;
}
return null;
}
if (definition.kind === 'FragmentDefinition' && !fragmentDefinition) {
fragmentDefinition = definition;
}
}
function shouldInclude(selection, variables) {
if (variables === void 0) { variables = {}; }
return getInclusionDirectives(selection.directives).every(function (_a) {
var directive = _a.directive, ifArgument = _a.ifArgument;
var evaledValue = false;
if (ifArgument.value.kind === 'Variable') {
evaledValue = variables[ifArgument.value.name.value];
process.env.NODE_ENV === "production" ? tsInvariant.invariant(evaledValue !== void 0, 1) : tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.");
}
else {
evaledValue = ifArgument.value.value;
}
return directive.name.value === 'skip' ? !evaledValue : evaledValue;
});
if (fragmentDefinition) {
return fragmentDefinition;
}
function getDirectiveNames(doc) {
var names = [];
visitor.visit(doc, {
Directive: function (node) {
names.push(node.name.value);
},
});
return names;
throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(16) : new _tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.');
}
function createFragmentMap(fragments) {
if (fragments === void 0) {
fragments = [];
}
function hasDirectives(names, doc) {
return getDirectiveNames(doc).some(function (name) { return names.indexOf(name) > -1; });
var symTable = {};
fragments.forEach(function (fragment) {
symTable[fragment.name.value] = fragment;
});
return symTable;
}
function getDefaultValues(definition) {
if (definition && definition.variableDefinitions && definition.variableDefinitions.length) {
var defaultValues = definition.variableDefinitions.filter(function (_a) {
var defaultValue = _a.defaultValue;
return defaultValue;
}).map(function (_a) {
var variable = _a.variable,
defaultValue = _a.defaultValue;
var defaultValueObj = {};
valueToObjectRepresentation(defaultValueObj, variable.name, defaultValue);
return defaultValueObj;
});
return assign.apply(void 0, [{}].concat(defaultValues));
}
function hasClientExports(document) {
return (document &&
hasDirectives(['client'], document) &&
hasDirectives(['export'], document));
return {};
}
function variablesInOperation(operation) {
var names = new Set();
if (operation.variableDefinitions) {
for (var _i = 0, _a = operation.variableDefinitions; _i < _a.length; _i++) {
var definition = _a[_i];
names.add(definition.variable.name.value);
}
}
function isInclusionDirective(_a) {
var value = _a.name.value;
return value === 'skip' || value === 'include';
}
function getInclusionDirectives(directives) {
return directives ? directives.filter(isInclusionDirective).map(function (directive) {
var directiveArguments = directive.arguments;
var directiveName = directive.name.value;
process.env.NODE_ENV === "production" ? tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, 2) : tsInvariant.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
var ifArgument = directiveArguments[0];
process.env.NODE_ENV === "production" ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', 3) : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.");
var ifValue = ifArgument.value;
process.env.NODE_ENV === "production" ? tsInvariant.invariant(ifValue &&
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 4) : tsInvariant.invariant(ifValue &&
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.");
return { directive: directive, ifArgument: ifArgument };
}) : [];
}
function getFragmentQueryDocument(document, fragmentName) {
var actualFragmentName = fragmentName;
var fragments = [];
document.definitions.forEach(function (definition) {
if (definition.kind === 'OperationDefinition') {
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(5) : new tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
'No operations are allowed when using a fragment as a query. Only fragments are allowed.');
}
if (definition.kind === 'FragmentDefinition') {
fragments.push(definition);
}
});
if (typeof actualFragmentName === 'undefined') {
process.env.NODE_ENV === "production" ? tsInvariant.invariant(fragments.length === 1, 6) : tsInvariant.invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
actualFragmentName = fragments[0].name.value;
}
var query = tslib.__assign({}, document, { definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'FragmentSpread',
name: {
kind: 'Name',
value: actualFragmentName,
},
},
],
},
}
].concat(document.definitions) });
return query;
return names;
}
function filterInPlace(array, test, context) {
var target = 0;
array.forEach(function (elem, i) {
if (test.call(this, elem, i, array)) {
array[target++] = elem;
}
}, context);
array.length = target;
return array;
}
var TYPENAME_FIELD = {
kind: 'Field',
name: {
kind: 'Name',
value: '__typename'
}
};
function assign(target) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
function isEmpty(op, fragments) {
return op.selectionSet.selections.every(function (selection) {
return selection.kind === 'FragmentSpread' && isEmpty(fragments[selection.name.value], fragments);
});
}
function nullIfDocIsEmpty(doc) {
return isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc))) ? null : doc;
}
function getDirectiveMatcher(directives) {
return function directiveMatcher(directive) {
return directives.some(function (dir) {
return dir.name && dir.name === directive.name.value || dir.test && dir.test(directive);
});
};
}
function removeDirectivesFromDocument(directives, doc) {
var variablesInUse = Object.create(null);
var variablesToRemove = [];
var fragmentSpreadsInUse = Object.create(null);
var fragmentSpreadsToRemove = [];
var modifiedDoc = nullIfDocIsEmpty((0, _visitor.visit)(doc, {
Variable: {
enter: function (node, _key, parent) {
if (parent.kind !== 'VariableDefinition') {
variablesInUse[node.name.value] = true;
}
}
sources.forEach(function (source) {
if (typeof source === 'undefined' || source === null) {
return;
}
Object.keys(source).forEach(function (key) {
target[key] = source[key];
},
Field: {
enter: function (node) {
if (directives && node.directives) {
var shouldRemoveField = directives.some(function (directive) {
return directive.remove;
});
});
return target;
}
function getMutationDefinition(doc) {
checkDocument(doc);
var mutationDef = doc.definitions.filter(function (definition) {
return definition.kind === 'OperationDefinition' &&
definition.operation === 'mutation';
})[0];
process.env.NODE_ENV === "production" ? tsInvariant.invariant(mutationDef, 7) : tsInvariant.invariant(mutationDef, 'Must contain a mutation definition.');
return mutationDef;
}
function checkDocument(doc) {
process.env.NODE_ENV === "production" ? tsInvariant.invariant(doc && doc.kind === 'Document', 8) : tsInvariant.invariant(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
var operations = doc.definitions
.filter(function (d) { return d.kind !== 'FragmentDefinition'; })
.map(function (definition) {
if (definition.kind !== 'OperationDefinition') {
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(9) : new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
if (shouldRemoveField && node.directives && node.directives.some(getDirectiveMatcher(directives))) {
if (node.arguments) {
node.arguments.forEach(function (arg) {
if (arg.value.kind === 'Variable') {
variablesToRemove.push({
name: arg.value.name.value
});
}
});
}
if (node.selectionSet) {
getAllFragmentSpreadsFromSelectionSet(node.selectionSet).forEach(function (frag) {
fragmentSpreadsToRemove.push({
name: frag.name.value
});
});
}
return null;
}
return definition;
});
process.env.NODE_ENV === "production" ? tsInvariant.invariant(operations.length <= 1, 10) : tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations");
return doc;
}
function getOperationDefinition(doc) {
checkDocument(doc);
return doc.definitions.filter(function (definition) { return definition.kind === 'OperationDefinition'; })[0];
}
function getOperationDefinitionOrDie(document) {
var def = getOperationDefinition(document);
process.env.NODE_ENV === "production" ? tsInvariant.invariant(def, 11) : tsInvariant.invariant(def, "GraphQL document is missing an operation");
return def;
}
function getOperationName(doc) {
return (doc.definitions
.filter(function (definition) {
return definition.kind === 'OperationDefinition' && definition.name;
})
.map(function (x) { return x.name.value; })[0] || null);
}
function getFragmentDefinitions(doc) {
return doc.definitions.filter(function (definition) { return definition.kind === 'FragmentDefinition'; });
}
function getQueryDefinition(doc) {
var queryDef = getOperationDefinition(doc);
process.env.NODE_ENV === "production" ? tsInvariant.invariant(queryDef && queryDef.operation === 'query', 12) : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.');
return queryDef;
}
function getFragmentDefinition(doc) {
process.env.NODE_ENV === "production" ? tsInvariant.invariant(doc.kind === 'Document', 13) : tsInvariant.invariant(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
process.env.NODE_ENV === "production" ? tsInvariant.invariant(doc.definitions.length <= 1, 14) : tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.');
var fragmentDef = doc.definitions[0];
process.env.NODE_ENV === "production" ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 15) : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.');
return fragmentDef;
}
function getMainDefinition(queryDoc) {
checkDocument(queryDoc);
var fragmentDefinition;
for (var _i = 0, _a = queryDoc.definitions; _i < _a.length; _i++) {
var definition = _a[_i];
if (definition.kind === 'OperationDefinition') {
var operation = definition.operation;
if (operation === 'query' ||
operation === 'mutation' ||
operation === 'subscription') {
return definition;
}
}
if (definition.kind === 'FragmentDefinition' && !fragmentDefinition) {
fragmentDefinition = definition;
}
}
}
if (fragmentDefinition) {
return fragmentDefinition;
},
FragmentSpread: {
enter: function (node) {
fragmentSpreadsInUse[node.name.value] = true;
}
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(16) : new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.');
},
Directive: {
enter: function (node) {
if (getDirectiveMatcher(directives)(node)) {
return null;
}
}
}
}));
if (modifiedDoc && filterInPlace(variablesToRemove, function (v) {
return !variablesInUse[v.name];
}).length) {
modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);
}
function createFragmentMap(fragments) {
if (fragments === void 0) { fragments = []; }
var symTable = {};
fragments.forEach(function (fragment) {
symTable[fragment.name.value] = fragment;
});
return symTable;
if (modifiedDoc && filterInPlace(fragmentSpreadsToRemove, function (fs) {
return !fragmentSpreadsInUse[fs.name];
}).length) {
modifiedDoc = removeFragmentSpreadFromDocument(fragmentSpreadsToRemove, modifiedDoc);
}
function getDefaultValues(definition) {
if (definition &&
definition.variableDefinitions &&
definition.variableDefinitions.length) {
var defaultValues = definition.variableDefinitions
.filter(function (_a) {
var defaultValue = _a.defaultValue;
return defaultValue;
})
.map(function (_a) {
var variable = _a.variable, defaultValue = _a.defaultValue;
var defaultValueObj = {};
valueToObjectRepresentation(defaultValueObj, variable.name, defaultValue);
return defaultValueObj;
});
return assign.apply(void 0, [{}].concat(defaultValues));
return modifiedDoc;
}
function addTypenameToDocument(doc) {
return (0, _visitor.visit)(checkDocument(doc), {
SelectionSet: {
enter: function (node, _key, parent) {
if (parent && parent.kind === 'OperationDefinition') {
return;
}
var selections = node.selections;
if (!selections) {
return;
}
var skip = selections.some(function (selection) {
return isField(selection) && (selection.name.value === '__typename' || selection.name.value.lastIndexOf('__', 0) === 0);
});
if (skip) {
return;
}
var field = parent;
if (isField(field) && field.directives && field.directives.some(function (d) {
return d.name.value === 'export';
})) {
return;
}
return (0, _tslib.__assign)({}, node, {
selections: selections.concat([TYPENAME_FIELD])
});
}
return {};
}
function variablesInOperation(operation) {
var names = new Set();
if (operation.variableDefinitions) {
for (var _i = 0, _a = operation.variableDefinitions; _i < _a.length; _i++) {
var definition = _a[_i];
names.add(definition.variable.name.value);
}
}
});
}
var connectionRemoveConfig = {
test: function (directive) {
var willRemove = directive.name.value === 'connection';
if (willRemove) {
if (!directive.arguments || !directive.arguments.some(function (arg) {
return arg.name.value === 'key';
})) {
process.env.NODE_ENV === "production" || _tsInvariant.invariant.warn('Removing an @connection directive even though it does not have a key. ' + 'You may want to use the key parameter to specify a store key.');
}
return names;
}
return willRemove;
}
};
function filterInPlace(array, test, context) {
var target = 0;
array.forEach(function (elem, i) {
if (test.call(this, elem, i, array)) {
array[target++] = elem;
}
}, context);
array.length = target;
return array;
function removeConnectionDirectiveFromDocument(doc) {
return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
}
function hasDirectivesInSelectionSet(directives, selectionSet, nestedCheck) {
if (nestedCheck === void 0) {
nestedCheck = true;
}
var TYPENAME_FIELD = {
kind: 'Field',
name: {
kind: 'Name',
value: '__typename',
},
};
function isEmpty(op, fragments) {
return op.selectionSet.selections.every(function (selection) {
return selection.kind === 'FragmentSpread' &&
isEmpty(fragments[selection.name.value], fragments);
});
return selectionSet && selectionSet.selections && selectionSet.selections.some(function (selection) {
return hasDirectivesInSelection(directives, selection, nestedCheck);
});
}
function hasDirectivesInSelection(directives, selection, nestedCheck) {
if (nestedCheck === void 0) {
nestedCheck = true;
}
function nullIfDocIsEmpty(doc) {
return isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc)))
? null
: doc;
if (!isField(selection)) {
return true;
}
function getDirectiveMatcher(directives) {
return function directiveMatcher(directive) {
return directives.some(function (dir) {
return (dir.name && dir.name === directive.name.value) ||
(dir.test && dir.test(directive));
});
};
if (!selection.directives) {
return false;
}
function removeDirectivesFromDocument(directives, doc) {
var variablesInUse = Object.create(null);
var variablesToRemove = [];
var fragmentSpreadsInUse = Object.create(null);
var fragmentSpreadsToRemove = [];
var modifiedDoc = nullIfDocIsEmpty(visitor.visit(doc, {
Variable: {
enter: function (node, _key, parent) {
if (parent.kind !== 'VariableDefinition') {
variablesInUse[node.name.value] = true;
}
},
},
Field: {
enter: function (node) {
if (directives && node.directives) {
var shouldRemoveField = directives.some(function (directive) { return directive.remove; });
if (shouldRemoveField &&
node.directives &&
node.directives.some(getDirectiveMatcher(directives))) {
if (node.arguments) {
node.arguments.forEach(function (arg) {
if (arg.value.kind === 'Variable') {
variablesToRemove.push({
name: arg.value.name.value,
});
}
});
}
if (node.selectionSet) {
getAllFragmentSpreadsFromSelectionSet(node.selectionSet).forEach(function (frag) {
fragmentSpreadsToRemove.push({
name: frag.name.value,
});
});
}
return null;
}
}
},
},
FragmentSpread: {
enter: function (node) {
fragmentSpreadsInUse[node.name.value] = true;
},
},
Directive: {
enter: function (node) {
if (getDirectiveMatcher(directives)(node)) {
return null;
}
},
},
}));
if (modifiedDoc &&
filterInPlace(variablesToRemove, function (v) { return !variablesInUse[v.name]; }).length) {
modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);
return selection.directives.some(getDirectiveMatcher(directives)) || nestedCheck && hasDirectivesInSelectionSet(directives, selection.selectionSet, nestedCheck);
}
function getDirectivesFromDocument(directives, doc) {
checkDocument(doc);
var parentPath;
return nullIfDocIsEmpty((0, _visitor.visit)(doc, {
SelectionSet: {
enter: function (node, _key, _parent, path) {
var currentPath = path.join('-');
if (!parentPath || currentPath === parentPath || !currentPath.startsWith(parentPath)) {
if (node.selections) {
var selectionsWithDirectives = node.selections.filter(function (selection) {
return hasDirectivesInSelection(directives, selection);
});
if (hasDirectivesInSelectionSet(directives, node, false)) {
parentPath = currentPath;
}
return (0, _tslib.__assign)({}, node, {
selections: selectionsWithDirectives
});
} else {
return null;
}
}
}
if (modifiedDoc &&
filterInPlace(fragmentSpreadsToRemove, function (fs) { return !fragmentSpreadsInUse[fs.name]; })
.length) {
modifiedDoc = removeFragmentSpreadFromDocument(fragmentSpreadsToRemove, modifiedDoc);
}
return modifiedDoc;
}
function addTypenameToDocument(doc) {
return visitor.visit(checkDocument(doc), {
SelectionSet: {
enter: function (node, _key, parent) {
if (parent &&
parent.kind === 'OperationDefinition') {
return;
}
var selections = node.selections;
if (!selections) {
return;
}
var skip = selections.some(function (selection) {
return (isField(selection) &&
(selection.name.value === '__typename' ||
selection.name.value.lastIndexOf('__', 0) === 0));
});
if (skip) {
return;
}
var field = parent;
if (isField(field) &&
field.directives &&
field.directives.some(function (d) { return d.name.value === 'export'; })) {
return;
}
return tslib.__assign({}, node, { selections: selections.concat([TYPENAME_FIELD]) });
},
},
});
}
var connectionRemoveConfig = {
test: function (directive) {
var willRemove = directive.name.value === 'connection';
if (willRemove) {
if (!directive.arguments ||
!directive.arguments.some(function (arg) { return arg.name.value === 'key'; })) {
process.env.NODE_ENV === "production" || tsInvariant.invariant.warn('Removing an @connection directive even though it does not have a key. ' +
'You may want to use the key parameter to specify a store key.');
}
}
return willRemove;
},
}
}));
}
function getArgumentMatcher(config) {
return function argumentMatcher(argument) {
return config.some(function (aConfig) {
return argument.value && argument.value.kind === 'Variable' && argument.value.name && (aConfig.name === argument.value.name.value || aConfig.test && aConfig.test(argument));
});
};
function removeConnectionDirectiveFromDocument(doc) {
return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
}
function hasDirectivesInSelectionSet(directives, selectionSet, nestedCheck) {
if (nestedCheck === void 0) { nestedCheck = true; }
return (selectionSet &&
selectionSet.selections &&
selectionSet.selections.some(function (selection) {
return hasDirectivesInSelection(directives, selection, nestedCheck);
}));
}
function hasDirectivesInSelection(directives, selection, nestedCheck) {
if (nestedCheck === void 0) { nestedCheck = true; }
if (!isField(selection)) {
return true;
}
function removeArgumentsFromDocument(config, doc) {
var argMatcher = getArgumentMatcher(config);
return nullIfDocIsEmpty((0, _visitor.visit)(doc, {
OperationDefinition: {
enter: function (node) {
return (0, _tslib.__assign)({}, node, {
variableDefinitions: node.variableDefinitions.filter(function (varDef) {
return !config.some(function (arg) {
return arg.name === varDef.variable.name.value;
});
})
});
}
if (!selection.directives) {
return false;
}
return (selection.directives.some(getDirectiveMatcher(directives)) ||
(nestedCheck &&
hasDirectivesInSelectionSet(directives, selection.selectionSet, nestedCheck)));
}
function getDirectivesFromDocument(directives, doc) {
checkDocument(doc);
var parentPath;
return nullIfDocIsEmpty(visitor.visit(doc, {
SelectionSet: {
enter: function (node, _key, _parent, path) {
var currentPath = path.join('-');
if (!parentPath ||
currentPath === parentPath ||
!currentPath.startsWith(parentPath)) {
if (node.selections) {
var selectionsWithDirectives = node.selections.filter(function (selection) { return hasDirectivesInSelection(directives, selection); });
if (hasDirectivesInSelectionSet(directives, node, false)) {
parentPath = currentPath;
}
return tslib.__assign({}, node, { selections: selectionsWithDirectives });
}
else {
return null;
}
}
},
},
}));
}
function getArgumentMatcher(config) {
return function argumentMatcher(argument) {
return config.some(function (aConfig) {
return argument.value &&
argument.value.kind === 'Variable' &&
argument.value.name &&
(aConfig.name === argument.value.name.value ||
(aConfig.test && aConfig.test(argument)));
},
Field: {
enter: function (node) {
var shouldRemoveField = config.some(function (argConfig) {
return argConfig.remove;
});
if (shouldRemoveField) {
var argMatchCount_1 = 0;
node.arguments.forEach(function (arg) {
if (argMatcher(arg)) {
argMatchCount_1 += 1;
}
});
};
}
function removeArgumentsFromDocument(config, doc) {
var argMatcher = getArgumentMatcher(config);
return nullIfDocIsEmpty(visitor.visit(doc, {
OperationDefinition: {
enter: function (node) {
return tslib.__assign({}, node, { variableDefinitions: node.variableDefinitions.filter(function (varDef) {
return !config.some(function (arg) { return arg.name === varDef.variable.name.value; });
}) });
},
},
Field: {
enter: function (node) {
var shouldRemoveField = config.some(function (argConfig) { return argConfig.remove; });
if (shouldRemoveField) {
var argMatchCount_1 = 0;
node.arguments.forEach(function (arg) {
if (argMatcher(arg)) {
argMatchCount_1 += 1;
}
});
if (argMatchCount_1 === 1) {
return null;
}
}
},
},
Argument: {
enter: function (node) {
if (argMatcher(node)) {
return null;
}
},
},
}));
}
function removeFragmentSpreadFromDocument(config, doc) {
function enter(node) {
if (config.some(function (def) { return def.name === node.name.value; })) {
return null;
if (argMatchCount_1 === 1) {
return null;
}
}
}
return nullIfDocIsEmpty(visitor.visit(doc, {
FragmentSpread: { enter: enter },
FragmentDefinition: { enter: enter },
}));
},
Argument: {
enter: function (node) {
if (argMatcher(node)) {
return null;
}
}
}
}));
}
function removeFragmentSpreadFromDocument(config, doc) {
function enter(node) {
if (config.some(function (def) {
return def.name === node.name.value;
})) {
return null;
}
}
function getAllFragmentSpreadsFromSelectionSet(selectionSet) {
var allFragments = [];
selectionSet.selections.forEach(function (selection) {
if ((isField(selection) || isInlineFragment(selection)) &&
selection.selectionSet) {
getAllFragmentSpreadsFromSelectionSet(selection.selectionSet).forEach(function (frag) { return allFragments.push(frag); });
}
else if (selection.kind === 'FragmentSpread') {
allFragments.push(selection);
}
return nullIfDocIsEmpty((0, _visitor.visit)(doc, {
FragmentSpread: {
enter: enter
},
FragmentDefinition: {
enter: enter
}
}));
}
function getAllFragmentSpreadsFromSelectionSet(selectionSet) {
var allFragments = [];
selectionSet.selections.forEach(function (selection) {
if ((isField(selection) || isInlineFragment(selection)) && selection.selectionSet) {
getAllFragmentSpreadsFromSelectionSet(selection.selectionSet).forEach(function (frag) {
return allFragments.push(frag);
});
return allFragments;
} else if (selection.kind === 'FragmentSpread') {
allFragments.push(selection);
}
});
return allFragments;
}
function buildQueryFromSelectionSet(document) {
var definition = getMainDefinition(document);
var definitionOperation = definition.operation;
if (definitionOperation === 'query') {
return document;
}
function buildQueryFromSelectionSet(document) {
var definition = getMainDefinition(document);
var definitionOperation = definition.operation;
if (definitionOperation === 'query') {
return document;
var modifiedDoc = (0, _visitor.visit)(document, {
OperationDefinition: {
enter: function (node) {
return (0, _tslib.__assign)({}, node, {
operation: 'query'
});
}
var modifiedDoc = visitor.visit(document, {
OperationDefinition: {
enter: function (node) {
return tslib.__assign({}, node, { operation: 'query' });
},
},
});
return modifiedDoc;
}
function removeClientSetsFromDocument(document) {
checkDocument(document);
var modifiedDoc = removeDirectivesFromDocument([
{
test: function (directive) { return directive.name.value === 'client'; },
remove: true,
},
], document);
if (modifiedDoc) {
modifiedDoc = visitor.visit(modifiedDoc, {
FragmentDefinition: {
enter: function (node) {
if (node.selectionSet) {
var isTypenameOnly = node.selectionSet.selections.every(function (selection) {
return isField(selection) && selection.name.value === '__typename';
});
if (isTypenameOnly) {
return null;
}
}
},
},
});
}
return modifiedDoc;
}
}
});
return modifiedDoc;
}
var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
navigator.product === 'ReactNative');
function removeClientSetsFromDocument(document) {
checkDocument(document);
var modifiedDoc = removeDirectivesFromDocument([{
test: function (directive) {
return directive.name.value === 'client';
},
remove: true
}], document);
var toString = Object.prototype.toString;
function cloneDeep(value) {
return cloneDeepHelper(value, new Map());
}
function cloneDeepHelper(val, seen) {
switch (toString.call(val)) {
case "[object Array]": {
if (seen.has(val))
return seen.get(val);
var copy_1 = val.slice(0);
seen.set(val, copy_1);
copy_1.forEach(function (child, i) {
copy_1[i] = cloneDeepHelper(child, seen);
});
return copy_1;
if (modifiedDoc) {
modifiedDoc = (0, _visitor.visit)(modifiedDoc, {
FragmentDefinition: {
enter: function (node) {
if (node.selectionSet) {
var isTypenameOnly = node.selectionSet.selections.every(function (selection) {
return isField(selection) && selection.name.value === '__typename';
});
if (isTypenameOnly) {
return null;
}
}
case "[object Object]": {
if (seen.has(val))
return seen.get(val);
var copy_2 = Object.create(Object.getPrototypeOf(val));
seen.set(val, copy_2);
Object.keys(val).forEach(function (key) {
copy_2[key] = cloneDeepHelper(val[key], seen);
});
return copy_2;
}
default:
return val;
}
}
});
}
function getEnv() {
if (typeof process !== 'undefined' && process.env.NODE_ENV) {
return process.env.NODE_ENV;
return modifiedDoc;
}
var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' && navigator.product === 'ReactNative');
_exports.canUseWeakMap = canUseWeakMap;
var toString = Object.prototype.toString;
function cloneDeep(value) {
return cloneDeepHelper(value, new Map());
}
function cloneDeepHelper(val, seen) {
switch (toString.call(val)) {
case "[object Array]":
{
if (seen.has(val)) return seen.get(val);
var copy_1 = val.slice(0);
seen.set(val, copy_1);
copy_1.forEach(function (child, i) {
copy_1[i] = cloneDeepHelper(child, seen);
});
return copy_1;
}
return 'development';
}
function isEnv(env) {
return getEnv() === env;
}
function isProduction() {
return isEnv('production') === true;
}
function isDevelopment() {
return isEnv('development') === true;
}
function isTest() {
return isEnv('test') === true;
}
function tryFunctionOrLogError(f) {
try {
return f();
case "[object Object]":
{
if (seen.has(val)) return seen.get(val);
var copy_2 = Object.create(Object.getPrototypeOf(val));
seen.set(val, copy_2);
Object.keys(val).forEach(function (key) {
copy_2[key] = cloneDeepHelper(val[key], seen);
});
return copy_2;
}
catch (e) {
if (console.error) {
console.error(e);
}
}
default:
return val;
}
function graphQLResultHasError(result) {
return result.errors && result.errors.length;
}
function getEnv() {
if (typeof process !== 'undefined' && process.env.NODE_ENV) {
return process.env.NODE_ENV;
}
function isEqual(a, b) {
if (a === b) {
return true;
}
if (a instanceof Date && b instanceof Date) {
return a.getTime() === b.getTime();
}
if (a != null &&
typeof a === 'object' &&
b != null &&
typeof b === 'object') {
for (var key in a) {
if (Object.prototype.hasOwnProperty.call(a, key)) {
if (!Object.prototype.hasOwnProperty.call(b, key)) {
return false;
}
if (!isEqual(a[key], b[key])) {
return false;
}
}
}
for (var key in b) {
if (Object.prototype.hasOwnProperty.call(b, key) &&
!Object.prototype.hasOwnProperty.call(a, key)) {
return false;
}
}
return true;
}
return false;
return 'development';
}
function isEnv(env) {
return getEnv() === env;
}
function isProduction() {
return isEnv('production') === true;
}
function isDevelopment() {
return isEnv('development') === true;
}
function isTest() {
return isEnv('test') === true;
}
function tryFunctionOrLogError(f) {
try {
return f();
} catch (e) {
if (console.error) {
console.error(e);
}
}
}
function deepFreeze(o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach(function (prop) {
if (o[prop] !== null &&
(typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
!Object.isFrozen(o[prop])) {
deepFreeze(o[prop]);
}
});
return o;
function graphQLResultHasError(result) {
return result.errors && result.errors.length;
}
function isEqual(a, b) {
return (0, _lodash.default)(a, b);
}
function deepFreeze(o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach(function (prop) {
if (o[prop] !== null && (typeof o[prop] === 'object' || typeof o[prop] === 'function') && !Object.isFrozen(o[prop])) {
deepFreeze(o[prop]);
}
});
return o;
}
function maybeDeepFreeze(obj) {
if (isDevelopment() || isTest()) {
var symbolIsPolyfilled = typeof Symbol === 'function' && typeof Symbol('') === 'string';
if (!symbolIsPolyfilled) {
return deepFreeze(obj);
}
}
function maybeDeepFreeze(obj) {
if (isDevelopment() || isTest()) {
var symbolIsPolyfilled = typeof Symbol === 'function' && typeof Symbol('') === 'string';
if (!symbolIsPolyfilled) {
return deepFreeze(obj);
}
}
return obj;
return obj;
}
var hasOwnProperty = Object.prototype.hasOwnProperty;
function mergeDeep() {
var sources = [];
for (var _i = 0; _i < arguments.length; _i++) {
sources[_i] = arguments[_i];
}
var hasOwnProperty = Object.prototype.hasOwnProperty;
function mergeDeep() {
var sources = [];
for (var _i = 0; _i < arguments.length; _i++) {
sources[_i] = arguments[_i];
}
return mergeDeepArray(sources);
return mergeDeepArray(sources);
}
function mergeDeepArray(sources) {
var target = sources[0] || {};
var count = sources.length;
if (count > 1) {
var pastCopies = [];
target = shallowCopyForMerge(target, pastCopies);
for (var i = 1; i < count; ++i) {
target = mergeHelper(target, sources[i], pastCopies);
}
}
function mergeDeepArray(sources) {
var target = sources[0] || {};
var count = sources.length;
if (count > 1) {
var pastCopies = [];
target = shallowCopyForMerge(target, pastCopies);
for (var i = 1; i < count; ++i) {
target = mergeHelper(target, sources[i], pastCopies);
}
return target;
}
function isObject(obj) {
return obj !== null && typeof obj === 'object';
}
function mergeHelper(target, source, pastCopies) {
if (isObject(source) && isObject(target)) {
if (Object.isExtensible && !Object.isExtensible(target)) {
target = shallowCopyForMerge(target, pastCopies);
}
Object.keys(source).forEach(function (sourceKey) {
var sourceValue = source[sourceKey];
if (hasOwnProperty.call(target, sourceKey)) {
var targetValue = target[sourceKey];
if (sourceValue !== targetValue) {
target[sourceKey] = mergeHelper(shallowCopyForMerge(targetValue, pastCopies), sourceValue, pastCopies);
}
} else {
target[sourceKey] = sourceValue;
}
return target;
});
return target;
}
function isObject(obj) {
return obj !== null && typeof obj === 'object';
return source;
}
function shallowCopyForMerge(value, pastCopies) {
if (value !== null && typeof value === 'object' && pastCopies.indexOf(value) < 0) {
if (Array.isArray(value)) {
value = value.slice(0);
} else {
value = (0, _tslib.__assign)({
__proto__: Object.getPrototypeOf(value)
}, value);
}
pastCopies.push(value);
}
function mergeHelper(target, source, pastCopies) {
if (isObject(source) && isObject(target)) {
if (Object.isExtensible && !Object.isExtensible(target)) {
target = shallowCopyForMerge(target, pastCopies);
}
Object.keys(source).forEach(function (sourceKey) {
var sourceValue = source[sourceKey];
if (hasOwnProperty.call(target, sourceKey)) {
var targetValue = target[sourceKey];
if (sourceValue !== targetValue) {
target[sourceKey] = mergeHelper(shallowCopyForMerge(targetValue, pastCopies), sourceValue, pastCopies);
}
}
else {
target[sourceKey] = sourceValue;
}
});
return target;
}
return source;
}
function shallowCopyForMerge(value, pastCopies) {
if (value !== null &&
typeof value === 'object' &&
pastCopies.indexOf(value) < 0) {
if (Array.isArray(value)) {
value = value.slice(0);
}
else {
value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
}
pastCopies.push(value);
}
return value;
}
var haveWarned = Object.create({});
function warnOnceInDevelopment(msg, type) {
if (type === void 0) { type = 'warn'; }
if (!isProduction() && !haveWarned[msg]) {
if (!isTest()) {
haveWarned[msg] = true;
}
if (type === 'error') {
console.error(msg);
}
else {
console.warn(msg);
}
}
return value;
}
var haveWarned = Object.create({});
function warnOnceInDevelopment(msg, type) {
if (type === void 0) {
type = 'warn';
}
function stripSymbols(data) {
return JSON.parse(JSON.stringify(data));
if (!isProduction() && !haveWarned[msg]) {
if (!isTest()) {
haveWarned[msg] = true;
}
if (type === 'error') {
console.error(msg);
} else {
console.warn(msg);
}
}
}
exports.addTypenameToDocument = addTypenameToDocument;
exports.argumentsObjectFromField = argumentsObjectFromField;
exports.assign = assign;
exports.buildQueryFromSelectionSet = buildQueryFromSelectionSet;
exports.canUseWeakMap = canUseWeakMap;
exports.checkDocument = checkDocument;
exports.cloneDeep = cloneDeep;
exports.createFragmentMap = createFragmentMap;
exports.getDefaultValues = getDefaultValues;
exports.getDirectiveInfoFromField = getDirectiveInfoFromField;
exports.getDirectiveNames = getDirectiveNames;
exports.getDirectivesFromDocument = getDirectivesFromDocument;
exports.getEnv = getEnv;
exports.getFragmentDefinition = getFragmentDefinition;
exports.getFragmentDefinitions = getFragmentDefinitions;
exports.getFragmentQueryDocument = getFragmentQueryDocument;
exports.getInclusionDirectives = getInclusionDirectives;
exports.getMainDefinition = getMainDefinition;
exports.getMutationDefinition = getMutationDefinition;
exports.getOperationDefinition = getOperationDefinition;
exports.getOperationDefinitionOrDie = getOperationDefinitionOrDie;
exports.getOperationName = getOperationName;
exports.getQueryDefinition = getQueryDefinition;
exports.getStoreKeyName = getStoreKeyName;
exports.graphQLResultHasError = graphQLResultHasError;
exports.hasClientExports = hasClientExports;
exports.hasDirectives = hasDirectives;
exports.isDevelopment = isDevelopment;
exports.isEnv = isEnv;
exports.isEqual = isEqual;
exports.isField = isField;
exports.isIdValue = isIdValue;
exports.isInlineFragment = isInlineFragment;
exports.isJsonValue = isJsonValue;
exports.isNumberValue = isNumberValue;
exports.isProduction = isProduction;
exports.isScalarValue = isScalarValue;
exports.isTest = isTest;
exports.maybeDeepFreeze = maybeDeepFreeze;
exports.mergeDeep = mergeDeep;
exports.mergeDeepArray = mergeDeepArray;
exports.removeArgumentsFromDocument = removeArgumentsFromDocument;
exports.removeClientSetsFromDocument = removeClientSetsFromDocument;
exports.removeConnectionDirectiveFromDocument = removeConnectionDirectiveFromDocument;
exports.removeDirectivesFromDocument = removeDirectivesFromDocument;
exports.removeFragmentSpreadFromDocument = removeFragmentSpreadFromDocument;
exports.resultKeyNameFromField = resultKeyNameFromField;
exports.shouldInclude = shouldInclude;
exports.storeKeyNameFromField = storeKeyNameFromField;
exports.stripSymbols = stripSymbols;
exports.toIdValue = toIdValue;
exports.tryFunctionOrLogError = tryFunctionOrLogError;
exports.valueFromNode = valueFromNode;
exports.valueToObjectRepresentation = valueToObjectRepresentation;
exports.variablesInOperation = variablesInOperation;
exports.warnOnceInDevelopment = warnOnceInDevelopment;
function stripSymbols(data) {
return JSON.parse(JSON.stringify(data));
}
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=bundle.umd.js.map
});
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var lodash_isequal_1 = tslib_1.__importDefault(require("lodash.isequal"));
function isEqual(a, b) {
if (a === b) {
return true;
}
if (a instanceof Date && b instanceof Date) {
return a.getTime() === b.getTime();
}
if (a != null &&
typeof a === 'object' &&
b != null &&
typeof b === 'object') {
for (var key in a) {
if (Object.prototype.hasOwnProperty.call(a, key)) {
if (!Object.prototype.hasOwnProperty.call(b, key)) {
return false;
}
if (!isEqual(a[key], b[key])) {
return false;
}
}
}
for (var key in b) {
if (Object.prototype.hasOwnProperty.call(b, key) &&
!Object.prototype.hasOwnProperty.call(a, key)) {
return false;
}
}
return true;
}
return false;
return lodash_isequal_1.default(a, b);
}
exports.isEqual = isEqual;
//# sourceMappingURL=isEqual.js.map
{
"name": "apollo-utilities",
"version": "1.3.0",
"version": "1.3.1",
"description": "Utilities for working with GraphQL ASTs",

@@ -43,6 +43,10 @@ "author": "James Baxley <james@meteor.com>",

"fast-json-stable-stringify": "^2.0.0",
"lodash.isequal": "^4.5.0",
"ts-invariant": "^0.4.0",
"tslib": "^1.9.3"
},
"gitHead": "6838c5b11efb7c12abe0a37ae45061bf4f28c134"
"devDependencies": {
"@types/lodash.isequal": "^4.5.5"
},
"gitHead": "4db0a7394649d8b21eaa8d5ba06dc2c3b9ee2b3a"
}

@@ -93,2 +93,83 @@ import { isEqual } from '../isEqual';

});
describe('comparing objects with circular refs', () => {
// copied with slight modification from lodash test suite
it('should compare objects with circular references', () => {
const object1 = {},
object2 = {};
object1.a = object1;
object2.a = object2;
expect(isEqual(object1, object2)).toBe(true);
object1.b = 0;
object2.b = Object(0);
expect(isEqual(object1, object2)).toBe(true);
object1.c = Object(1);
object2.c = Object(2);
expect(isEqual(object1, object2)).toBe(false);
object1 = { a: 1, b: 2, c: 3 };
object1.b = object1;
object2 = { a: 1, b: { a: 1, b: 2, c: 3 }, c: 3 };
expect(isEqual(object1, object2)).toBe(false);
});
it('should have transitive equivalence for circular references of objects', () => {
const object1 = {},
object2 = { a: object1 },
object3 = { a: object2 };
object1.a = object1;
expect(isEqual(object1, object2)).toBe(true);
expect(isEqual(object2, object3)).toBe(true);
expect(isEqual(object1, object3)).toBe(true);
});
it('should compare objects with multiple circular references', () => {
const array1 = [{}],
array2 = [{}];
(array1[0].a = array1).push(array1);
(array2[0].a = array2).push(array2);
expect(isEqual(array1, array2)).toBe(true);
array1[0].b = 0;
array2[0].b = Object(0);
expect(isEqual(array1, array2)).toBe(true);
array1[0].c = Object(1);
array2[0].c = Object(2);
expect(isEqual(array1, array2)).toBe(false);
});
it('should compare objects with complex circular references', () => {
const object1 = {
foo: { b: { c: { d: {} } } },
bar: { a: 2 },
};
const object2 = {
foo: { b: { c: { d: {} } } },
bar: { a: 2 },
};
object1.foo.b.c.d = object1;
object1.bar.b = object1.foo.b;
object2.foo.b.c.d = object2;
object2.bar.b = object2.foo.b;
expect(isEqual(object1, object2)).toBe(true);
});
});
});

@@ -0,1 +1,3 @@

import isEqualLodash from 'lodash.isequal';
/**

@@ -5,44 +7,3 @@ * Performs a deep equality check on two JavaScript values.

export function isEqual(a: any, b: any): boolean {
// If the two values are strictly equal, we are good.
if (a === b) {
return true;
}
// Dates are equivalent if their time values are equal.
if (a instanceof Date && b instanceof Date) {
return a.getTime() === b.getTime();
}
// If a and b are both objects, we will compare their properties. This will compare arrays as
// well.
if (
a != null &&
typeof a === 'object' &&
b != null &&
typeof b === 'object'
) {
// Compare all of the keys in `a`. If one of the keys has a different value, or that key does
// not exist in `b` return false immediately.
for (const key in a) {
if (Object.prototype.hasOwnProperty.call(a, key)) {
if (!Object.prototype.hasOwnProperty.call(b, key)) {
return false;
}
if (!isEqual(a[key], b[key])) {
return false;
}
}
}
// Look through all the keys in `b`. If `b` has a key that `a` does not, return false.
for (const key in b) {
if (
Object.prototype.hasOwnProperty.call(b, key) &&
!Object.prototype.hasOwnProperty.call(a, key)
) {
return false;
}
}
// If we made it this far the objects are equal!
return true;
}
// Otherwise the values are not equal.
return false;
return isEqualLodash(a, b);
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc