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.2.0-beta.0 to 1.2.0-beta.1

jest.config.js

114

lib/bundle.umd.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('graphql/language/visitor'), require('fast-json-stable-stringify')) :
typeof define === 'function' && define.amd ? define(['exports', 'graphql/language/visitor', 'fast-json-stable-stringify'], factory) :
(global = global || self, factory((global.apollo = global.apollo || {}, global.apollo.utilities = {}), global.visitor, global.stringify));
}(this, function (exports, visitor, stringify) { 'use strict';
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';
stringify = stringify && stringify.hasOwnProperty('default') ? stringify['default'] : stringify;
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function isScalarValue(value) {

@@ -100,3 +74,3 @@ return ['StringValue', 'BooleanValue', 'EnumValue'].indexOf(value.kind) > -1;

else {
throw new Error("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError() : new tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
'is not supported. Use variables instead of inline arguments to ' +

@@ -205,3 +179,3 @@ 'overcome this limitation.');

if (generated === void 0) { generated = false; }
return __assign({ type: 'id', generated: generated }, (typeof idConfig === 'string'
return tslib.__assign({ type: 'id', generated: generated }, (typeof idConfig === 'string'
? { id: idConfig, typename: undefined }

@@ -216,3 +190,3 @@ : idConfig));

function defaultValueFromVariable(node) {
throw new Error("Variable nodes are not supported by valueFromNode");
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError() : new tsInvariant.InvariantError("Variable nodes are not supported by valueFromNode");
}

@@ -267,21 +241,11 @@ function valueFromNode(node, onVariable) {

var directiveName = directive.name.value;
if (directiveArguments.length !== 1) {
throw new Error("Incorrect number of arguments for the @" + directiveName + " directive.");
}
process.env.NODE_ENV === "production" ? tsInvariant.invariant(directiveArguments.length === 1) : tsInvariant.invariant(directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
var ifArgument = directiveArguments[0];
if (!ifArgument.name || ifArgument.name.value !== 'if') {
throw new Error("Invalid argument for the @" + directiveName + " directive.");
}
process.env.NODE_ENV === "production" ? tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if') : tsInvariant.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.");
var ifValue = directiveArguments[0].value;
var evaledValue = false;
if (!ifValue || ifValue.kind !== 'BooleanValue') {
if (ifValue.kind !== 'Variable') {
throw new Error("Argument for the @" + directiveName + " directive must be a variable or a boolean value.");
}
else {
evaledValue = variables[ifValue.name.value];
if (evaledValue === undefined) {
throw new Error("Invalid variable referenced in @" + directiveName + " directive.");
}
}
process.env.NODE_ENV === "production" ? tsInvariant.invariant(ifValue.kind === 'Variable') : tsInvariant.invariant(ifValue.kind === 'Variable', "Argument for the @" + directiveName + " directive must be a variable or a boolean value.");
evaledValue = variables[ifValue.name.value];
process.env.NODE_ENV === "production" ? tsInvariant.invariant(evaledValue !== void 0) : tsInvariant.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directiveName + " directive.");
}

@@ -323,3 +287,3 @@ else {

if (definition.kind === 'OperationDefinition') {
throw new Error("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError() : 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.');

@@ -332,8 +296,6 @@ }

if (typeof actualFragmentName === 'undefined') {
if (fragments.length !== 1) {
throw new Error("Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
}
process.env.NODE_ENV === "production" ? tsInvariant.invariant(fragments.length === 1) : 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 = __assign({}, document, { definitions: [
var query = tslib.__assign({}, document, { definitions: [
{

@@ -381,11 +343,7 @@ kind: 'OperationDefinition',

})[0];
if (!mutationDef) {
throw new Error('Must contain a mutation definition.');
}
process.env.NODE_ENV === "production" ? tsInvariant.invariant(mutationDef) : tsInvariant.invariant(mutationDef, 'Must contain a mutation definition.');
return mutationDef;
}
function checkDocument(doc) {
if (!doc || doc.kind !== 'Document') {
throw new Error("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 && doc.kind === 'Document') : 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

@@ -395,9 +353,7 @@ .filter(function (d) { return d.kind !== 'FragmentDefinition'; })

if (definition.kind !== 'OperationDefinition') {
throw new Error("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError() : new tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
}
return definition;
});
if (operations.length > 1) {
throw new Error("Ambiguous GraphQL document: contains " + operations.length + " operations");
}
process.env.NODE_ENV === "production" ? tsInvariant.invariant(operations.length <= 1) : tsInvariant.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations");
return doc;

@@ -411,5 +367,3 @@ }

var def = getOperationDefinition(document);
if (!def) {
throw new Error("GraphQL document is missing an operation");
}
process.env.NODE_ENV === "production" ? tsInvariant.invariant(def) : tsInvariant.invariant(def, "GraphQL document is missing an operation");
return def;

@@ -429,18 +383,10 @@ }

var queryDef = getOperationDefinition(doc);
if (!queryDef || queryDef.operation !== 'query') {
throw new Error('Must contain a query definition.');
}
process.env.NODE_ENV === "production" ? tsInvariant.invariant(queryDef && queryDef.operation === 'query') : tsInvariant.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.');
return queryDef;
}
function getFragmentDefinition(doc) {
if (doc.kind !== 'Document') {
throw new Error("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");
}
if (doc.definitions.length > 1) {
throw new Error('Fragment must have exactly one definition.');
}
process.env.NODE_ENV === "production" ? tsInvariant.invariant(doc.kind === 'Document') : 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) : tsInvariant.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.');
var fragmentDef = doc.definitions[0];
if (fragmentDef.kind !== 'FragmentDefinition') {
throw new Error('Must be a fragment definition.');
}
process.env.NODE_ENV === "production" ? tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition') : tsInvariant.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.');
return fragmentDef;

@@ -468,3 +414,3 @@ }

}
throw new Error('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.');
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError() : new tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.');
}

@@ -631,3 +577,3 @@ function createFragmentMap(fragments) {

}
return __assign({}, node, { selections: selections.concat([TYPENAME_FIELD]) });
return tslib.__assign({}, node, { selections: selections.concat([TYPENAME_FIELD]) });
},

@@ -688,3 +634,3 @@ },

}
return __assign({}, node, { selections: selectionsWithDirectives });
return tslib.__assign({}, node, { selections: selectionsWithDirectives });
}

@@ -715,3 +661,3 @@ else {

enter: function (node) {
return __assign({}, node, { variableDefinitions: node.variableDefinitions.filter(function (varDef) {
return tslib.__assign({}, node, { variableDefinitions: node.variableDefinitions.filter(function (varDef) {
return !config.some(function (arg) { return arg.name === varDef.variable.name.value; });

@@ -779,3 +725,3 @@ }) });

enter: function (node) {
return __assign({}, node, { operation: 'query' });
return tslib.__assign({}, node, { operation: 'query' });
},

@@ -983,3 +929,3 @@ },

else {
value = __assign({ __proto__: Object.getPrototypeOf(value) }, value);
value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
}

@@ -986,0 +932,0 @@ pastCopies.push(value);

@@ -0,0 +0,0 @@ import { FieldNode, SelectionNode, DocumentNode } from 'graphql';

@@ -1,8 +0,11 @@

import { visit } from 'graphql/language/visitor';
import { argumentsObjectFromField } from './storeUtils';
export function getDirectiveInfoFromField(field, variables) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var visitor_1 = require("graphql/language/visitor");
var ts_invariant_1 = require("ts-invariant");
var storeUtils_1 = require("./storeUtils");
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);
directiveObj_1[directive.name.value] = storeUtils_1.argumentsObjectFromField(directive, variables);
});

@@ -13,3 +16,4 @@ return directiveObj_1;

}
export function shouldInclude(selection, variables) {
exports.getDirectiveInfoFromField = getDirectiveInfoFromField;
function shouldInclude(selection, variables) {
if (variables === void 0) { variables = {}; }

@@ -26,21 +30,11 @@ if (!selection.directives) {

var directiveName = directive.name.value;
if (directiveArguments.length !== 1) {
throw new Error("Incorrect number of arguments for the @" + directiveName + " directive.");
}
ts_invariant_1.invariant(directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
var ifArgument = directiveArguments[0];
if (!ifArgument.name || ifArgument.name.value !== 'if') {
throw new Error("Invalid argument for the @" + directiveName + " directive.");
}
ts_invariant_1.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.");
var ifValue = directiveArguments[0].value;
var evaledValue = false;
if (!ifValue || ifValue.kind !== 'BooleanValue') {
if (ifValue.kind !== 'Variable') {
throw new Error("Argument for the @" + directiveName + " directive must be a variable or a boolean value.");
}
else {
evaledValue = variables[ifValue.name.value];
if (evaledValue === undefined) {
throw new Error("Invalid variable referenced in @" + directiveName + " directive.");
}
}
ts_invariant_1.invariant(ifValue.kind === 'Variable', "Argument for the @" + directiveName + " directive must be a variable or a boolean value.");
evaledValue = variables[ifValue.name.value];
ts_invariant_1.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directiveName + " directive.");
}

@@ -59,5 +53,6 @@ else {

}
export function getDirectiveNames(doc) {
exports.shouldInclude = shouldInclude;
function getDirectiveNames(doc) {
var names = [];
visit(doc, {
visitor_1.visit(doc, {
Directive: function (node) {

@@ -69,6 +64,8 @@ names.push(node.name.value);

}
export function hasDirectives(names, doc) {
exports.getDirectiveNames = getDirectiveNames;
function hasDirectives(names, doc) {
return getDirectiveNames(doc).some(function (name) { return names.indexOf(name) > -1; });
}
export function hasClientExports(document) {
exports.hasDirectives = hasDirectives;
function hasClientExports(document) {
return (document &&

@@ -78,2 +75,3 @@ hasDirectives(['client'], document) &&

}
exports.hasClientExports = hasClientExports;
//# sourceMappingURL=directives.js.map
import { DocumentNode } from 'graphql';
export declare function getFragmentQueryDocument(document: DocumentNode, fragmentName?: string): DocumentNode;
//# sourceMappingURL=fragments.d.ts.map

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

import * as tslib_1 from "tslib";
export function getFragmentQueryDocument(document, fragmentName) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ts_invariant_1 = require("ts-invariant");
function getFragmentQueryDocument(document, fragmentName) {
var actualFragmentName = fragmentName;

@@ -7,3 +10,3 @@ var fragments = [];

if (definition.kind === 'OperationDefinition') {
throw new Error("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " +
throw new ts_invariant_1.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.');

@@ -16,5 +19,3 @@ }

if (typeof actualFragmentName === 'undefined') {
if (fragments.length !== 1) {
throw new Error("Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
}
ts_invariant_1.invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
actualFragmentName = fragments[0].name.value;

@@ -42,2 +43,3 @@ }

}
exports.getFragmentQueryDocument = getFragmentQueryDocument;
//# sourceMappingURL=fragments.js.map

@@ -0,0 +0,0 @@ import { DocumentNode, OperationDefinitionNode, FragmentDefinitionNode } from 'graphql';

@@ -1,4 +0,7 @@

import { assign } from './util/assign';
import { valueToObjectRepresentation } from './storeUtils';
export function getMutationDefinition(doc) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ts_invariant_1 = require("ts-invariant");
var assign_1 = require("./util/assign");
var storeUtils_1 = require("./storeUtils");
function getMutationDefinition(doc) {
checkDocument(doc);

@@ -9,11 +12,8 @@ var mutationDef = doc.definitions.filter(function (definition) {

})[0];
if (!mutationDef) {
throw new Error('Must contain a mutation definition.');
}
ts_invariant_1.invariant(mutationDef, 'Must contain a mutation definition.');
return mutationDef;
}
export function checkDocument(doc) {
if (!doc || doc.kind !== 'Document') {
throw new Error("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");
}
exports.getMutationDefinition = getMutationDefinition;
function checkDocument(doc) {
ts_invariant_1.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

@@ -23,23 +23,22 @@ .filter(function (d) { return d.kind !== 'FragmentDefinition'; })

if (definition.kind !== 'OperationDefinition') {
throw new Error("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
throw new ts_invariant_1.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
}
return definition;
});
if (operations.length > 1) {
throw new Error("Ambiguous GraphQL document: contains " + operations.length + " operations");
}
ts_invariant_1.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations");
return doc;
}
export function getOperationDefinition(doc) {
exports.checkDocument = checkDocument;
function getOperationDefinition(doc) {
checkDocument(doc);
return doc.definitions.filter(function (definition) { return definition.kind === 'OperationDefinition'; })[0];
}
export function getOperationDefinitionOrDie(document) {
exports.getOperationDefinition = getOperationDefinition;
function getOperationDefinitionOrDie(document) {
var def = getOperationDefinition(document);
if (!def) {
throw new Error("GraphQL document is missing an operation");
}
ts_invariant_1.invariant(def, "GraphQL document is missing an operation");
return def;
}
export function getOperationName(doc) {
exports.getOperationDefinitionOrDie = getOperationDefinitionOrDie;
function getOperationName(doc) {
return (doc.definitions

@@ -51,26 +50,22 @@ .filter(function (definition) {

}
export function getFragmentDefinitions(doc) {
exports.getOperationName = getOperationName;
function getFragmentDefinitions(doc) {
return doc.definitions.filter(function (definition) { return definition.kind === 'FragmentDefinition'; });
}
export function getQueryDefinition(doc) {
exports.getFragmentDefinitions = getFragmentDefinitions;
function getQueryDefinition(doc) {
var queryDef = getOperationDefinition(doc);
if (!queryDef || queryDef.operation !== 'query') {
throw new Error('Must contain a query definition.');
}
ts_invariant_1.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.');
return queryDef;
}
export function getFragmentDefinition(doc) {
if (doc.kind !== 'Document') {
throw new Error("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");
}
if (doc.definitions.length > 1) {
throw new Error('Fragment must have exactly one definition.');
}
exports.getQueryDefinition = getQueryDefinition;
function getFragmentDefinition(doc) {
ts_invariant_1.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");
ts_invariant_1.invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.');
var fragmentDef = doc.definitions[0];
if (fragmentDef.kind !== 'FragmentDefinition') {
throw new Error('Must be a fragment definition.');
}
ts_invariant_1.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.');
return fragmentDef;
}
export function getMainDefinition(queryDoc) {
exports.getFragmentDefinition = getFragmentDefinition;
function getMainDefinition(queryDoc) {
checkDocument(queryDoc);

@@ -95,5 +90,6 @@ var fragmentDefinition;

}
throw new Error('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.');
throw new ts_invariant_1.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.');
}
export function createFragmentMap(fragments) {
exports.getMainDefinition = getMainDefinition;
function createFragmentMap(fragments) {
if (fragments === void 0) { fragments = []; }

@@ -106,3 +102,4 @@ var symTable = {};

}
export function getDefaultValues(definition) {
exports.createFragmentMap = createFragmentMap;
function getDefaultValues(definition) {
if (definition &&

@@ -119,10 +116,11 @@ definition.variableDefinitions &&

var defaultValueObj = {};
valueToObjectRepresentation(defaultValueObj, variable.name, defaultValue);
storeUtils_1.valueToObjectRepresentation(defaultValueObj, variable.name, defaultValue);
return defaultValueObj;
});
return assign.apply(void 0, [{}].concat(defaultValues));
return assign_1.assign.apply(void 0, [{}].concat(defaultValues));
}
return {};
}
export function variablesInOperation(operation) {
exports.getDefaultValues = getDefaultValues;
function variablesInOperation(operation) {
var names = new Set();

@@ -137,2 +135,3 @@ if (operation.variableDefinitions) {

}
exports.variablesInOperation = variablesInOperation;
//# sourceMappingURL=getFromAST.js.map

@@ -0,0 +0,0 @@ export * from './directives';

@@ -1,16 +0,19 @@

export * from './directives';
export * from './fragments';
export * from './getFromAST';
export * from './transform';
export * from './storeUtils';
export * from './util/assign';
export * from './util/cloneDeep';
export * from './util/environment';
export * from './util/errorHandling';
export * from './util/isEqual';
export * from './util/maybeDeepFreeze';
export * from './util/mergeDeep';
export * from './util/warnOnce';
export * from './util/stripSymbols';
export * from './util/mergeDeep';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./directives"), exports);
tslib_1.__exportStar(require("./fragments"), exports);
tslib_1.__exportStar(require("./getFromAST"), exports);
tslib_1.__exportStar(require("./transform"), exports);
tslib_1.__exportStar(require("./storeUtils"), exports);
tslib_1.__exportStar(require("./util/assign"), exports);
tslib_1.__exportStar(require("./util/cloneDeep"), exports);
tslib_1.__exportStar(require("./util/environment"), exports);
tslib_1.__exportStar(require("./util/errorHandling"), exports);
tslib_1.__exportStar(require("./util/isEqual"), exports);
tslib_1.__exportStar(require("./util/maybeDeepFreeze"), exports);
tslib_1.__exportStar(require("./util/mergeDeep"), exports);
tslib_1.__exportStar(require("./util/warnOnce"), exports);
tslib_1.__exportStar(require("./util/stripSymbols"), exports);
tslib_1.__exportStar(require("./util/mergeDeep"), exports);
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ import { DirectiveNode, FieldNode, IntValueNode, FloatValueNode, StringValueNode, BooleanValueNode, EnumValueNode, VariableNode, InlineFragmentNode, ValueNode, SelectionNode, NameNode } from 'graphql';

@@ -1,9 +0,14 @@

import * as tslib_1 from "tslib";
import stringify from 'fast-json-stable-stringify';
export function isScalarValue(value) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var fast_json_stable_stringify_1 = tslib_1.__importDefault(require("fast-json-stable-stringify"));
var ts_invariant_1 = require("ts-invariant");
function isScalarValue(value) {
return ['StringValue', 'BooleanValue', 'EnumValue'].indexOf(value.kind) > -1;
}
export function isNumberValue(value) {
exports.isScalarValue = isScalarValue;
function isNumberValue(value) {
return ['IntValue', 'FloatValue'].indexOf(value.kind) > -1;
}
exports.isNumberValue = isNumberValue;
function isStringValue(value) {

@@ -36,3 +41,3 @@ return value.kind === 'StringValue';

}
export function valueToObjectRepresentation(argObj, name, value, variables) {
function valueToObjectRepresentation(argObj, name, value, variables) {
if (isIntValue(value) || isFloatValue(value)) {

@@ -69,3 +74,3 @@ argObj[name.value] = Number(value.value);

else {
throw new Error("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
throw new ts_invariant_1.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
'is not supported. Use variables instead of inline arguments to ' +

@@ -75,3 +80,4 @@ 'overcome this limitation.');

}
export function storeKeyNameFromField(field, variables) {
exports.valueToObjectRepresentation = valueToObjectRepresentation;
function storeKeyNameFromField(field, variables) {
var directivesObj = null;

@@ -100,2 +106,3 @@ if (field.directives) {

}
exports.storeKeyNameFromField = storeKeyNameFromField;
var KNOWN_DIRECTIVES = [

@@ -109,3 +116,3 @@ 'connection',

];
export function getStoreKeyName(fieldName, args, directives) {
function getStoreKeyName(fieldName, args, directives) {
if (directives &&

@@ -133,3 +140,3 @@ directives['connection'] &&

if (args) {
var stringifiedArgs = stringify(args);
var stringifiedArgs = fast_json_stable_stringify_1.default(args);
completeFieldName += "(" + stringifiedArgs + ")";

@@ -151,3 +158,4 @@ }

}
export function argumentsObjectFromField(field, variables) {
exports.getStoreKeyName = getStoreKeyName;
function argumentsObjectFromField(field, variables) {
if (field.arguments && field.arguments.length) {

@@ -163,12 +171,16 @@ var argObj_1 = {};

}
export function resultKeyNameFromField(field) {
exports.argumentsObjectFromField = argumentsObjectFromField;
function resultKeyNameFromField(field) {
return field.alias ? field.alias.value : field.name.value;
}
export function isField(selection) {
exports.resultKeyNameFromField = resultKeyNameFromField;
function isField(selection) {
return selection.kind === 'Field';
}
export function isInlineFragment(selection) {
exports.isField = isField;
function isInlineFragment(selection) {
return selection.kind === 'InlineFragment';
}
export function isIdValue(idObject) {
exports.isInlineFragment = isInlineFragment;
function isIdValue(idObject) {
return idObject &&

@@ -178,3 +190,4 @@ idObject.type === 'id' &&

}
export function toIdValue(idConfig, generated) {
exports.isIdValue = isIdValue;
function toIdValue(idConfig, generated) {
if (generated === void 0) { generated = false; }

@@ -185,3 +198,4 @@ return tslib_1.__assign({ type: 'id', generated: generated }, (typeof idConfig === 'string'

}
export function isJsonValue(jsonObject) {
exports.toIdValue = toIdValue;
function isJsonValue(jsonObject) {
return (jsonObject != null &&

@@ -191,6 +205,7 @@ typeof jsonObject === 'object' &&

}
exports.isJsonValue = isJsonValue;
function defaultValueFromVariable(node) {
throw new Error("Variable nodes are not supported by valueFromNode");
throw new ts_invariant_1.InvariantError("Variable nodes are not supported by valueFromNode");
}
export function valueFromNode(node, onVariable) {
function valueFromNode(node, onVariable) {
if (onVariable === void 0) { onVariable = defaultValueFromVariable; }

@@ -220,2 +235,3 @@ switch (node.kind) {

}
exports.valueFromNode = valueFromNode;
//# sourceMappingURL=storeUtils.js.map

@@ -0,0 +0,0 @@ import { DocumentNode, DirectiveNode, FragmentDefinitionNode, ArgumentNode, FragmentSpreadNode, VariableDefinitionNode } from 'graphql';

@@ -1,5 +0,7 @@

import * as tslib_1 from "tslib";
import { visit } from 'graphql/language/visitor';
import { checkDocument, getOperationDefinition, getFragmentDefinition, getFragmentDefinitions, createFragmentMap, getMainDefinition, } from './getFromAST';
import { filterInPlace } from './util/filterInPlace';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var visitor_1 = require("graphql/language/visitor");
var getFromAST_1 = require("./getFromAST");
var filterInPlace_1 = require("./util/filterInPlace");
var TYPENAME_FIELD = {

@@ -19,3 +21,3 @@ kind: 'Field',

function nullIfDocIsEmpty(doc) {
return isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc)))
return isEmpty(getFromAST_1.getOperationDefinition(doc) || getFromAST_1.getFragmentDefinition(doc), getFromAST_1.createFragmentMap(getFromAST_1.getFragmentDefinitions(doc)))
? null

@@ -32,3 +34,3 @@ : doc;

}
export function removeDirectivesFromDocument(directives, doc) {
function removeDirectivesFromDocument(directives, doc) {
var variablesInUse = Object.create(null);

@@ -38,3 +40,3 @@ var variablesToRemove = [];

var fragmentSpreadsToRemove = [];
var modifiedDoc = nullIfDocIsEmpty(visit(doc, {
var modifiedDoc = nullIfDocIsEmpty(visitor_1.visit(doc, {
Variable: {

@@ -89,7 +91,7 @@ enter: function (node, _key, parent) {

if (modifiedDoc &&
filterInPlace(variablesToRemove, function (v) { return !variablesInUse[v.name]; }).length) {
filterInPlace_1.filterInPlace(variablesToRemove, function (v) { return !variablesInUse[v.name]; }).length) {
modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);
}
if (modifiedDoc &&
filterInPlace(fragmentSpreadsToRemove, function (fs) { return !fragmentSpreadsInUse[fs.name]; })
filterInPlace_1.filterInPlace(fragmentSpreadsToRemove, function (fs) { return !fragmentSpreadsInUse[fs.name]; })
.length) {

@@ -100,4 +102,5 @@ modifiedDoc = removeFragmentSpreadFromDocument(fragmentSpreadsToRemove, modifiedDoc);

}
export function addTypenameToDocument(doc) {
return visit(checkDocument(doc), {
exports.removeDirectivesFromDocument = removeDirectivesFromDocument;
function addTypenameToDocument(doc) {
return visitor_1.visit(getFromAST_1.checkDocument(doc), {
SelectionSet: {

@@ -126,2 +129,3 @@ enter: function (node, _key, parent) {

}
exports.addTypenameToDocument = addTypenameToDocument;
var connectionRemoveConfig = {

@@ -140,5 +144,6 @@ test: function (directive) {

};
export function removeConnectionDirectiveFromDocument(doc) {
return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
function removeConnectionDirectiveFromDocument(doc) {
return removeDirectivesFromDocument([connectionRemoveConfig], getFromAST_1.checkDocument(doc));
}
exports.removeConnectionDirectiveFromDocument = removeConnectionDirectiveFromDocument;
function hasDirectivesInSelectionSet(directives, selectionSet, nestedCheck) {

@@ -164,6 +169,6 @@ if (nestedCheck === void 0) { nestedCheck = true; }

}
export function getDirectivesFromDocument(directives, doc) {
checkDocument(doc);
function getDirectivesFromDocument(directives, doc) {
getFromAST_1.checkDocument(doc);
var parentPath;
return nullIfDocIsEmpty(visit(doc, {
return nullIfDocIsEmpty(visitor_1.visit(doc, {
SelectionSet: {

@@ -190,2 +195,3 @@ enter: function (node, _key, _parent, path) {

}
exports.getDirectivesFromDocument = getDirectivesFromDocument;
function getArgumentMatcher(config) {

@@ -202,5 +208,5 @@ return function argumentMatcher(argument) {

}
export function removeArgumentsFromDocument(config, doc) {
function removeArgumentsFromDocument(config, doc) {
var argMatcher = getArgumentMatcher(config);
return nullIfDocIsEmpty(visit(doc, {
return nullIfDocIsEmpty(visitor_1.visit(doc, {
OperationDefinition: {

@@ -238,3 +244,4 @@ enter: function (node) {

}
export function removeFragmentSpreadFromDocument(config, doc) {
exports.removeArgumentsFromDocument = removeArgumentsFromDocument;
function removeFragmentSpreadFromDocument(config, doc) {
function enter(node) {

@@ -245,3 +252,3 @@ if (config.some(function (def) { return def.name === node.name.value; })) {

}
return nullIfDocIsEmpty(visit(doc, {
return nullIfDocIsEmpty(visitor_1.visit(doc, {
FragmentSpread: { enter: enter },

@@ -251,2 +258,3 @@ FragmentDefinition: { enter: enter },

}
exports.removeFragmentSpreadFromDocument = removeFragmentSpreadFromDocument;
function getAllFragmentSpreadsFromSelectionSet(selectionSet) {

@@ -265,4 +273,4 @@ var allFragments = [];

}
export function buildQueryFromSelectionSet(document) {
var definition = getMainDefinition(document);
function buildQueryFromSelectionSet(document) {
var definition = getFromAST_1.getMainDefinition(document);
var definitionOperation = definition.operation;

@@ -272,3 +280,3 @@ if (definitionOperation === 'query') {

}
var modifiedDoc = visit(document, {
var modifiedDoc = visitor_1.visit(document, {
OperationDefinition: {

@@ -282,4 +290,5 @@ enter: function (node) {

}
export function removeClientSetsFromDocument(document) {
checkDocument(document);
exports.buildQueryFromSelectionSet = buildQueryFromSelectionSet;
function removeClientSetsFromDocument(document) {
getFromAST_1.checkDocument(document);
var modifiedDoc = removeDirectivesFromDocument([

@@ -292,3 +301,3 @@ {

if (modifiedDoc) {
modifiedDoc = visit(modifiedDoc, {
modifiedDoc = visitor_1.visit(modifiedDoc, {
FragmentDefinition: {

@@ -311,2 +320,3 @@ enter: function (node) {

}
exports.removeClientSetsFromDocument = removeClientSetsFromDocument;
//# sourceMappingURL=transform.js.map

@@ -0,0 +0,0 @@ export declare function assign<A, B>(a: A, b: B): A & B;

@@ -1,2 +0,4 @@

export function assign(target) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function assign(target) {
var sources = [];

@@ -16,2 +18,3 @@ for (var _i = 1; _i < arguments.length; _i++) {

}
exports.assign = assign;
//# sourceMappingURL=assign.js.map
export declare function cloneDeep<T>(value: T): T;
//# sourceMappingURL=cloneDeep.d.ts.map

@@ -0,5 +1,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var toString = Object.prototype.toString;
export function cloneDeep(value) {
function cloneDeep(value) {
return cloneDeepHelper(value, new Map());
}
exports.cloneDeep = cloneDeep;
function cloneDeepHelper(val, seen) {

@@ -6,0 +9,0 @@ switch (toString.call(val)) {

@@ -0,0 +0,0 @@ export declare function getEnv(): string | undefined;

@@ -1,2 +0,4 @@

export function getEnv() {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getEnv() {
if (typeof process !== 'undefined' && process.env.NODE_ENV) {

@@ -7,14 +9,19 @@ return process.env.NODE_ENV;

}
export function isEnv(env) {
exports.getEnv = getEnv;
function isEnv(env) {
return getEnv() === env;
}
export function isProduction() {
exports.isEnv = isEnv;
function isProduction() {
return isEnv('production') === true;
}
export function isDevelopment() {
exports.isProduction = isProduction;
function isDevelopment() {
return isEnv('development') === true;
}
export function isTest() {
exports.isDevelopment = isDevelopment;
function isTest() {
return isEnv('test') === true;
}
exports.isTest = isTest;
//# sourceMappingURL=environment.js.map

@@ -0,0 +0,0 @@ import { ExecutionResult } from 'graphql';

@@ -1,2 +0,4 @@

export function tryFunctionOrLogError(f) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function tryFunctionOrLogError(f) {
try {

@@ -11,5 +13,7 @@ return f();

}
export function graphQLResultHasError(result) {
exports.tryFunctionOrLogError = tryFunctionOrLogError;
function graphQLResultHasError(result) {
return result.errors && result.errors.length;
}
exports.graphQLResultHasError = graphQLResultHasError;
//# sourceMappingURL=errorHandling.js.map
export declare function filterInPlace<T>(array: T[], test: (elem: T) => boolean, context?: any): T[];
//# sourceMappingURL=filterInPlace.d.ts.map

@@ -1,2 +0,4 @@

export function filterInPlace(array, test, context) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function filterInPlace(array, test, context) {
var target = 0;

@@ -11,2 +13,3 @@ array.forEach(function (elem, i) {

}
exports.filterInPlace = filterInPlace;
//# sourceMappingURL=filterInPlace.js.map
export declare function isEqual(a: any, b: any): boolean;
//# sourceMappingURL=isEqual.d.ts.map

@@ -1,2 +0,4 @@

export function isEqual(a, b) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function isEqual(a, b) {
if (a === b) {

@@ -32,2 +34,3 @@ return true;

}
exports.isEqual = isEqual;
//# sourceMappingURL=isEqual.js.map
export declare function maybeDeepFreeze(obj: any): any;
//# sourceMappingURL=maybeDeepFreeze.d.ts.map

@@ -1,2 +0,4 @@

import { isDevelopment, isTest } from './environment';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var environment_1 = require("./environment");
function deepFreeze(o) {

@@ -13,4 +15,4 @@ Object.freeze(o);

}
export function maybeDeepFreeze(obj) {
if (isDevelopment() || isTest()) {
function maybeDeepFreeze(obj) {
if (environment_1.isDevelopment() || environment_1.isTest()) {
var symbolIsPolyfilled = typeof Symbol === 'function' && typeof Symbol('') === 'string';

@@ -23,2 +25,3 @@ if (!symbolIsPolyfilled) {

}
exports.maybeDeepFreeze = maybeDeepFreeze;
//# sourceMappingURL=maybeDeepFreeze.js.map

@@ -0,0 +0,0 @@ export declare type TupleToIntersection<T extends any[]> = T extends [] ? {} : T extends [infer A] ? A : T extends [infer A, infer B] ? A & B : T extends [infer A, infer B, infer C] ? A & B & C : T extends [infer A, infer B, infer C, infer D] ? A & B & C & D : T extends [infer A, infer B, infer C, infer D, infer E] ? A & B & C & D & E : T extends (infer U)[] ? U : any;

@@ -1,4 +0,6 @@

import * as tslib_1 from "tslib";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var hasOwnProperty = Object.prototype.hasOwnProperty;
export function mergeDeep() {
function mergeDeep() {
var sources = [];

@@ -10,3 +12,4 @@ for (var _i = 0; _i < arguments.length; _i++) {

}
export function mergeDeepArray(sources) {
exports.mergeDeep = mergeDeep;
function mergeDeepArray(sources) {
var target = sources[0] || {};

@@ -23,2 +26,3 @@ var count = sources.length;

}
exports.mergeDeepArray = mergeDeepArray;
function isObject(obj) {

@@ -25,0 +29,0 @@ return obj !== null && typeof obj === 'object';

export declare function stripSymbols<T>(data: T): T;
//# sourceMappingURL=stripSymbols.d.ts.map

@@ -1,4 +0,7 @@

export function stripSymbols(data) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function stripSymbols(data) {
return JSON.parse(JSON.stringify(data));
}
exports.stripSymbols = stripSymbols;
//# sourceMappingURL=stripSymbols.js.map
export declare function warnOnceInDevelopment(msg: string, type?: string): void;
//# sourceMappingURL=warnOnce.d.ts.map

@@ -1,10 +0,12 @@

import { isProduction, isTest } from './environment';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var environment_1 = require("./environment");
var haveWarned = Object.create({});
export function warnOnceInDevelopment(msg, type) {
function warnOnceInDevelopment(msg, type) {
if (type === void 0) { type = 'warn'; }
if (isProduction()) {
if (environment_1.isProduction()) {
return;
}
if (!haveWarned[msg]) {
if (!isTest()) {
if (!environment_1.isTest()) {
haveWarned[msg] = true;

@@ -21,2 +23,3 @@ }

}
exports.warnOnceInDevelopment = warnOnceInDevelopment;
//# sourceMappingURL=warnOnce.js.map
{
"name": "apollo-utilities",
"version": "1.2.0-beta.0",
"version": "1.2.0-beta.1",
"description": "Utilities for working with GraphQL ASTs",

@@ -13,5 +13,4 @@ "author": "James Baxley <james@meteor.com>",

"license": "MIT",
"main": "./lib/bundle.umd.js",
"module": "./lib/index.js",
"jsnext:main": "./lib/index.js",
"main": "./lib/bundle.cjs.js",
"module": "./lib/bundle.esm.js",
"typings": "./lib/index.d.ts",

@@ -29,14 +28,12 @@ "sideEffects": false,

"prepare": "npm run lint && npm run build",
"test": "jest",
"test": "tsc -p tsconfig.json --noEmit && jest",
"coverage": "jest --coverage",
"lint": "tslint -c \"../../config/tslint.json\" -p tsconfig.json src/*.ts",
"prebuild": "npm run clean",
"build": "tsc -p .",
"build": "tsc -b .",
"postbuild": "npm run bundle",
"bundle": "../../node_modules/rollup/bin/rollup -c rollup.config.js",
"watch": "tsc -w -p .",
"clean": "rm -rf coverage/* && rm -rf lib/*",
"prepublishOnly": "npm run clean && npm run build",
"minify": "../../node_modules/uglify-js/bin/uglifyjs -c -m -o ./lib/bundle.min.js -- ./lib/bundle.umd.js",
"filesize": "npm run minify"
"clean": "rm -rf coverage/* lib/*",
"prepublishOnly": "npm run clean && npm run build"
},

@@ -48,18 +45,6 @@ "peerDependencies": {

"fast-json-stable-stringify": "^2.0.0",
"ts-invariant": "^0.2.1",
"tslib": "^1.9.3"
},
"jest": {
"transform": {
".(ts|tsx)": "ts-jest"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
],
"testURL": "http://localhost"
},
"gitHead": "b49a7e851b5637eb9bf3784781fd2c8881a2d2d8"
"gitHead": "ada6057dc4a30ec07b7e8ef2f68e9372e16e1e12"
}

@@ -14,2 +14,4 @@ // Provides the methods that allow QueryManager to handle the `skip` and

import { invariant } from 'ts-invariant';
import { argumentsObjectFromField } from './storeUtils';

@@ -57,12 +59,13 @@

const directiveName = directive.name.value;
if (directiveArguments.length !== 1) {
throw new Error(
`Incorrect number of arguments for the @${directiveName} directive.`,
);
}
invariant(
directiveArguments.length === 1,
`Incorrect number of arguments for the @${directiveName} directive.`,
);
const ifArgument = directiveArguments[0];
if (!ifArgument.name || ifArgument.name.value !== 'if') {
throw new Error(`Invalid argument for the @${directiveName} directive.`);
}
invariant(
ifArgument.name && ifArgument.name.value === 'if',
`Invalid argument for the @${directiveName} directive.`,
);

@@ -73,14 +76,11 @@ const ifValue = directiveArguments[0].value;

// means it has to be a variable value if this is a valid @skip or @include directive
if (ifValue.kind !== 'Variable') {
throw new Error(
`Argument for the @${directiveName} directive must be a variable or a boolean value.`,
);
} else {
evaledValue = variables[(ifValue as VariableNode).name.value];
if (evaledValue === undefined) {
throw new Error(
`Invalid variable referenced in @${directiveName} directive.`,
);
}
}
invariant(
ifValue.kind === 'Variable',
`Argument for the @${directiveName} directive must be a variable or a boolean value.`,
);
evaledValue = variables[(ifValue as VariableNode).name.value];
invariant(
evaledValue !== void 0,
`Invalid variable referenced in @${directiveName} directive.`,
);
} else {

@@ -87,0 +87,0 @@ evaledValue = (ifValue as BooleanValueNode).value;

import { DocumentNode, FragmentDefinitionNode } from 'graphql';
import { invariant, InvariantError } from 'ts-invariant';

@@ -39,3 +40,3 @@ /**

if (definition.kind === 'OperationDefinition') {
throw new Error(
throw new InvariantError(
`Found a ${definition.operation} operation${

@@ -57,9 +58,8 @@ definition.name ? ` named '${definition.name.value}'` : ''

if (typeof actualFragmentName === 'undefined') {
if (fragments.length !== 1) {
throw new Error(
`Found ${
fragments.length
} fragments. \`fragmentName\` must be provided when there is not exactly 1 fragment.`,
);
}
invariant(
fragments.length === 1,
`Found ${
fragments.length
} fragments. \`fragmentName\` must be provided when there is not exactly 1 fragment.`,
);
actualFragmentName = fragments[0].name.value;

@@ -66,0 +66,0 @@ }

@@ -7,2 +7,5 @@ import {

} from 'graphql';
import { invariant, InvariantError } from 'ts-invariant';
import { assign } from './util/assign';

@@ -23,5 +26,3 @@

if (!mutationDef) {
throw new Error('Must contain a mutation definition.');
}
invariant(mutationDef, 'Must contain a mutation definition.');

@@ -33,6 +34,7 @@ return mutationDef;

export function checkDocument(doc: DocumentNode) {
if (!doc || doc.kind !== 'Document') {
throw new Error(`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`);
}
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`,
);

@@ -43,3 +45,3 @@ const operations = doc.definitions

if (definition.kind !== 'OperationDefinition') {
throw new Error(
throw new InvariantError(
`Schema type definitions not allowed in queries. Found: "${

@@ -53,7 +55,6 @@ definition.kind

if (operations.length > 1) {
throw new Error(
`Ambiguous GraphQL document: contains ${operations.length} operations`,
);
}
invariant(
operations.length <= 1,
`Ambiguous GraphQL document: contains ${operations.length} operations`,
);

@@ -76,5 +77,3 @@ return doc;

const def = getOperationDefinition(document);
if (!def) {
throw new Error(`GraphQL document is missing an operation`);
}
invariant(def, `GraphQL document is missing an operation`);
return def;

@@ -106,5 +105,6 @@ }

if (!queryDef || queryDef.operation !== 'query') {
throw new Error('Must contain a query definition.');
}
invariant(
queryDef && queryDef.operation === 'query',
'Must contain a query definition.',
);

@@ -117,16 +117,19 @@ return queryDef;

): FragmentDefinitionNode {
if (doc.kind !== 'Document') {
throw new Error(`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`);
}
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`,
);
if (doc.definitions.length > 1) {
throw new Error('Fragment must have exactly one definition.');
}
invariant(
doc.definitions.length <= 1,
'Fragment must have exactly one definition.',
);
const fragmentDef = doc.definitions[0] as FragmentDefinitionNode;
if (fragmentDef.kind !== 'FragmentDefinition') {
throw new Error('Must be a fragment definition.');
}
invariant(
fragmentDef.kind === 'FragmentDefinition',
'Must be a fragment definition.',
);

@@ -170,3 +173,3 @@ return fragmentDef as FragmentDefinitionNode;

throw new Error(
throw new InvariantError(
'Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.',

@@ -173,0 +176,0 @@ );

@@ -20,2 +20,3 @@ import {

import stringify from 'fast-json-stable-stringify';
import { InvariantError } from 'ts-invariant';

@@ -131,3 +132,3 @@ export interface IdValue {

} else {
throw new Error(
throw new InvariantError(
`The inline argument "${name.value}" of kind "${(value as any).kind}"` +

@@ -308,3 +309,3 @@ 'is not supported. Use variables instead of inline arguments to ' +

function defaultValueFromVariable(node: VariableNode) {
throw new Error(`Variable nodes are not supported by valueFromNode`);
throw new InvariantError(`Variable nodes are not supported by valueFromNode`);
}

@@ -311,0 +312,0 @@

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

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

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

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

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

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