planning
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s

This commit is contained in:
2024-10-14 09:15:30 +02:00
parent bcba00a730
commit 6e64e138e2
21059 changed files with 2317811 additions and 1 deletions

8
node_modules/apollo-utilities/.flowconfig generated vendored Normal file
View File

@@ -0,0 +1,8 @@
[ignore]
[include]
[libs]
[options]
suppress_comment= \\(.\\|\n\\)*\\$ExpectError

106
node_modules/apollo-utilities/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,106 @@
# CHANGELOG
----
**NOTE:** This changelog is no longer maintained. Changes are now tracked in
the top level [`CHANGELOG.md`](https://github.com/apollographql/apollo-client/blob/master/CHANGELOG.md).
----
### 1.0.16
- Removed unnecessary whitespace from error message
[Issue #3398](https://github.com/apollographql/apollo-client/issues/3398)
[PR #3593](https://github.com/apollographql/apollo-client/pull/3593)
### 1.0.15
- No changes
### 1.0.14
- Store key names generated by `getStoreKeyName` now leverage a more
deterministic approach to handling JSON based strings. This prevents store
key names from differing when using `args` like
`{ prop1: 'value1', prop2: 'value2' }` and
`{ prop2: 'value2', prop1: 'value1' }`.
[PR #2869](https://github.com/apollographql/apollo-client/pull/2869)
- Avoid needless `hasOwnProperty` check in `deepFreeze`.
[PR #3545](https://github.com/apollographql/apollo-client/pull/3545)
### 1.0.13
- Make `maybeDeepFreeze` a little more defensive, by always using
`Object.prototype.hasOwnProperty` (to avoid cases where the object being
frozen doesn't have its own `hasOwnProperty`).
[Issue #3426](https://github.com/apollographql/apollo-client/issues/3426)
[PR #3418](https://github.com/apollographql/apollo-client/pull/3418)
- Remove certain small internal caches to prevent memory leaks when using SSR.
[PR #3444](https://github.com/apollographql/apollo-client/pull/3444)
### 1.0.12
- Not documented
### 1.0.11
- `toIdValue` helper now takes an object with `id` and `typename` properties
as the preferred interface
[PR #3159](https://github.com/apollographql/apollo-client/pull/3159)
- Map coverage to original source
- Don't `deepFreeze` in development/test environments if ES6 symbols are
polyfilled
[PR #3082](https://github.com/apollographql/apollo-client/pull/3082)
- Added ability to include or ignore fragments in `getDirectivesFromDocument`
[PR #3010](https://github.com/apollographql/apollo-client/pull/3010)
### 1.0.9
- Dependency updates
- Added getDirectivesFromDocument utility function
[PR #2974](https://github.com/apollographql/apollo-client/pull/2974)
### 1.0.8
- Add client, rest, and export directives to list of known directives
[PR #2949](https://github.com/apollographql/apollo-client/pull/2949)
### 1.0.7
- Fix typo in error message for invalid argument being passed to @skip or
@include directives
[PR #2867](https://github.com/apollographql/apollo-client/pull/2867)
### 1.0.6
- Update `getStoreKeyName` to support custom directives
### 1.0.5
- Package dependency updates
### 1.0.4
- Package dependency updates
### 1.0.3
- Package dependency updates
### 1.0.2
- Improved rollup builds
### 1.0.1
- Added config to remove selection set of directive matches test
### 1.0.0
- Added utilities from hermes cache
- Added removeDirectivesFromDocument to allow cleaning of client only
directives
- Added hasDirectives to recurse the AST and return a boolean for an array of
directive names
- Improved performance of common store actions by memoizing addTypename and
removeConnectionDirective

22
node_modules/apollo-utilities/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2018 Meteor Development Group, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3
node_modules/apollo-utilities/jest.config.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
module.exports = {
...require('../../config/jest.config.settings'),
};

1125
node_modules/apollo-utilities/lib/bundle.cjs.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

1
node_modules/apollo-utilities/lib/bundle.cjs.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

1
node_modules/apollo-utilities/lib/bundle.cjs.min.js generated vendored Normal file

File diff suppressed because one or more lines are too long

915
node_modules/apollo-utilities/lib/bundle.esm.js generated vendored Normal file
View File

@@ -0,0 +1,915 @@
import { visit } from 'graphql/language/visitor';
import { InvariantError, invariant } from 'ts-invariant';
import { __assign, __spreadArrays } from 'tslib';
import stringify from 'fast-json-stable-stringify';
export { equal as isEqual } from '@wry/equality';
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 InvariantError(17) : new 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 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',
];
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;
}
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;
}
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 __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 InvariantError(18) : new 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;
}
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;
}
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" ? invariant(evaledValue !== void 0, 13) : 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 = [];
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" ? invariant(directiveArguments && directiveArguments.length === 1, 14) : invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
var ifArgument = directiveArguments[0];
process.env.NODE_ENV === "production" ? invariant(ifArgument.name && ifArgument.name.value === 'if', 15) : invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.");
var ifValue = ifArgument.value;
process.env.NODE_ENV === "production" ? invariant(ifValue &&
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 16) : 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 InvariantError(11) : new 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" ? invariant(fragments.length === 1, 12) : 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(__assign({}, document), { definitions: __spreadArrays([
{
kind: 'OperationDefinition',
operation: 'query',
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'FragmentSpread',
name: {
kind: 'Name',
value: actualFragmentName,
},
},
],
},
}
], document.definitions) });
return query;
}
function assign(target) {
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;
}
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" ? invariant(mutationDef, 1) : invariant(mutationDef, 'Must contain a mutation definition.');
return mutationDef;
}
function checkDocument(doc) {
process.env.NODE_ENV === "production" ? invariant(doc && doc.kind === 'Document', 2) : 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 InvariantError(3) : new InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
}
return definition;
});
process.env.NODE_ENV === "production" ? invariant(operations.length <= 1, 4) : 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" ? invariant(def, 5) : 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" ? invariant(queryDef && queryDef.operation === 'query', 6) : invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.');
return queryDef;
}
function getFragmentDefinition(doc) {
process.env.NODE_ENV === "production" ? invariant(doc.kind === 'Document', 7) : 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" ? invariant(doc.definitions.length <= 1, 8) : invariant(doc.definitions.length <= 1, 'Fragment must have exactly one definition.');
var fragmentDef = doc.definitions[0];
process.env.NODE_ENV === "production" ? invariant(fragmentDef.kind === 'FragmentDefinition', 9) : 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;
}
throw process.env.NODE_ENV === "production" ? new InvariantError(10) : new 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;
}
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, __spreadArrays([{}], 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);
}
}
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 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(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);
}
if (modifiedDoc &&
filterInPlace(fragmentSpreadsToRemove, function (fs) { return !fragmentSpreadsInUse[fs.name]; })
.length) {
modifiedDoc = removeFragmentSpreadFromDocument(fragmentSpreadsToRemove, modifiedDoc);
}
return modifiedDoc;
}
function addTypenameToDocument(doc) {
return 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 __assign(__assign({}, node), { selections: __spreadArrays(selections, [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" || 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));
}
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;
}
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(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 __assign(__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)));
});
};
}
function removeArgumentsFromDocument(config, doc) {
var argMatcher = getArgumentMatcher(config);
return nullIfDocIsEmpty(visit(doc, {
OperationDefinition: {
enter: function (node) {
return __assign(__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;
}
}
return nullIfDocIsEmpty(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;
}
function buildQueryFromSelectionSet(document) {
var definition = getMainDefinition(document);
var definitionOperation = definition.operation;
if (definitionOperation === 'query') {
return document;
}
var modifiedDoc = visit(document, {
OperationDefinition: {
enter: function (node) {
return __assign(__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 = 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 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;
}
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';
}
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 graphQLResultHasError(result) {
return result.errors && result.errors.length;
}
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);
}
}
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);
}
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 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 = __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);
}
}
}
function stripSymbols(data) {
return JSON.parse(JSON.stringify(data));
}
export { addTypenameToDocument, argumentsObjectFromField, assign, buildQueryFromSelectionSet, canUseWeakMap, checkDocument, cloneDeep, createFragmentMap, getDefaultValues, getDirectiveInfoFromField, getDirectiveNames, getDirectivesFromDocument, getEnv, getFragmentDefinition, getFragmentDefinitions, getFragmentQueryDocument, getInclusionDirectives, getMainDefinition, getMutationDefinition, getOperationDefinition, getOperationDefinitionOrDie, getOperationName, getQueryDefinition, getStoreKeyName, graphQLResultHasError, hasClientExports, hasDirectives, isDevelopment, isEnv, isField, isIdValue, isInlineFragment, isJsonValue, isNumberValue, isProduction, isScalarValue, isTest, maybeDeepFreeze, mergeDeep, mergeDeepArray, removeArgumentsFromDocument, removeClientSetsFromDocument, removeConnectionDirectiveFromDocument, removeDirectivesFromDocument, removeFragmentSpreadFromDocument, resultKeyNameFromField, shouldInclude, storeKeyNameFromField, stripSymbols, toIdValue, tryFunctionOrLogError, valueFromNode, valueToObjectRepresentation, variablesInOperation, warnOnceInDevelopment };
//# sourceMappingURL=bundle.esm.js.map

1
node_modules/apollo-utilities/lib/bundle.esm.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

1131
node_modules/apollo-utilities/lib/bundle.umd.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

1
node_modules/apollo-utilities/lib/bundle.umd.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

19
node_modules/apollo-utilities/lib/directives.d.ts generated vendored Normal file
View File

@@ -0,0 +1,19 @@
import { FieldNode, SelectionNode, DirectiveNode, DocumentNode, ArgumentNode } from 'graphql';
export declare type DirectiveInfo = {
[fieldName: string]: {
[argName: string]: any;
};
};
export declare function getDirectiveInfoFromField(field: FieldNode, variables: Object): DirectiveInfo;
export declare function shouldInclude(selection: SelectionNode, variables?: {
[name: string]: any;
}): boolean;
export declare function getDirectiveNames(doc: DocumentNode): string[];
export declare function hasDirectives(names: string[], doc: DocumentNode): boolean;
export declare function hasClientExports(document: DocumentNode): boolean;
export declare type InclusionDirectives = Array<{
directive: DirectiveNode;
ifArgument: ArgumentNode;
}>;
export declare function getInclusionDirectives(directives: ReadonlyArray<DirectiveNode>): InclusionDirectives;
//# sourceMappingURL=directives.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"directives.d.ts","sourceRoot":"","sources":["src/directives.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,SAAS,EACT,aAAa,EAGb,aAAa,EACb,YAAY,EACZ,YAAY,EAEb,MAAM,SAAS,CAAC;AAQjB,oBAAY,aAAa,GAAG;IAC1B,CAAC,SAAS,EAAE,MAAM,GAAG;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACjD,CAAC;AAEF,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,GAChB,aAAa,CAYf;AAED,wBAAgB,aAAa,CAC3B,SAAS,EAAE,aAAa,EACxB,SAAS,GAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAA;CAAO,GACtC,OAAO,CAgBT;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,YAUlD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,YAAY,WAI/D;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,WAMtD;AAED,oBAAY,mBAAmB,GAAG,KAAK,CAAC;IACtC,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,YAAY,CAAC;CAC1B,CAAC,CAAC;AAMH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,aAAa,CAAC,aAAa,CAAC,GACvC,mBAAmB,CA2BrB"}

71
node_modules/apollo-utilities/lib/directives.js generated vendored Normal file
View File

@@ -0,0 +1,71 @@
"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] = storeUtils_1.argumentsObjectFromField(directive, variables);
});
return directiveObj_1;
}
return null;
}
exports.getDirectiveInfoFromField = getDirectiveInfoFromField;
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];
ts_invariant_1.invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.");
}
else {
evaledValue = ifArgument.value.value;
}
return directive.name.value === 'skip' ? !evaledValue : evaledValue;
});
}
exports.shouldInclude = shouldInclude;
function getDirectiveNames(doc) {
var names = [];
visitor_1.visit(doc, {
Directive: function (node) {
names.push(node.name.value);
},
});
return names;
}
exports.getDirectiveNames = getDirectiveNames;
function hasDirectives(names, doc) {
return getDirectiveNames(doc).some(function (name) { return names.indexOf(name) > -1; });
}
exports.hasDirectives = hasDirectives;
function hasClientExports(document) {
return (document &&
hasDirectives(['client'], document) &&
hasDirectives(['export'], document));
}
exports.hasClientExports = hasClientExports;
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;
ts_invariant_1.invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
var ifArgument = directiveArguments[0];
ts_invariant_1.invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.");
var ifValue = ifArgument.value;
ts_invariant_1.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 };
}) : [];
}
exports.getInclusionDirectives = getInclusionDirectives;
//# sourceMappingURL=directives.js.map

1
node_modules/apollo-utilities/lib/directives.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"directives.js","sourceRoot":"","sources":["../src/directives.ts"],"names":[],"mappings":";;AAaA,oDAAiD;AAEjD,6CAAyC;AAEzC,2CAAwD;AAMxD,SAAgB,yBAAyB,CACvC,KAAgB,EAChB,SAAiB;IAEjB,IAAI,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE;QAC/C,IAAM,cAAY,GAAkB,EAAE,CAAC;QACvC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,UAAC,SAAwB;YAChD,cAAY,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,qCAAwB,CAC3D,SAAS,EACT,SAAS,CACV,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,OAAO,cAAY,CAAC;KACrB;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAfD,8DAeC;AAED,SAAgB,aAAa,CAC3B,SAAwB,EACxB,SAAuC;IAAvC,0BAAA,EAAA,cAAuC;IAEvC,OAAO,sBAAsB,CAC3B,SAAS,CAAC,UAAU,CACrB,CAAC,KAAK,CAAC,UAAC,EAAyB;YAAvB,wBAAS,EAAE,0BAAU;QAC9B,IAAI,WAAW,GAAY,KAAK,CAAC;QACjC,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE;YACxC,WAAW,GAAG,SAAS,CAAE,UAAU,CAAC,KAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvE,wBAAS,CACP,WAAW,KAAK,KAAK,CAAC,EACtB,qCAAmC,SAAS,CAAC,IAAI,CAAC,KAAK,gBAAa,CACrE,CAAC;SACH;aAAM;YACL,WAAW,GAAI,UAAU,CAAC,KAA0B,CAAC,KAAK,CAAC;SAC5D;QACD,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC;AAnBD,sCAmBC;AAED,SAAgB,iBAAiB,CAAC,GAAiB;IACjD,IAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,eAAK,CAAC,GAAG,EAAE;QACT,SAAS,YAAC,IAAI;YACZ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC;AAVD,8CAUC;AAED,SAAgB,aAAa,CAAC,KAAe,EAAE,GAAiB;IAC9D,OAAO,iBAAiB,CAAC,GAAG,CAAC,CAAC,IAAI,CAChC,UAAC,IAAY,IAAK,OAAA,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAxB,CAAwB,CAC3C,CAAC;AACJ,CAAC;AAJD,sCAIC;AAED,SAAgB,gBAAgB,CAAC,QAAsB;IACrD,OAAO,CACL,QAAQ;QACR,aAAa,CAAC,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;QACnC,aAAa,CAAC,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CACpC,CAAC;AACJ,CAAC;AAND,4CAMC;AAOD,SAAS,oBAAoB,CAAC,EAAkC;QAAxB,qBAAK;IAC3C,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,SAAgB,sBAAsB,CACpC,UAAwC;IAExC,OAAO,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,UAAA,SAAS;QACvE,IAAM,kBAAkB,GAAG,SAAS,CAAC,SAAS,CAAC;QAC/C,IAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;QAE3C,wBAAS,CACP,kBAAkB,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,EACrD,4CAA0C,aAAa,gBAAa,CACrE,CAAC;QAEF,IAAM,UAAU,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;QACzC,wBAAS,CACP,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,EACjD,+BAA6B,aAAa,gBAAa,CACxD,CAAC;QAEF,IAAM,OAAO,GAAc,UAAU,CAAC,KAAK,CAAC;QAG5C,wBAAS,CACP,OAAO;YACL,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,EAClE,uBAAqB,aAAa,sDAAmD,CACtF,CAAC;QAEF,OAAO,EAAE,SAAS,WAAA,EAAE,UAAU,YAAA,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACV,CAAC;AA7BD,wDA6BC"}

3
node_modules/apollo-utilities/lib/fragments.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
import { DocumentNode } from 'graphql';
export declare function getFragmentQueryDocument(document: DocumentNode, fragmentName?: string): DocumentNode;
//# sourceMappingURL=fragments.d.ts.map

1
node_modules/apollo-utilities/lib/fragments.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"fragments.d.ts","sourceRoot":"","sources":["src/fragments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0B,MAAM,SAAS,CAAC;AAyB/D,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,YAAY,EACtB,YAAY,CAAC,EAAE,MAAM,GACpB,YAAY,CA+Dd"}

42
node_modules/apollo-utilities/lib/fragments.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
"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;
var fragments = [];
document.definitions.forEach(function (definition) {
if (definition.kind === 'OperationDefinition') {
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.');
}
if (definition.kind === 'FragmentDefinition') {
fragments.push(definition);
}
});
if (typeof actualFragmentName === 'undefined') {
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;
}
var query = tslib_1.__assign(tslib_1.__assign({}, document), { definitions: tslib_1.__spreadArrays([
{
kind: 'OperationDefinition',
operation: 'query',
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'FragmentSpread',
name: {
kind: 'Name',
value: actualFragmentName,
},
},
],
},
}
], document.definitions) });
return query;
}
exports.getFragmentQueryDocument = getFragmentQueryDocument;
//# sourceMappingURL=fragments.js.map

1
node_modules/apollo-utilities/lib/fragments.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"fragments.js","sourceRoot":"","sources":["../src/fragments.ts"],"names":[],"mappings":";;;AACA,6CAAyD;AAwBzD,SAAgB,wBAAwB,CACtC,QAAsB,EACtB,YAAqB;IAErB,IAAI,kBAAkB,GAAG,YAAY,CAAC;IAKtC,IAAM,SAAS,GAAkC,EAAE,CAAC;IACpD,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,UAAA,UAAU;QAGrC,IAAI,UAAU,CAAC,IAAI,KAAK,qBAAqB,EAAE;YAC7C,MAAM,IAAI,6BAAc,CACtB,aAAW,UAAU,CAAC,SAAS,mBAC7B,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,aAAW,UAAU,CAAC,IAAI,CAAC,KAAK,MAAG,CAAC,CAAC,CAAC,EAAE,QACxD;gBACF,yFAAyF,CAC5F,CAAC;SACH;QAGD,IAAI,UAAU,CAAC,IAAI,KAAK,oBAAoB,EAAE;YAC5C,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SAC5B;IACH,CAAC,CAAC,CAAC;IAIH,IAAI,OAAO,kBAAkB,KAAK,WAAW,EAAE;QAC7C,wBAAS,CACP,SAAS,CAAC,MAAM,KAAK,CAAC,EACtB,WACE,SAAS,CAAC,MAAM,sFACmE,CACtF,CAAC;QACF,kBAAkB,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;KAC9C;IAID,IAAM,KAAK,yCACN,QAAQ,KACX,WAAW;YACT;gBACE,IAAI,EAAE,qBAAqB;gBAC3B,SAAS,EAAE,OAAO;gBAClB,YAAY,EAAE;oBACZ,IAAI,EAAE,cAAc;oBACpB,UAAU,EAAE;wBACV;4BACE,IAAI,EAAE,gBAAgB;4BACtB,IAAI,EAAE;gCACJ,IAAI,EAAE,MAAM;gCACZ,KAAK,EAAE,kBAAkB;6BAC1B;yBACF;qBACF;iBACF;aACF;WACE,QAAQ,CAAC,WAAW,IAE1B,CAAC;IAEF,OAAO,KAAK,CAAC;AACf,CAAC;AAlED,4DAkEC"}

20
node_modules/apollo-utilities/lib/getFromAST.d.ts generated vendored Normal file
View File

@@ -0,0 +1,20 @@
import { DocumentNode, OperationDefinitionNode, FragmentDefinitionNode } from 'graphql';
import { JsonValue } from './storeUtils';
export declare function getMutationDefinition(doc: DocumentNode): OperationDefinitionNode;
export declare function checkDocument(doc: DocumentNode): DocumentNode;
export declare function getOperationDefinition(doc: DocumentNode): OperationDefinitionNode | undefined;
export declare function getOperationDefinitionOrDie(document: DocumentNode): OperationDefinitionNode;
export declare function getOperationName(doc: DocumentNode): string | null;
export declare function getFragmentDefinitions(doc: DocumentNode): FragmentDefinitionNode[];
export declare function getQueryDefinition(doc: DocumentNode): OperationDefinitionNode;
export declare function getFragmentDefinition(doc: DocumentNode): FragmentDefinitionNode;
export declare function getMainDefinition(queryDoc: DocumentNode): OperationDefinitionNode | FragmentDefinitionNode;
export interface FragmentMap {
[fragmentName: string]: FragmentDefinitionNode;
}
export declare function createFragmentMap(fragments?: FragmentDefinitionNode[]): FragmentMap;
export declare function getDefaultValues(definition: OperationDefinitionNode | undefined): {
[key: string]: JsonValue;
};
export declare function variablesInOperation(operation: OperationDefinitionNode): Set<string>;
//# sourceMappingURL=getFromAST.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getFromAST.d.ts","sourceRoot":"","sources":["src/getFromAST.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,sBAAsB,EAEvB,MAAM,SAAS,CAAC;AAMjB,OAAO,EAA+B,SAAS,EAAE,MAAM,cAAc,CAAC;AAEtE,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,YAAY,GAChB,uBAAuB,CAYzB;AAGD,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,gBA0B9C;AAED,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,YAAY,GAChB,uBAAuB,GAAG,SAAS,CAKrC;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,YAAY,GACrB,uBAAuB,CAIzB;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CASjE;AAGD,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,YAAY,GAChB,sBAAsB,EAAE,CAI1B;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,GAAG,uBAAuB,CAS7E;AAED,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,YAAY,GAChB,sBAAsB,CAoBxB;AAOD,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,YAAY,GACrB,uBAAuB,GAAG,sBAAsB,CA8BlD;AAKD,MAAM,WAAW,WAAW;IAC1B,CAAC,YAAY,EAAE,MAAM,GAAG,sBAAsB,CAAC;CAChD;AAID,wBAAgB,iBAAiB,CAC/B,SAAS,GAAE,sBAAsB,EAAO,GACvC,WAAW,CAOb;AAED,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,uBAAuB,GAAG,SAAS,GAC9C;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAyB9B;AAKD,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,uBAAuB,GACjC,GAAG,CAAC,MAAM,CAAC,CASb"}

131
node_modules/apollo-utilities/lib/getFromAST.js generated vendored Normal file
View File

@@ -0,0 +1,131 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ts_invariant_1 = require("ts-invariant");
var assign_1 = require("./util/assign");
var storeUtils_1 = require("./storeUtils");
function getMutationDefinition(doc) {
checkDocument(doc);
var mutationDef = doc.definitions.filter(function (definition) {
return definition.kind === 'OperationDefinition' &&
definition.operation === 'mutation';
})[0];
ts_invariant_1.invariant(mutationDef, 'Must contain a mutation definition.');
return mutationDef;
}
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
.filter(function (d) { return d.kind !== 'FragmentDefinition'; })
.map(function (definition) {
if (definition.kind !== 'OperationDefinition') {
throw new ts_invariant_1.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
}
return definition;
});
ts_invariant_1.invariant(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations");
return doc;
}
exports.checkDocument = checkDocument;
function getOperationDefinition(doc) {
checkDocument(doc);
return doc.definitions.filter(function (definition) { return definition.kind === 'OperationDefinition'; })[0];
}
exports.getOperationDefinition = getOperationDefinition;
function getOperationDefinitionOrDie(document) {
var def = getOperationDefinition(document);
ts_invariant_1.invariant(def, "GraphQL document is missing an operation");
return def;
}
exports.getOperationDefinitionOrDie = getOperationDefinitionOrDie;
function getOperationName(doc) {
return (doc.definitions
.filter(function (definition) {
return definition.kind === 'OperationDefinition' && definition.name;
})
.map(function (x) { return x.name.value; })[0] || null);
}
exports.getOperationName = getOperationName;
function getFragmentDefinitions(doc) {
return doc.definitions.filter(function (definition) { return definition.kind === 'FragmentDefinition'; });
}
exports.getFragmentDefinitions = getFragmentDefinitions;
function getQueryDefinition(doc) {
var queryDef = getOperationDefinition(doc);
ts_invariant_1.invariant(queryDef && queryDef.operation === 'query', 'Must contain a query definition.');
return queryDef;
}
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];
ts_invariant_1.invariant(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.');
return fragmentDef;
}
exports.getFragmentDefinition = getFragmentDefinition;
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;
}
throw new ts_invariant_1.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.');
}
exports.getMainDefinition = getMainDefinition;
function createFragmentMap(fragments) {
if (fragments === void 0) { fragments = []; }
var symTable = {};
fragments.forEach(function (fragment) {
symTable[fragment.name.value] = fragment;
});
return symTable;
}
exports.createFragmentMap = createFragmentMap;
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 = {};
storeUtils_1.valueToObjectRepresentation(defaultValueObj, variable.name, defaultValue);
return defaultValueObj;
});
return assign_1.assign.apply(void 0, tslib_1.__spreadArrays([{}], defaultValues));
}
return {};
}
exports.getDefaultValues = getDefaultValues;
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);
}
}
return names;
}
exports.variablesInOperation = variablesInOperation;
//# sourceMappingURL=getFromAST.js.map

1
node_modules/apollo-utilities/lib/getFromAST.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"getFromAST.js","sourceRoot":"","sources":["../src/getFromAST.ts"],"names":[],"mappings":";;;AAOA,6CAAyD;AAEzD,wCAAuC;AAEvC,2CAAsE;AAEtE,SAAgB,qBAAqB,CACnC,GAAiB;IAEjB,aAAa,CAAC,GAAG,CAAC,CAAC;IAEnB,IAAI,WAAW,GAAmC,GAAG,CAAC,WAAW,CAAC,MAAM,CACtE,UAAA,UAAU;QACR,OAAA,UAAU,CAAC,IAAI,KAAK,qBAAqB;YACzC,UAAU,CAAC,SAAS,KAAK,UAAU;IADnC,CACmC,CACtC,CAAC,CAAC,CAA4B,CAAC;IAEhC,wBAAS,CAAC,WAAW,EAAE,qCAAqC,CAAC,CAAC;IAE9D,OAAO,WAAW,CAAC;AACrB,CAAC;AAdD,sDAcC;AAGD,SAAgB,aAAa,CAAC,GAAiB;IAC7C,wBAAS,CACP,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,UAAU,EAC9B,0JAC2E,CAC5E,CAAC;IAEF,IAAM,UAAU,GAAG,GAAG,CAAC,WAAW;SAC/B,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,KAAK,oBAAoB,EAA/B,CAA+B,CAAC;SAC5C,GAAG,CAAC,UAAA,UAAU;QACb,IAAI,UAAU,CAAC,IAAI,KAAK,qBAAqB,EAAE;YAC7C,MAAM,IAAI,6BAAc,CACtB,8DACE,UAAU,CAAC,IAAI,OACd,CACJ,CAAC;SACH;QACD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC,CAAC;IAEL,wBAAS,CACP,UAAU,CAAC,MAAM,IAAI,CAAC,EACtB,0CAAwC,UAAU,CAAC,MAAM,gBAAa,CACvE,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC;AA1BD,sCA0BC;AAED,SAAgB,sBAAsB,CACpC,GAAiB;IAEjB,aAAa,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,GAAG,CAAC,WAAW,CAAC,MAAM,CAC3B,UAAA,UAAU,IAAI,OAAA,UAAU,CAAC,IAAI,KAAK,qBAAqB,EAAzC,CAAyC,CACxD,CAAC,CAAC,CAA4B,CAAC;AAClC,CAAC;AAPD,wDAOC;AAED,SAAgB,2BAA2B,CACzC,QAAsB;IAEtB,IAAM,GAAG,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IAC7C,wBAAS,CAAC,GAAG,EAAE,0CAA0C,CAAC,CAAC;IAC3D,OAAO,GAAG,CAAC;AACb,CAAC;AAND,kEAMC;AAED,SAAgB,gBAAgB,CAAC,GAAiB;IAChD,OAAO,CACL,GAAG,CAAC,WAAW;SACZ,MAAM,CACL,UAAA,UAAU;QACR,OAAA,UAAU,CAAC,IAAI,KAAK,qBAAqB,IAAI,UAAU,CAAC,IAAI;IAA5D,CAA4D,CAC/D;SACA,GAAG,CAAC,UAAC,CAA0B,IAAK,OAAA,CAAC,CAAC,IAAI,CAAC,KAAK,EAAZ,CAAY,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAChE,CAAC;AACJ,CAAC;AATD,4CASC;AAGD,SAAgB,sBAAsB,CACpC,GAAiB;IAEjB,OAAO,GAAG,CAAC,WAAW,CAAC,MAAM,CAC3B,UAAA,UAAU,IAAI,OAAA,UAAU,CAAC,IAAI,KAAK,oBAAoB,EAAxC,CAAwC,CAC3B,CAAC;AAChC,CAAC;AAND,wDAMC;AAED,SAAgB,kBAAkB,CAAC,GAAiB;IAClD,IAAM,QAAQ,GAAG,sBAAsB,CAAC,GAAG,CAA4B,CAAC;IAExE,wBAAS,CACP,QAAQ,IAAI,QAAQ,CAAC,SAAS,KAAK,OAAO,EAC1C,kCAAkC,CACnC,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC;AATD,gDASC;AAED,SAAgB,qBAAqB,CACnC,GAAiB;IAEjB,wBAAS,CACP,GAAG,CAAC,IAAI,KAAK,UAAU,EACvB,0JAC2E,CAC5E,CAAC;IAEF,wBAAS,CACP,GAAG,CAAC,WAAW,CAAC,MAAM,IAAI,CAAC,EAC3B,4CAA4C,CAC7C,CAAC;IAEF,IAAM,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAA2B,CAAC;IAEjE,wBAAS,CACP,WAAW,CAAC,IAAI,KAAK,oBAAoB,EACzC,gCAAgC,CACjC,CAAC;IAEF,OAAO,WAAqC,CAAC;AAC/C,CAAC;AAtBD,sDAsBC;AAOD,SAAgB,iBAAiB,CAC/B,QAAsB;IAEtB,aAAa,CAAC,QAAQ,CAAC,CAAC;IAExB,IAAI,kBAAkB,CAAC;IAEvB,KAAuB,UAAoB,EAApB,KAAA,QAAQ,CAAC,WAAW,EAApB,cAAoB,EAApB,IAAoB,EAAE;QAAxC,IAAI,UAAU,SAAA;QACjB,IAAI,UAAU,CAAC,IAAI,KAAK,qBAAqB,EAAE;YAC7C,IAAM,SAAS,GAAI,UAAsC,CAAC,SAAS,CAAC;YACpE,IACE,SAAS,KAAK,OAAO;gBACrB,SAAS,KAAK,UAAU;gBACxB,SAAS,KAAK,cAAc,EAC5B;gBACA,OAAO,UAAqC,CAAC;aAC9C;SACF;QACD,IAAI,UAAU,CAAC,IAAI,KAAK,oBAAoB,IAAI,CAAC,kBAAkB,EAAE;YAGnE,kBAAkB,GAAG,UAAoC,CAAC;SAC3D;KACF;IAED,IAAI,kBAAkB,EAAE;QACtB,OAAO,kBAAkB,CAAC;KAC3B;IAED,MAAM,IAAI,6BAAc,CACtB,sFAAsF,CACvF,CAAC;AACJ,CAAC;AAhCD,8CAgCC;AAWD,SAAgB,iBAAiB,CAC/B,SAAwC;IAAxC,0BAAA,EAAA,cAAwC;IAExC,IAAM,QAAQ,GAAgB,EAAE,CAAC;IACjC,SAAS,CAAC,OAAO,CAAC,UAAA,QAAQ;QACxB,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC;AATD,8CASC;AAED,SAAgB,gBAAgB,CAC9B,UAA+C;IAE/C,IACE,UAAU;QACV,UAAU,CAAC,mBAAmB;QAC9B,UAAU,CAAC,mBAAmB,CAAC,MAAM,EACrC;QACA,IAAM,aAAa,GAAG,UAAU,CAAC,mBAAmB;aACjD,MAAM,CAAC,UAAC,EAAgB;gBAAd,8BAAY;YAAO,OAAA,YAAY;QAAZ,CAAY,CAAC;aAC1C,GAAG,CACF,UAAC,EAA0B;gBAAxB,sBAAQ,EAAE,8BAAY;YACvB,IAAM,eAAe,GAAiC,EAAE,CAAC;YACzD,wCAA2B,CACzB,eAAe,EACf,QAAQ,CAAC,IAAI,EACb,YAAyB,CAC1B,CAAC;YAEF,OAAO,eAAe,CAAC;QACzB,CAAC,CACF,CAAC;QAEJ,OAAO,eAAM,uCAAC,EAAE,GAAK,aAAa,GAAE;KACrC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AA3BD,4CA2BC;AAKD,SAAgB,oBAAoB,CAClC,SAAkC;IAElC,IAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,IAAI,SAAS,CAAC,mBAAmB,EAAE;QACjC,KAAyB,UAA6B,EAA7B,KAAA,SAAS,CAAC,mBAAmB,EAA7B,cAA6B,EAA7B,IAA6B,EAAE;YAAnD,IAAM,UAAU,SAAA;YACnB,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAC3C;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAXD,oDAWC"}

17
node_modules/apollo-utilities/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,17 @@
export * from './directives';
export * from './fragments';
export * from './getFromAST';
export * from './transform';
export * from './storeUtils';
export * from './util/assign';
export * from './util/canUse';
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';
//# sourceMappingURL=index.d.ts.map

1
node_modules/apollo-utilities/lib/index.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC"}

20
node_modules/apollo-utilities/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
"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/canUse"), 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

1
node_modules/apollo-utilities/lib/index.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,sDAA4B;AAC5B,uDAA6B;AAC7B,sDAA4B;AAC5B,uDAA6B;AAC7B,wDAA8B;AAC9B,wDAA8B;AAC9B,2DAAiC;AACjC,6DAAmC;AACnC,+DAAqC;AACrC,yDAA+B;AAC/B,iEAAuC;AACvC,2DAAiC;AACjC,0DAAgC;AAChC,8DAAoC;AACpC,2DAAiC"}

39
node_modules/apollo-utilities/lib/storeUtils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,39 @@
import { DirectiveNode, FieldNode, IntValueNode, FloatValueNode, StringValueNode, BooleanValueNode, EnumValueNode, VariableNode, InlineFragmentNode, ValueNode, SelectionNode, NameNode } from 'graphql';
export interface IdValue {
type: 'id';
id: string;
generated: boolean;
typename: string | undefined;
}
export interface JsonValue {
type: 'json';
json: any;
}
export declare type ListValue = Array<null | IdValue>;
export declare type StoreValue = number | string | string[] | IdValue | ListValue | JsonValue | null | undefined | void | Object;
export declare type ScalarValue = StringValueNode | BooleanValueNode | EnumValueNode;
export declare function isScalarValue(value: ValueNode): value is ScalarValue;
export declare type NumberValue = IntValueNode | FloatValueNode;
export declare function isNumberValue(value: ValueNode): value is NumberValue;
export declare function valueToObjectRepresentation(argObj: any, name: NameNode, value: ValueNode, variables?: Object): void;
export declare function storeKeyNameFromField(field: FieldNode, variables?: Object): string;
export declare type Directives = {
[directiveName: string]: {
[argName: string]: any;
};
};
export declare function getStoreKeyName(fieldName: string, args?: Object, directives?: Directives): string;
export declare function argumentsObjectFromField(field: FieldNode | DirectiveNode, variables: Object): Object;
export declare function resultKeyNameFromField(field: FieldNode): string;
export declare function isField(selection: SelectionNode): selection is FieldNode;
export declare function isInlineFragment(selection: SelectionNode): selection is InlineFragmentNode;
export declare function isIdValue(idObject: StoreValue): idObject is IdValue;
export declare type IdConfig = {
id: string;
typename: string | undefined;
};
export declare function toIdValue(idConfig: string | IdConfig, generated?: boolean): IdValue;
export declare function isJsonValue(jsonObject: StoreValue): jsonObject is JsonValue;
export declare type VariableValue = (node: VariableNode) => any;
export declare function valueFromNode(node: ValueNode, onVariable?: VariableValue): any;
//# sourceMappingURL=storeUtils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"storeUtils.d.ts","sourceRoot":"","sources":["src/storeUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EACT,YAAY,EACZ,cAAc,EACd,eAAe,EACf,gBAAgB,EAGhB,aAAa,EAEb,YAAY,EACZ,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,QAAQ,EACT,MAAM,SAAS,CAAC;AAKjB,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,IAAI,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;CACX;AAED,oBAAY,SAAS,GAAG,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC;AAE9C,oBAAY,UAAU,GAClB,MAAM,GACN,MAAM,GACN,MAAM,EAAE,GACR,OAAO,GACP,SAAS,GACT,SAAS,GACT,IAAI,GACJ,SAAS,GACT,IAAI,GACJ,MAAM,CAAC;AAEX,oBAAY,WAAW,GAAG,eAAe,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAE7E,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,WAAW,CAEpE;AAED,oBAAY,WAAW,GAAG,YAAY,GAAG,cAAc,CAAC;AAExD,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,WAAW,CAEpE;AAsCD,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,SAAS,EAChB,SAAS,CAAC,EAAE,MAAM,QAqCnB;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,SAAS,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CA6BR;AAED,oBAAY,UAAU,GAAG;IACvB,CAAC,aAAa,EAAE,MAAM,GAAG;QACvB,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC;KACxB,CAAC;CACH,CAAC;AAWF,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,UAAU,GACtB,MAAM,CAmDR;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,SAAS,GAAG,aAAa,EAChC,SAAS,EAAE,MAAM,GAChB,MAAM,CAUR;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAE/D;AAED,wBAAgB,OAAO,CAAC,SAAS,EAAE,aAAa,GAAG,SAAS,IAAI,SAAS,CAExE;AAED,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,aAAa,GACvB,SAAS,IAAI,kBAAkB,CAEjC;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,UAAU,GAAG,QAAQ,IAAI,OAAO,CAInE;AAED,oBAAY,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B,CAAC;AAEF,wBAAgB,SAAS,CACvB,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAC3B,SAAS,UAAQ,GAChB,OAAO,CAQT;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,SAAS,CAM3E;AAMD,oBAAY,aAAa,GAAG,CAAC,IAAI,EAAE,YAAY,KAAK,GAAG,CAAC;AAKxD,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,EACf,UAAU,GAAE,aAAwC,GACnD,GAAG,CAsBL"}

225
node_modules/apollo-utilities/lib/storeUtils.js generated vendored Normal file
View File

@@ -0,0 +1,225 @@
"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;
}
exports.isScalarValue = isScalarValue;
function isNumberValue(value) {
return ['IntValue', 'FloatValue'].indexOf(value.kind) > -1;
}
exports.isNumberValue = isNumberValue;
function isStringValue(value) {
return value.kind === 'StringValue';
}
function isBooleanValue(value) {
return value.kind === 'BooleanValue';
}
function isIntValue(value) {
return value.kind === 'IntValue';
}
function isFloatValue(value) {
return value.kind === 'FloatValue';
}
function isVariable(value) {
return value.kind === 'Variable';
}
function isObjectValue(value) {
return value.kind === 'ObjectValue';
}
function isListValue(value) {
return value.kind === 'ListValue';
}
function isEnumValue(value) {
return value.kind === 'EnumValue';
}
function 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 new ts_invariant_1.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" +
'is not supported. Use variables instead of inline arguments to ' +
'overcome this limitation.');
}
}
exports.valueToObjectRepresentation = valueToObjectRepresentation;
function storeKeyNameFromField(field, variables) {
var directivesObj = null;
if (field.directives) {
directivesObj = {};
field.directives.forEach(function (directive) {
directivesObj[directive.name.value] = {};
if (directive.arguments) {
directive.arguments.forEach(function (_a) {
var name = _a.name, value = _a.value;
return valueToObjectRepresentation(directivesObj[directive.name.value], name, value, variables);
});
}
});
}
var argObj = null;
if (field.arguments && field.arguments.length) {
argObj = {};
field.arguments.forEach(function (_a) {
var name = _a.name, value = _a.value;
return valueToObjectRepresentation(argObj, name, value, variables);
});
}
return getStoreKeyName(field.name.value, argObj, directivesObj);
}
exports.storeKeyNameFromField = storeKeyNameFromField;
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 = fast_json_stable_stringify_1.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;
}
exports.getStoreKeyName = getStoreKeyName;
function argumentsObjectFromField(field, variables) {
if (field.arguments && field.arguments.length) {
var argObj_1 = {};
field.arguments.forEach(function (_a) {
var name = _a.name, value = _a.value;
return valueToObjectRepresentation(argObj_1, name, value, variables);
});
return argObj_1;
}
return null;
}
exports.argumentsObjectFromField = argumentsObjectFromField;
function resultKeyNameFromField(field) {
return field.alias ? field.alias.value : field.name.value;
}
exports.resultKeyNameFromField = resultKeyNameFromField;
function isField(selection) {
return selection.kind === 'Field';
}
exports.isField = isField;
function isInlineFragment(selection) {
return selection.kind === 'InlineFragment';
}
exports.isInlineFragment = isInlineFragment;
function isIdValue(idObject) {
return idObject &&
idObject.type === 'id' &&
typeof idObject.generated === 'boolean';
}
exports.isIdValue = isIdValue;
function toIdValue(idConfig, generated) {
if (generated === void 0) { generated = false; }
return tslib_1.__assign({ type: 'id', generated: generated }, (typeof idConfig === 'string'
? { id: idConfig, typename: undefined }
: idConfig));
}
exports.toIdValue = toIdValue;
function isJsonValue(jsonObject) {
return (jsonObject != null &&
typeof jsonObject === 'object' &&
jsonObject.type === 'json');
}
exports.isJsonValue = isJsonValue;
function defaultValueFromVariable(node) {
throw new ts_invariant_1.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;
}
default:
return node.value;
}
}
exports.valueFromNode = valueFromNode;
//# sourceMappingURL=storeUtils.js.map

1
node_modules/apollo-utilities/lib/storeUtils.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

26
node_modules/apollo-utilities/lib/transform.d.ts generated vendored Normal file
View File

@@ -0,0 +1,26 @@
import { DocumentNode, DirectiveNode, FragmentDefinitionNode, ArgumentNode, FragmentSpreadNode, VariableDefinitionNode } from 'graphql';
export declare type RemoveNodeConfig<N> = {
name?: string;
test?: (node: N) => boolean;
remove?: boolean;
};
export declare type GetNodeConfig<N> = {
name?: string;
test?: (node: N) => boolean;
};
export declare type RemoveDirectiveConfig = RemoveNodeConfig<DirectiveNode>;
export declare type GetDirectiveConfig = GetNodeConfig<DirectiveNode>;
export declare type RemoveArgumentsConfig = RemoveNodeConfig<ArgumentNode>;
export declare type GetFragmentSpreadConfig = GetNodeConfig<FragmentSpreadNode>;
export declare type RemoveFragmentSpreadConfig = RemoveNodeConfig<FragmentSpreadNode>;
export declare type RemoveFragmentDefinitionConfig = RemoveNodeConfig<FragmentDefinitionNode>;
export declare type RemoveVariableDefinitionConfig = RemoveNodeConfig<VariableDefinitionNode>;
export declare function removeDirectivesFromDocument(directives: RemoveDirectiveConfig[], doc: DocumentNode): DocumentNode | null;
export declare function addTypenameToDocument(doc: DocumentNode): DocumentNode;
export declare function removeConnectionDirectiveFromDocument(doc: DocumentNode): DocumentNode;
export declare function getDirectivesFromDocument(directives: GetDirectiveConfig[], doc: DocumentNode): DocumentNode;
export declare function removeArgumentsFromDocument(config: RemoveArgumentsConfig[], doc: DocumentNode): DocumentNode;
export declare function removeFragmentSpreadFromDocument(config: RemoveFragmentSpreadConfig[], doc: DocumentNode): DocumentNode;
export declare function buildQueryFromSelectionSet(document: DocumentNode): DocumentNode;
export declare function removeClientSetsFromDocument(document: DocumentNode): DocumentNode | null;
//# sourceMappingURL=transform.d.ts.map

1
node_modules/apollo-utilities/lib/transform.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["src/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAKZ,aAAa,EACb,sBAAsB,EACtB,YAAY,EACZ,kBAAkB,EAClB,sBAAsB,EAEvB,MAAM,SAAS,CAAC;AAgBjB,oBAAY,gBAAgB,CAAC,CAAC,IAAI;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,oBAAY,aAAa,CAAC,CAAC,IAAI;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;CAC7B,CAAC;AAEF,oBAAY,qBAAqB,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAC;AACpE,oBAAY,kBAAkB,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAC9D,oBAAY,qBAAqB,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;AACnE,oBAAY,uBAAuB,GAAG,aAAa,CAAC,kBAAkB,CAAC,CAAC;AACxE,oBAAY,0BAA0B,GAAG,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;AAC9E,oBAAY,8BAA8B,GAAG,gBAAgB,CAC3D,sBAAsB,CACvB,CAAC;AACF,oBAAY,8BAA8B,GAAG,gBAAgB,CAC3D,sBAAsB,CACvB,CAAC;AA0CF,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,qBAAqB,EAAE,EACnC,GAAG,EAAE,YAAY,GAChB,YAAY,GAAG,IAAI,CAiHrB;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,YAAY,GAAG,YAAY,CAkDrE;AAqBD,wBAAgB,qCAAqC,CAAC,GAAG,EAAE,YAAY,gBAKtE;AAwCD,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,kBAAkB,EAAE,EAChC,GAAG,EAAE,YAAY,GAChB,YAAY,CAqCd;AAeD,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,qBAAqB,EAAE,EAC/B,GAAG,EAAE,YAAY,GAChB,YAAY,CAgDd;AAED,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,0BAA0B,EAAE,EACpC,GAAG,EAAE,YAAY,GAChB,YAAY,CAed;AA0BD,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,YAAY,GACrB,YAAY,CAqBd;AAGD,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,YAAY,GACrB,YAAY,GAAG,IAAI,CAoCrB"}

311
node_modules/apollo-utilities/lib/transform.js generated vendored Normal file
View File

@@ -0,0 +1,311 @@
"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 ts_invariant_1 = require("ts-invariant");
var storeUtils_1 = require("./storeUtils");
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);
});
}
function nullIfDocIsEmpty(doc) {
return isEmpty(getFromAST_1.getOperationDefinition(doc) || getFromAST_1.getFragmentDefinition(doc), getFromAST_1.createFragmentMap(getFromAST_1.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(visitor_1.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_1.filterInPlace(variablesToRemove, function (v) { return !variablesInUse[v.name]; }).length) {
modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);
}
if (modifiedDoc &&
filterInPlace_1.filterInPlace(fragmentSpreadsToRemove, function (fs) { return !fragmentSpreadsInUse[fs.name]; })
.length) {
modifiedDoc = removeFragmentSpreadFromDocument(fragmentSpreadsToRemove, modifiedDoc);
}
return modifiedDoc;
}
exports.removeDirectivesFromDocument = removeDirectivesFromDocument;
function addTypenameToDocument(doc) {
return visitor_1.visit(getFromAST_1.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 (storeUtils_1.isField(selection) &&
(selection.name.value === '__typename' ||
selection.name.value.lastIndexOf('__', 0) === 0));
});
if (skip) {
return;
}
var field = parent;
if (storeUtils_1.isField(field) &&
field.directives &&
field.directives.some(function (d) { return d.name.value === 'export'; })) {
return;
}
return tslib_1.__assign(tslib_1.__assign({}, node), { selections: tslib_1.__spreadArrays(selections, [TYPENAME_FIELD]) });
},
},
});
}
exports.addTypenameToDocument = addTypenameToDocument;
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'; })) {
ts_invariant_1.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], getFromAST_1.checkDocument(doc));
}
exports.removeConnectionDirectiveFromDocument = removeConnectionDirectiveFromDocument;
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 (!storeUtils_1.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) {
getFromAST_1.checkDocument(doc);
var parentPath;
return nullIfDocIsEmpty(visitor_1.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_1.__assign(tslib_1.__assign({}, node), { selections: selectionsWithDirectives });
}
else {
return null;
}
}
},
},
}));
}
exports.getDirectivesFromDocument = getDirectivesFromDocument;
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 removeArgumentsFromDocument(config, doc) {
var argMatcher = getArgumentMatcher(config);
return nullIfDocIsEmpty(visitor_1.visit(doc, {
OperationDefinition: {
enter: function (node) {
return tslib_1.__assign(tslib_1.__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;
}
},
},
}));
}
exports.removeArgumentsFromDocument = removeArgumentsFromDocument;
function removeFragmentSpreadFromDocument(config, doc) {
function enter(node) {
if (config.some(function (def) { return def.name === node.name.value; })) {
return null;
}
}
return nullIfDocIsEmpty(visitor_1.visit(doc, {
FragmentSpread: { enter: enter },
FragmentDefinition: { enter: enter },
}));
}
exports.removeFragmentSpreadFromDocument = removeFragmentSpreadFromDocument;
function getAllFragmentSpreadsFromSelectionSet(selectionSet) {
var allFragments = [];
selectionSet.selections.forEach(function (selection) {
if ((storeUtils_1.isField(selection) || storeUtils_1.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 = getFromAST_1.getMainDefinition(document);
var definitionOperation = definition.operation;
if (definitionOperation === 'query') {
return document;
}
var modifiedDoc = visitor_1.visit(document, {
OperationDefinition: {
enter: function (node) {
return tslib_1.__assign(tslib_1.__assign({}, node), { operation: 'query' });
},
},
});
return modifiedDoc;
}
exports.buildQueryFromSelectionSet = buildQueryFromSelectionSet;
function removeClientSetsFromDocument(document) {
getFromAST_1.checkDocument(document);
var modifiedDoc = removeDirectivesFromDocument([
{
test: function (directive) { return directive.name.value === 'client'; },
remove: true,
},
], document);
if (modifiedDoc) {
modifiedDoc = visitor_1.visit(modifiedDoc, {
FragmentDefinition: {
enter: function (node) {
if (node.selectionSet) {
var isTypenameOnly = node.selectionSet.selections.every(function (selection) {
return storeUtils_1.isField(selection) && selection.name.value === '__typename';
});
if (isTypenameOnly) {
return null;
}
}
},
},
});
}
return modifiedDoc;
}
exports.removeClientSetsFromDocument = removeClientSetsFromDocument;
//# sourceMappingURL=transform.js.map

1
node_modules/apollo-utilities/lib/transform.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

6
node_modules/apollo-utilities/lib/util/assign.d.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
export declare function assign<A, B>(a: A, b: B): A & B;
export declare function assign<A, B, C>(a: A, b: B, c: C): A & B & C;
export declare function assign<A, B, C, D>(a: A, b: B, c: C, d: D): A & B & C & D;
export declare function assign<A, B, C, D, E>(a: A, b: B, c: C, d: D, e: E): A & B & C & D & E;
export declare function assign(target: any, ...sources: Array<any>): any;
//# sourceMappingURL=assign.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"assign.d.ts","sourceRoot":"","sources":["../src/util/assign.ts"],"names":[],"mappings":"AAMA,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAChD,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC7D,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC1E,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAClC,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,GACH,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACrB,wBAAgB,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC"}

19
node_modules/apollo-utilities/lib/util/assign.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function assign(target) {
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;
}
Object.keys(source).forEach(function (key) {
target[key] = source[key];
});
});
return target;
}
exports.assign = assign;
//# sourceMappingURL=assign.js.map

1
node_modules/apollo-utilities/lib/util/assign.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"assign.js","sourceRoot":"","sources":["../../src/util/assign.ts"],"names":[],"mappings":";;AAiBA,SAAgB,MAAM,CACpB,MAA8B;IAC9B,iBAAyC;SAAzC,UAAyC,EAAzC,qBAAyC,EAAzC,IAAyC;QAAzC,gCAAyC;;IAEzC,OAAO,CAAC,OAAO,CAAC,UAAA,MAAM;QACpB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,IAAI,EAAE;YACpD,OAAO;SACR;QACD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;YAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAbD,wBAaC"}

2
node_modules/apollo-utilities/lib/util/canUse.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export declare const canUseWeakMap: boolean;
//# sourceMappingURL=canUse.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"canUse.d.ts","sourceRoot":"","sources":["../src/util/canUse.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,SAGzB,CAAC"}

5
node_modules/apollo-utilities/lib/util/canUse.js generated vendored Normal file
View File

@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
navigator.product === 'ReactNative');
//# sourceMappingURL=canUse.js.map

1
node_modules/apollo-utilities/lib/util/canUse.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"canUse.js","sourceRoot":"","sources":["../../src/util/canUse.ts"],"names":[],"mappings":";;AAAa,QAAA,aAAa,GAAG,OAAO,OAAO,KAAK,UAAU,IAAI,CAAC,CAC7D,OAAO,SAAS,KAAK,QAAQ;IAC7B,SAAS,CAAC,OAAO,KAAK,aAAa,CACpC,CAAC"}

View File

@@ -0,0 +1,2 @@
export declare function cloneDeep<T>(value: T): T;
//# sourceMappingURL=cloneDeep.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"cloneDeep.d.ts","sourceRoot":"","sources":["../src/util/cloneDeep.ts"],"names":[],"mappings":"AAKA,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAExC"}

34
node_modules/apollo-utilities/lib/util/cloneDeep.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var toString = Object.prototype.toString;
function cloneDeep(value) {
return cloneDeepHelper(value, new Map());
}
exports.cloneDeep = cloneDeep;
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;
}
}
//# sourceMappingURL=cloneDeep.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"cloneDeep.js","sourceRoot":"","sources":["../../src/util/cloneDeep.ts"],"names":[],"mappings":";;AAAQ,IAAA,oCAAQ,CAAsB;AAKtC,SAAgB,SAAS,CAAI,KAAQ;IACnC,OAAO,eAAe,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;AAC3C,CAAC;AAFD,8BAEC;AAED,SAAS,eAAe,CAAI,GAAM,EAAE,IAAmB;IACrD,QAAQ,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAC5B,KAAK,gBAAgB,CAAC,CAAC;YACrB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACxC,IAAM,MAAI,GAAe,GAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC9C,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAI,CAAC,CAAC;YACpB,MAAI,CAAC,OAAO,CAAC,UAAU,KAAK,EAAE,CAAC;gBAC7B,MAAI,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;YACH,OAAO,MAAI,CAAC;SACb;QAED,KAAK,iBAAiB,CAAC,CAAC;YACtB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAGxC,IAAM,MAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;YACvD,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAI,CAAC,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;gBAC1B,MAAI,CAAC,GAAG,CAAC,GAAG,eAAe,CAAE,GAAW,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;YACvD,CAAC,CAAC,CAAC;YACH,OAAO,MAAI,CAAC;SACb;QAED;YACE,OAAO,GAAG,CAAC;KACZ;AACH,CAAC"}

View File

@@ -0,0 +1,6 @@
export declare function getEnv(): string | undefined;
export declare function isEnv(env: string): boolean;
export declare function isProduction(): boolean;
export declare function isDevelopment(): boolean;
export declare function isTest(): boolean;
//# sourceMappingURL=environment.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../src/util/environment.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,IAAI,MAAM,GAAG,SAAS,CAO3C;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE1C;AAED,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED,wBAAgB,MAAM,IAAI,OAAO,CAEhC"}

26
node_modules/apollo-utilities/lib/util/environment.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getEnv() {
if (typeof process !== 'undefined' && process.env.NODE_ENV) {
return process.env.NODE_ENV;
}
return 'development';
}
exports.getEnv = getEnv;
function isEnv(env) {
return getEnv() === env;
}
exports.isEnv = isEnv;
function isProduction() {
return isEnv('production') === true;
}
exports.isProduction = isProduction;
function isDevelopment() {
return isEnv('development') === true;
}
exports.isDevelopment = isDevelopment;
function isTest() {
return isEnv('test') === true;
}
exports.isTest = isTest;
//# sourceMappingURL=environment.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/util/environment.ts"],"names":[],"mappings":";;AAAA,SAAgB,MAAM;IACpB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;QAC1D,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;KAC7B;IAGD,OAAO,aAAa,CAAC;AACvB,CAAC;AAPD,wBAOC;AAED,SAAgB,KAAK,CAAC,GAAW;IAC/B,OAAO,MAAM,EAAE,KAAK,GAAG,CAAC;AAC1B,CAAC;AAFD,sBAEC;AAED,SAAgB,YAAY;IAC1B,OAAO,KAAK,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;AACtC,CAAC;AAFD,oCAEC;AAED,SAAgB,aAAa;IAC3B,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;AACvC,CAAC;AAFD,sCAEC;AAED,SAAgB,MAAM;IACpB,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;AAChC,CAAC;AAFD,wBAEC"}

View File

@@ -0,0 +1,4 @@
import { ExecutionResult } from 'graphql';
export declare function tryFunctionOrLogError(f: Function): any;
export declare function graphQLResultHasError(result: ExecutionResult): number;
//# sourceMappingURL=errorHandling.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"errorHandling.d.ts","sourceRoot":"","sources":["../src/util/errorHandling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,QAAQ,OAQhD;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,UAE5D"}

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function tryFunctionOrLogError(f) {
try {
return f();
}
catch (e) {
if (console.error) {
console.error(e);
}
}
}
exports.tryFunctionOrLogError = tryFunctionOrLogError;
function graphQLResultHasError(result) {
return result.errors && result.errors.length;
}
exports.graphQLResultHasError = graphQLResultHasError;
//# sourceMappingURL=errorHandling.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"errorHandling.js","sourceRoot":"","sources":["../../src/util/errorHandling.ts"],"names":[],"mappings":";;AAEA,SAAgB,qBAAqB,CAAC,CAAW;IAC/C,IAAI;QACF,OAAO,CAAC,EAAE,CAAC;KACZ;IAAC,OAAO,CAAC,EAAE;QACV,IAAI,OAAO,CAAC,KAAK,EAAE;YACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAClB;KACF;AACH,CAAC;AARD,sDAQC;AAED,SAAgB,qBAAqB,CAAC,MAAuB;IAC3D,OAAO,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;AAC/C,CAAC;AAFD,sDAEC"}

View File

@@ -0,0 +1,2 @@
export declare function filterInPlace<T>(array: T[], test: (elem: T) => boolean, context?: any): T[];
//# sourceMappingURL=filterInPlace.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"filterInPlace.d.ts","sourceRoot":"","sources":["../src/util/filterInPlace.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EAAE,EACV,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,EAC1B,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,EAAE,CASL"}

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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;
}
exports.filterInPlace = filterInPlace;
//# sourceMappingURL=filterInPlace.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"filterInPlace.js","sourceRoot":"","sources":["../../src/util/filterInPlace.ts"],"names":[],"mappings":";;AAAA,SAAgB,aAAa,CAC3B,KAAU,EACV,IAA0B,EAC1B,OAAa;IAEb,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;QAC7B,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE;YACnC,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;SACxB;IACH,CAAC,EAAE,OAAO,CAAC,CAAC;IACZ,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,OAAO,KAAK,CAAC;AACf,CAAC;AAbD,sCAaC"}

2
node_modules/apollo-utilities/lib/util/isEqual.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export { equal as isEqual } from '@wry/equality';
//# sourceMappingURL=isEqual.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"isEqual.d.ts","sourceRoot":"","sources":["../src/util/isEqual.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,eAAe,CAAC"}

5
node_modules/apollo-utilities/lib/util/isEqual.js generated vendored Normal file
View File

@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var equality_1 = require("@wry/equality");
exports.isEqual = equality_1.equal;
//# sourceMappingURL=isEqual.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"isEqual.js","sourceRoot":"","sources":["../../src/util/isEqual.ts"],"names":[],"mappings":";;AAAA,0CAAiD;AAAxC,6BAAA,KAAK,CAAW"}

View File

@@ -0,0 +1,2 @@
export declare function maybeDeepFreeze(obj: any): any;
//# sourceMappingURL=maybeDeepFreeze.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"maybeDeepFreeze.d.ts","sourceRoot":"","sources":["../src/util/maybeDeepFreeze.ts"],"names":[],"mappings":"AAoBA,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,OAYvC"}

View File

@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var environment_1 = require("./environment");
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 (environment_1.isDevelopment() || environment_1.isTest()) {
var symbolIsPolyfilled = typeof Symbol === 'function' && typeof Symbol('') === 'string';
if (!symbolIsPolyfilled) {
return deepFreeze(obj);
}
}
return obj;
}
exports.maybeDeepFreeze = maybeDeepFreeze;
//# sourceMappingURL=maybeDeepFreeze.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"maybeDeepFreeze.js","sourceRoot":"","sources":["../../src/util/maybeDeepFreeze.ts"],"names":[],"mappings":";;AAAA,6CAAsD;AAItD,SAAS,UAAU,CAAC,CAAM;IACxB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAEjB,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAS,IAAI;QACjD,IACE,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI;YAChB,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC;YAC9D,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EACzB;YACA,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;SACrB;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAgB,eAAe,CAAC,GAAQ;IACtC,IAAI,2BAAa,EAAE,IAAI,oBAAM,EAAE,EAAE;QAG/B,IAAM,kBAAkB,GACtB,OAAO,MAAM,KAAK,UAAU,IAAI,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,QAAQ,CAAC;QAEjE,IAAI,CAAC,kBAAkB,EAAE;YACvB,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;SACxB;KACF;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAZD,0CAYC"}

View File

@@ -0,0 +1,4 @@
export declare type TupleToIntersection<T extends any[]> = 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;
export declare function mergeDeep<T extends any[]>(...sources: T): TupleToIntersection<T>;
export declare function mergeDeepArray<T>(sources: T[]): T;
//# sourceMappingURL=mergeDeep.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mergeDeep.d.ts","sourceRoot":"","sources":["../src/util/mergeDeep.ts"],"names":[],"mappings":"AAgBA,oBAAY,mBAAmB,CAAC,CAAC,SAAS,GAAG,EAAE,IAC7C,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GACvB,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GACpC,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GACjD,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAC9D,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAC3E,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC;AAElC,wBAAgB,SAAS,CAAC,CAAC,SAAS,GAAG,EAAE,EACvC,GAAG,OAAO,EAAE,CAAC,GACZ,mBAAmB,CAAC,CAAC,CAAC,CAExB;AAQD,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,CAWjD"}

64
node_modules/apollo-utilities/lib/util/mergeDeep.js generated vendored Normal file
View File

@@ -0,0 +1,64 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var hasOwnProperty = Object.prototype.hasOwnProperty;
function mergeDeep() {
var sources = [];
for (var _i = 0; _i < arguments.length; _i++) {
sources[_i] = arguments[_i];
}
return mergeDeepArray(sources);
}
exports.mergeDeep = mergeDeep;
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;
}
exports.mergeDeepArray = mergeDeepArray;
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 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_1.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
}
pastCopies.push(value);
}
return value;
}
//# sourceMappingURL=mergeDeep.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mergeDeep.js","sourceRoot":"","sources":["../../src/util/mergeDeep.ts"],"names":[],"mappings":";;;AAAQ,IAAA,gDAAc,CAAsB;AAwB5C,SAAgB,SAAS;IACvB,iBAAa;SAAb,UAAa,EAAb,qBAAa,EAAb,IAAa;QAAb,4BAAa;;IAEb,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAJD,8BAIC;AAQD,SAAgB,cAAc,CAAI,OAAY;IAC5C,IAAI,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,EAAO,CAAC;IACnC,IAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAC7B,IAAI,KAAK,GAAG,CAAC,EAAE;QACb,IAAM,UAAU,GAAU,EAAE,CAAC;QAC7B,MAAM,GAAG,mBAAmB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,EAAE,CAAC,EAAE;YAC9B,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;SACtD;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAXD,wCAWC;AAED,SAAS,QAAQ,CAAC,GAAQ;IACxB,OAAO,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAC;AACjD,CAAC;AAED,SAAS,WAAW,CAClB,MAAW,EACX,MAAW,EACX,UAAiB;IAEjB,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE;QAGxC,IAAI,MAAM,CAAC,YAAY,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;YACvD,MAAM,GAAG,mBAAmB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;SAClD;QAED,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAA,SAAS;YACnC,IAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;YACtC,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE;gBAC1C,IAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;gBACtC,IAAI,WAAW,KAAK,WAAW,EAAE;oBAQ/B,MAAM,CAAC,SAAS,CAAC,GAAG,WAAW,CAC7B,mBAAmB,CAAC,WAAW,EAAE,UAAU,CAAC,EAC5C,WAAW,EACX,UAAU,CACX,CAAC;iBACH;aACF;iBAAM;gBAGL,MAAM,CAAC,SAAS,CAAC,GAAG,WAAW,CAAC;aACjC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;KACf;IAGD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,mBAAmB,CAAI,KAAQ,EAAE,UAAiB;IACzD,IACE,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAC7B;QACA,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,KAAK,GAAI,KAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACjC;aAAM;YACL,KAAK,sBACH,SAAS,EAAE,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,IACpC,KAAK,CACT,CAAC;SACH;QACD,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACxB;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}

View File

@@ -0,0 +1,2 @@
export declare function stripSymbols<T>(data: T): T;
//# sourceMappingURL=stripSymbols.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"stripSymbols.d.ts","sourceRoot":"","sources":["../src/util/stripSymbols.ts"],"names":[],"mappings":"AAWA,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAE1C"}

View File

@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function stripSymbols(data) {
return JSON.parse(JSON.stringify(data));
}
exports.stripSymbols = stripSymbols;
//# sourceMappingURL=stripSymbols.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"stripSymbols.js","sourceRoot":"","sources":["../../src/util/stripSymbols.ts"],"names":[],"mappings":";;AAWA,SAAgB,YAAY,CAAI,IAAO;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1C,CAAC;AAFD,oCAEC"}

2
node_modules/apollo-utilities/lib/util/warnOnce.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export declare function warnOnceInDevelopment(msg: string, type?: string): void;
//# sourceMappingURL=warnOnce.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"warnOnce.d.ts","sourceRoot":"","sources":["../src/util/warnOnce.ts"],"names":[],"mappings":"AAYA,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,SAAS,QAW/D"}

20
node_modules/apollo-utilities/lib/util/warnOnce.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var environment_1 = require("./environment");
var haveWarned = Object.create({});
function warnOnceInDevelopment(msg, type) {
if (type === void 0) { type = 'warn'; }
if (!environment_1.isProduction() && !haveWarned[msg]) {
if (!environment_1.isTest()) {
haveWarned[msg] = true;
}
if (type === 'error') {
console.error(msg);
}
else {
console.warn(msg);
}
}
}
exports.warnOnceInDevelopment = warnOnceInDevelopment;
//# sourceMappingURL=warnOnce.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"warnOnce.js","sourceRoot":"","sources":["../../src/util/warnOnce.ts"],"names":[],"mappings":";;AAAA,6CAAqD;AAErD,IAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAUrC,SAAgB,qBAAqB,CAAC,GAAW,EAAE,IAAa;IAAb,qBAAA,EAAA,aAAa;IAC9D,IAAI,CAAC,0BAAY,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACvC,IAAI,CAAC,oBAAM,EAAE,EAAE;YACb,UAAU,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;SACxB;QACD,IAAI,IAAI,KAAK,OAAO,EAAE;YACpB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACpB;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACnB;KACF;AACH,CAAC;AAXD,sDAWC"}

48
node_modules/apollo-utilities/package.json generated vendored Normal file
View File

@@ -0,0 +1,48 @@
{
"name": "apollo-utilities",
"version": "1.3.4",
"description": "Utilities for working with GraphQL ASTs",
"author": "James Baxley <james@meteor.com>",
"contributors": [
"James Baxley <james@meteor.com>",
"Jonas Helfer <jonas@helfer.email>",
"Sashko Stubailo <sashko@stubailo.com>",
"James Burgess <jamesmillerburgess@gmail.com>"
],
"license": "MIT",
"main": "./lib/bundle.cjs.js",
"module": "./lib/bundle.esm.js",
"typings": "./lib/index.d.ts",
"sideEffects": false,
"repository": {
"type": "git",
"url": "git+https://github.com/apollographql/apollo-client.git"
},
"bugs": {
"url": "https://github.com/apollographql/apollo-client/issues"
},
"homepage": "https://github.com/apollographql/apollo-client#readme",
"scripts": {
"prepare": "npm run lint && npm run build",
"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 -b .",
"postbuild": "npm run bundle",
"bundle": "npx rollup -c rollup.config.js",
"watch": "../../node_modules/tsc-watch/index.js --onSuccess \"npm run postbuild\"",
"clean": "rm -rf coverage/* lib/*",
"prepublishOnly": "npm run clean && npm run build"
},
"peerDependencies": {
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
},
"dependencies": {
"@wry/equality": "^0.1.2",
"fast-json-stable-stringify": "^2.0.0",
"ts-invariant": "^0.4.0",
"tslib": "^1.10.0"
},
"gitHead": "d22394c419ff7d678afb5e7d4cd1df16ed803ead"
}

View File

@@ -0,0 +1,274 @@
import gql from 'graphql-tag';
import { cloneDeep } from 'lodash';
import { shouldInclude, hasDirectives } from '../directives';
import { getQueryDefinition } from '../getFromAST';
describe('hasDirective', () => {
it('should allow searching the ast for a directive', () => {
const query = gql`
query Simple {
field @live
}
`;
expect(hasDirectives(['live'], query)).toBe(true);
expect(hasDirectives(['defer'], query)).toBe(false);
});
it('works for all operation types', () => {
const query = gql`
{
field @live {
subField {
hello @live
}
}
}
`;
const mutation = gql`
mutation Directive {
mutate {
field {
subField {
hello @live
}
}
}
}
`;
const subscription = gql`
subscription LiveDirective {
sub {
field {
subField {
hello @live
}
}
}
}
`;
[query, mutation, subscription].forEach(x => {
expect(hasDirectives(['live'], x)).toBe(true);
expect(hasDirectives(['defer'], x)).toBe(false);
});
});
it('works for simple fragments', () => {
const query = gql`
query Simple {
...fieldFragment
}
fragment fieldFragment on Field {
foo @live
}
`;
expect(hasDirectives(['live'], query)).toBe(true);
expect(hasDirectives(['defer'], query)).toBe(false);
});
it('works for nested fragments', () => {
const query = gql`
query Simple {
...fieldFragment1
}
fragment fieldFragment1 on Field {
bar {
baz {
...nestedFragment
}
}
}
fragment nestedFragment on Field {
foo @live
}
`;
expect(hasDirectives(['live'], query)).toBe(true);
expect(hasDirectives(['defer'], query)).toBe(false);
});
});
describe('shouldInclude', () => {
it('should should not include a skipped field', () => {
const query = gql`
query {
fortuneCookie @skip(if: true)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(!shouldInclude(field, {})).toBe(true);
});
it('should include an included field', () => {
const query = gql`
query {
fortuneCookie @include(if: true)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(shouldInclude(field, {})).toBe(true);
});
it('should not include a not include: false field', () => {
const query = gql`
query {
fortuneCookie @include(if: false)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(!shouldInclude(field, {})).toBe(true);
});
it('should include a skip: false field', () => {
const query = gql`
query {
fortuneCookie @skip(if: false)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(shouldInclude(field, {})).toBe(true);
});
it('should not include a field if skip: true and include: true', () => {
const query = gql`
query {
fortuneCookie @skip(if: true) @include(if: true)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(!shouldInclude(field, {})).toBe(true);
});
it('should not include a field if skip: true and include: false', () => {
const query = gql`
query {
fortuneCookie @skip(if: true) @include(if: false)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(!shouldInclude(field, {})).toBe(true);
});
it('should include a field if skip: false and include: true', () => {
const query = gql`
query {
fortuneCookie @skip(if: false) @include(if: true)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(shouldInclude(field, {})).toBe(true);
});
it('should not include a field if skip: false and include: false', () => {
const query = gql`
query {
fortuneCookie @skip(if: false) @include(if: false)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(!shouldInclude(field, {})).toBe(true);
});
it('should leave the original query unmodified', () => {
const query = gql`
query {
fortuneCookie @skip(if: false) @include(if: false)
}
`;
const queryClone = cloneDeep(query);
const field = getQueryDefinition(query).selectionSet.selections[0];
shouldInclude(field, {});
expect(query).toEqual(queryClone);
});
it('does not throw an error on an unsupported directive', () => {
const query = gql`
query {
fortuneCookie @dosomething(if: true)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(() => {
shouldInclude(field, {});
}).not.toThrow();
});
it('throws an error on an invalid argument for the skip directive', () => {
const query = gql`
query {
fortuneCookie @skip(nothing: true)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(() => {
shouldInclude(field, {});
}).toThrow();
});
it('throws an error on an invalid argument for the include directive', () => {
const query = gql`
query {
fortuneCookie @include(nothing: true)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(() => {
shouldInclude(field, {});
}).toThrow();
});
it('throws an error on an invalid variable name within a directive argument', () => {
const query = gql`
query {
fortuneCookie @include(if: $neverDefined)
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(() => {
shouldInclude(field, {});
}).toThrow();
});
it('evaluates variables on skip fields', () => {
const query = gql`
query($shouldSkip: Boolean) {
fortuneCookie @skip(if: $shouldSkip)
}
`;
const variables = {
shouldSkip: true,
};
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(!shouldInclude(field, variables)).toBe(true);
});
it('evaluates variables on include fields', () => {
const query = gql`
query($shouldSkip: Boolean) {
fortuneCookie @include(if: $shouldInclude)
}
`;
const variables = {
shouldInclude: false,
};
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(!shouldInclude(field, variables)).toBe(true);
});
it('throws an error if the value of the argument is not a variable or boolean', () => {
const query = gql`
query {
fortuneCookie @include(if: "string")
}
`;
const field = getQueryDefinition(query).selectionSet.selections[0];
expect(() => {
shouldInclude(field, {});
}).toThrow();
});
});

View File

@@ -0,0 +1,327 @@
import { print } from 'graphql/language/printer';
import gql from 'graphql-tag';
import { disableFragmentWarnings } from 'graphql-tag';
// Turn off warnings for repeated fragment names
disableFragmentWarnings();
import { getFragmentQueryDocument } from '../fragments';
describe('getFragmentQueryDocument', () => {
it('will throw an error if there is an operation', () => {
expect(() =>
getFragmentQueryDocument(
gql`
{
a
b
c
}
`,
),
).toThrowError(
'Found a query operation. No operations are allowed when using a fragment as a query. Only fragments are allowed.',
);
expect(() =>
getFragmentQueryDocument(
gql`
query {
a
b
c
}
`,
),
).toThrowError(
'Found a query operation. No operations are allowed when using a fragment as a query. Only fragments are allowed.',
);
expect(() =>
getFragmentQueryDocument(
gql`
query Named {
a
b
c
}
`,
),
).toThrowError(
"Found a query operation named 'Named'. No operations are allowed when using a fragment as a query. Only fragments are allowed.",
);
expect(() =>
getFragmentQueryDocument(
gql`
mutation Named {
a
b
c
}
`,
),
).toThrowError(
"Found a mutation operation named 'Named'. No operations are allowed when using a fragment as a query. " +
'Only fragments are allowed.',
);
expect(() =>
getFragmentQueryDocument(
gql`
subscription Named {
a
b
c
}
`,
),
).toThrowError(
"Found a subscription operation named 'Named'. No operations are allowed when using a fragment as a query. " +
'Only fragments are allowed.',
);
});
it('will throw an error if there is not exactly one fragment but no `fragmentName`', () => {
expect(() => {
getFragmentQueryDocument(gql`
fragment foo on Foo {
a
b
c
}
fragment bar on Bar {
d
e
f
}
`);
}).toThrowError(
'Found 2 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.',
);
expect(() => {
getFragmentQueryDocument(gql`
fragment foo on Foo {
a
b
c
}
fragment bar on Bar {
d
e
f
}
fragment baz on Baz {
g
h
i
}
`);
}).toThrowError(
'Found 3 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.',
);
expect(() => {
getFragmentQueryDocument(gql`
scalar Foo
`);
}).toThrowError(
'Found 0 fragments. `fragmentName` must be provided when there is not exactly 1 fragment.',
);
});
it('will create a query document where the single fragment is spread in the root query', () => {
expect(
print(
getFragmentQueryDocument(gql`
fragment foo on Foo {
a
b
c
}
`),
),
).toEqual(
print(gql`
{
...foo
}
fragment foo on Foo {
a
b
c
}
`),
);
});
it('will create a query document where the named fragment is spread in the root query', () => {
expect(
print(
getFragmentQueryDocument(
gql`
fragment foo on Foo {
a
b
c
}
fragment bar on Bar {
d
e
f
...foo
}
fragment baz on Baz {
g
h
i
...foo
...bar
}
`,
'foo',
),
),
).toEqual(
print(gql`
{
...foo
}
fragment foo on Foo {
a
b
c
}
fragment bar on Bar {
d
e
f
...foo
}
fragment baz on Baz {
g
h
i
...foo
...bar
}
`),
);
expect(
print(
getFragmentQueryDocument(
gql`
fragment foo on Foo {
a
b
c
}
fragment bar on Bar {
d
e
f
...foo
}
fragment baz on Baz {
g
h
i
...foo
...bar
}
`,
'bar',
),
),
).toEqual(
print(gql`
{
...bar
}
fragment foo on Foo {
a
b
c
}
fragment bar on Bar {
d
e
f
...foo
}
fragment baz on Baz {
g
h
i
...foo
...bar
}
`),
);
expect(
print(
getFragmentQueryDocument(
gql`
fragment foo on Foo {
a
b
c
}
fragment bar on Bar {
d
e
f
...foo
}
fragment baz on Baz {
g
h
i
...foo
...bar
}
`,
'baz',
),
),
).toEqual(
print(gql`
{
...baz
}
fragment foo on Foo {
a
b
c
}
fragment bar on Bar {
d
e
f
...foo
}
fragment baz on Baz {
g
h
i
...foo
...bar
}
`),
);
});
});

View File

@@ -0,0 +1,316 @@
import { print } from 'graphql/language/printer';
import gql from 'graphql-tag';
import { FragmentDefinitionNode, OperationDefinitionNode } from 'graphql';
import {
checkDocument,
getFragmentDefinitions,
getQueryDefinition,
getMutationDefinition,
createFragmentMap,
FragmentMap,
getDefaultValues,
getOperationName,
} from '../getFromAST';
describe('AST utility functions', () => {
it('should correctly check a document for correctness', () => {
const multipleQueries = gql`
query {
author {
firstName
lastName
}
}
query {
author {
address
}
}
`;
expect(() => {
checkDocument(multipleQueries);
}).toThrow();
const namedFragment = gql`
query {
author {
...authorDetails
}
}
fragment authorDetails on Author {
firstName
lastName
}
`;
expect(() => {
checkDocument(namedFragment);
}).not.toThrow();
});
it('should get fragment definitions from a document containing a single fragment', () => {
const singleFragmentDefinition = gql`
query {
author {
...authorDetails
}
}
fragment authorDetails on Author {
firstName
lastName
}
`;
const expectedDoc = gql`
fragment authorDetails on Author {
firstName
lastName
}
`;
const expectedResult: FragmentDefinitionNode[] = [
expectedDoc.definitions[0] as FragmentDefinitionNode,
];
const actualResult = getFragmentDefinitions(singleFragmentDefinition);
expect(actualResult.length).toEqual(expectedResult.length);
expect(print(actualResult[0])).toBe(print(expectedResult[0]));
});
it('should get fragment definitions from a document containing a multiple fragments', () => {
const multipleFragmentDefinitions = gql`
query {
author {
...authorDetails
...moreAuthorDetails
}
}
fragment authorDetails on Author {
firstName
lastName
}
fragment moreAuthorDetails on Author {
address
}
`;
const expectedDoc = gql`
fragment authorDetails on Author {
firstName
lastName
}
fragment moreAuthorDetails on Author {
address
}
`;
const expectedResult: FragmentDefinitionNode[] = [
expectedDoc.definitions[0] as FragmentDefinitionNode,
expectedDoc.definitions[1] as FragmentDefinitionNode,
];
const actualResult = getFragmentDefinitions(multipleFragmentDefinitions);
expect(actualResult.map(print)).toEqual(expectedResult.map(print));
});
it('should get the correct query definition out of a query containing multiple fragments', () => {
const queryWithFragments = gql`
fragment authorDetails on Author {
firstName
lastName
}
fragment moreAuthorDetails on Author {
address
}
query {
author {
...authorDetails
...moreAuthorDetails
}
}
`;
const expectedDoc = gql`
query {
author {
...authorDetails
...moreAuthorDetails
}
}
`;
const expectedResult: OperationDefinitionNode = expectedDoc
.definitions[0] as OperationDefinitionNode;
const actualResult = getQueryDefinition(queryWithFragments);
expect(print(actualResult)).toEqual(print(expectedResult));
});
it('should throw if we try to get the query definition of a document with no query', () => {
const mutationWithFragments = gql`
fragment authorDetails on Author {
firstName
lastName
}
mutation {
createAuthor(firstName: "John", lastName: "Smith") {
...authorDetails
}
}
`;
expect(() => {
getQueryDefinition(mutationWithFragments);
}).toThrow();
});
it('should get the correct mutation definition out of a mutation with multiple fragments', () => {
const mutationWithFragments = gql`
mutation {
createAuthor(firstName: "John", lastName: "Smith") {
...authorDetails
}
}
fragment authorDetails on Author {
firstName
lastName
}
`;
const expectedDoc = gql`
mutation {
createAuthor(firstName: "John", lastName: "Smith") {
...authorDetails
}
}
`;
const expectedResult: OperationDefinitionNode = expectedDoc
.definitions[0] as OperationDefinitionNode;
const actualResult = getMutationDefinition(mutationWithFragments);
expect(print(actualResult)).toEqual(print(expectedResult));
});
it('should create the fragment map correctly', () => {
const fragments = getFragmentDefinitions(gql`
fragment authorDetails on Author {
firstName
lastName
}
fragment moreAuthorDetails on Author {
address
}
`);
const fragmentMap = createFragmentMap(fragments);
const expectedTable: FragmentMap = {
authorDetails: fragments[0],
moreAuthorDetails: fragments[1],
};
expect(fragmentMap).toEqual(expectedTable);
});
it('should return an empty fragment map if passed undefined argument', () => {
expect(createFragmentMap(undefined)).toEqual({});
});
it('should get the operation name out of a query', () => {
const query = gql`
query nameOfQuery {
fortuneCookie
}
`;
const operationName = getOperationName(query);
expect(operationName).toEqual('nameOfQuery');
});
it('should get the operation name out of a mutation', () => {
const query = gql`
mutation nameOfMutation {
fortuneCookie
}
`;
const operationName = getOperationName(query);
expect(operationName).toEqual('nameOfMutation');
});
it('should return null if the query does not have an operation name', () => {
const query = gql`
{
fortuneCookie
}
`;
const operationName = getOperationName(query);
expect(operationName).toEqual(null);
});
it('should throw if type definitions found in document', () => {
const queryWithTypeDefination = gql`
fragment authorDetails on Author {
firstName
lastName
}
query($search: AuthorSearchInputType) {
author(search: $search) {
...authorDetails
}
}
input AuthorSearchInputType {
firstName: String
}
`;
expect(() => {
getQueryDefinition(queryWithTypeDefination);
}).toThrowError(
'Schema type definitions not allowed in queries. Found: "InputObjectTypeDefinition"',
);
});
describe('getDefaultValues', () => {
it('will create an empty variable object if no default values are provided', () => {
const basicQuery = gql`
query people($first: Int, $second: String) {
allPeople(first: $first) {
people {
name
}
}
}
`;
expect(getDefaultValues(getQueryDefinition(basicQuery))).toEqual({});
});
it('will create a variable object based on the definition node with default values', () => {
const basicQuery = gql`
query people($first: Int = 1, $second: String!) {
allPeople(first: $first) {
people {
name
}
}
}
`;
const complexMutation = gql`
mutation complexStuff(
$test: Input = { key1: ["value", "value2"], key2: { key3: 4 } }
) {
complexStuff(test: $test) {
people {
name
}
}
}
`;
expect(getDefaultValues(getQueryDefinition(basicQuery))).toEqual({
first: 1,
});
expect(getDefaultValues(getMutationDefinition(complexMutation))).toEqual({
test: { key1: ['value', 'value2'], key2: { key3: 4 } },
});
});
});
});

View File

@@ -0,0 +1,23 @@
import { getStoreKeyName } from '../storeUtils';
describe('getStoreKeyName', () => {
it(
'should return a deterministic version of the store key name no matter ' +
'which order the args object properties are in',
() => {
const validStoreKeyName =
'someField({"prop1":"value1","prop2":"value2"})';
let generatedStoreKeyName = getStoreKeyName('someField', {
prop1: 'value1',
prop2: 'value2',
});
expect(generatedStoreKeyName).toEqual(validStoreKeyName);
generatedStoreKeyName = getStoreKeyName('someField', {
prop2: 'value2',
prop1: 'value1',
});
expect(generatedStoreKeyName).toEqual(validStoreKeyName);
},
);
});

1242
node_modules/apollo-utilities/src/__tests__/transform.ts generated vendored Normal file

File diff suppressed because it is too large Load Diff

1
node_modules/apollo-utilities/src/declarations.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
declare module 'fast-json-stable-stringify';

127
node_modules/apollo-utilities/src/directives.ts generated vendored Normal file
View File

@@ -0,0 +1,127 @@
// Provides the methods that allow QueryManager to handle the `skip` and
// `include` directives within GraphQL.
import {
FieldNode,
SelectionNode,
VariableNode,
BooleanValueNode,
DirectiveNode,
DocumentNode,
ArgumentNode,
ValueNode,
} from 'graphql';
import { visit } from 'graphql/language/visitor';
import { invariant } from 'ts-invariant';
import { argumentsObjectFromField } from './storeUtils';
export type DirectiveInfo = {
[fieldName: string]: { [argName: string]: any };
};
export function getDirectiveInfoFromField(
field: FieldNode,
variables: Object,
): DirectiveInfo {
if (field.directives && field.directives.length) {
const directiveObj: DirectiveInfo = {};
field.directives.forEach((directive: DirectiveNode) => {
directiveObj[directive.name.value] = argumentsObjectFromField(
directive,
variables,
);
});
return directiveObj;
}
return null;
}
export function shouldInclude(
selection: SelectionNode,
variables: { [name: string]: any } = {},
): boolean {
return getInclusionDirectives(
selection.directives,
).every(({ directive, ifArgument }) => {
let evaledValue: boolean = false;
if (ifArgument.value.kind === 'Variable') {
evaledValue = variables[(ifArgument.value as VariableNode).name.value];
invariant(
evaledValue !== void 0,
`Invalid variable referenced in @${directive.name.value} directive.`,
);
} else {
evaledValue = (ifArgument.value as BooleanValueNode).value;
}
return directive.name.value === 'skip' ? !evaledValue : evaledValue;
});
}
export function getDirectiveNames(doc: DocumentNode) {
const names: string[] = [];
visit(doc, {
Directive(node) {
names.push(node.name.value);
},
});
return names;
}
export function hasDirectives(names: string[], doc: DocumentNode) {
return getDirectiveNames(doc).some(
(name: string) => names.indexOf(name) > -1,
);
}
export function hasClientExports(document: DocumentNode) {
return (
document &&
hasDirectives(['client'], document) &&
hasDirectives(['export'], document)
);
}
export type InclusionDirectives = Array<{
directive: DirectiveNode;
ifArgument: ArgumentNode;
}>;
function isInclusionDirective({ name: { value } }: DirectiveNode): boolean {
return value === 'skip' || value === 'include';
}
export function getInclusionDirectives(
directives: ReadonlyArray<DirectiveNode>,
): InclusionDirectives {
return directives ? directives.filter(isInclusionDirective).map(directive => {
const directiveArguments = directive.arguments;
const directiveName = directive.name.value;
invariant(
directiveArguments && directiveArguments.length === 1,
`Incorrect number of arguments for the @${directiveName} directive.`,
);
const ifArgument = directiveArguments[0];
invariant(
ifArgument.name && ifArgument.name.value === 'if',
`Invalid argument for the @${directiveName} directive.`,
);
const ifValue: ValueNode = ifArgument.value;
// means it has to be a variable value if this is a valid @skip or @include directive
invariant(
ifValue &&
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'),
`Argument for the @${directiveName} directive must be a variable or a boolean value.`,
);
return { directive, ifArgument };
}) : [];
}

92
node_modules/apollo-utilities/src/fragments.ts generated vendored Normal file
View File

@@ -0,0 +1,92 @@
import { DocumentNode, FragmentDefinitionNode } from 'graphql';
import { invariant, InvariantError } from 'ts-invariant';
/**
* Returns a query document which adds a single query operation that only
* spreads the target fragment inside of it.
*
* So for example a document of:
*
* ```graphql
* fragment foo on Foo { a b c }
* ```
*
* Turns into:
*
* ```graphql
* { ...foo }
*
* fragment foo on Foo { a b c }
* ```
*
* The target fragment will either be the only fragment in the document, or a
* fragment specified by the provided `fragmentName`. If there is more than one
* fragment, but a `fragmentName` was not defined then an error will be thrown.
*/
export function getFragmentQueryDocument(
document: DocumentNode,
fragmentName?: string,
): DocumentNode {
let actualFragmentName = fragmentName;
// Build an array of all our fragment definitions that will be used for
// validations. We also do some validations on the other definitions in the
// document while building this list.
const fragments: Array<FragmentDefinitionNode> = [];
document.definitions.forEach(definition => {
// Throw an error if we encounter an operation definition because we will
// define our own operation definition later on.
if (definition.kind === 'OperationDefinition') {
throw new 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.',
);
}
// Add our definition to the fragments array if it is a fragment
// definition.
if (definition.kind === 'FragmentDefinition') {
fragments.push(definition);
}
});
// If the user did not give us a fragment name then let us try to get a
// name from a single fragment in the definition.
if (typeof actualFragmentName === 'undefined') {
invariant(
fragments.length === 1,
`Found ${
fragments.length
} fragments. \`fragmentName\` must be provided when there is not exactly 1 fragment.`,
);
actualFragmentName = fragments[0].name.value;
}
// Generate a query document with an operation that simply spreads the
// fragment inside of it.
const query: DocumentNode = {
...document,
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'FragmentSpread',
name: {
kind: 'Name',
value: actualFragmentName,
},
},
],
},
},
...document.definitions,
],
};
return query;
}

233
node_modules/apollo-utilities/src/getFromAST.ts generated vendored Normal file
View File

@@ -0,0 +1,233 @@
import {
DocumentNode,
OperationDefinitionNode,
FragmentDefinitionNode,
ValueNode,
} from 'graphql';
import { invariant, InvariantError } from 'ts-invariant';
import { assign } from './util/assign';
import { valueToObjectRepresentation, JsonValue } from './storeUtils';
export function getMutationDefinition(
doc: DocumentNode,
): OperationDefinitionNode {
checkDocument(doc);
let mutationDef: OperationDefinitionNode | null = doc.definitions.filter(
definition =>
definition.kind === 'OperationDefinition' &&
definition.operation === 'mutation',
)[0] as OperationDefinitionNode;
invariant(mutationDef, 'Must contain a mutation definition.');
return mutationDef;
}
// Checks the document for errors and throws an exception if there is an error.
export function checkDocument(doc: DocumentNode) {
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`,
);
const operations = doc.definitions
.filter(d => d.kind !== 'FragmentDefinition')
.map(definition => {
if (definition.kind !== 'OperationDefinition') {
throw new InvariantError(
`Schema type definitions not allowed in queries. Found: "${
definition.kind
}"`,
);
}
return definition;
});
invariant(
operations.length <= 1,
`Ambiguous GraphQL document: contains ${operations.length} operations`,
);
return doc;
}
export function getOperationDefinition(
doc: DocumentNode,
): OperationDefinitionNode | undefined {
checkDocument(doc);
return doc.definitions.filter(
definition => definition.kind === 'OperationDefinition',
)[0] as OperationDefinitionNode;
}
export function getOperationDefinitionOrDie(
document: DocumentNode,
): OperationDefinitionNode {
const def = getOperationDefinition(document);
invariant(def, `GraphQL document is missing an operation`);
return def;
}
export function getOperationName(doc: DocumentNode): string | null {
return (
doc.definitions
.filter(
definition =>
definition.kind === 'OperationDefinition' && definition.name,
)
.map((x: OperationDefinitionNode) => x.name.value)[0] || null
);
}
// Returns the FragmentDefinitions from a particular document as an array
export function getFragmentDefinitions(
doc: DocumentNode,
): FragmentDefinitionNode[] {
return doc.definitions.filter(
definition => definition.kind === 'FragmentDefinition',
) as FragmentDefinitionNode[];
}
export function getQueryDefinition(doc: DocumentNode): OperationDefinitionNode {
const queryDef = getOperationDefinition(doc) as OperationDefinitionNode;
invariant(
queryDef && queryDef.operation === 'query',
'Must contain a query definition.',
);
return queryDef;
}
export function getFragmentDefinition(
doc: DocumentNode,
): FragmentDefinitionNode {
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`,
);
invariant(
doc.definitions.length <= 1,
'Fragment must have exactly one definition.',
);
const fragmentDef = doc.definitions[0] as FragmentDefinitionNode;
invariant(
fragmentDef.kind === 'FragmentDefinition',
'Must be a fragment definition.',
);
return fragmentDef as FragmentDefinitionNode;
}
/**
* Returns the first operation definition found in this document.
* If no operation definition is found, the first fragment definition will be returned.
* If no definitions are found, an error will be thrown.
*/
export function getMainDefinition(
queryDoc: DocumentNode,
): OperationDefinitionNode | FragmentDefinitionNode {
checkDocument(queryDoc);
let fragmentDefinition;
for (let definition of queryDoc.definitions) {
if (definition.kind === 'OperationDefinition') {
const operation = (definition as OperationDefinitionNode).operation;
if (
operation === 'query' ||
operation === 'mutation' ||
operation === 'subscription'
) {
return definition as OperationDefinitionNode;
}
}
if (definition.kind === 'FragmentDefinition' && !fragmentDefinition) {
// we do this because we want to allow multiple fragment definitions
// to precede an operation definition.
fragmentDefinition = definition as FragmentDefinitionNode;
}
}
if (fragmentDefinition) {
return fragmentDefinition;
}
throw new InvariantError(
'Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.',
);
}
/**
* This is an interface that describes a map from fragment names to fragment definitions.
*/
export interface FragmentMap {
[fragmentName: string]: FragmentDefinitionNode;
}
// Utility function that takes a list of fragment definitions and makes a hash out of them
// that maps the name of the fragment to the fragment definition.
export function createFragmentMap(
fragments: FragmentDefinitionNode[] = [],
): FragmentMap {
const symTable: FragmentMap = {};
fragments.forEach(fragment => {
symTable[fragment.name.value] = fragment;
});
return symTable;
}
export function getDefaultValues(
definition: OperationDefinitionNode | undefined,
): { [key: string]: JsonValue } {
if (
definition &&
definition.variableDefinitions &&
definition.variableDefinitions.length
) {
const defaultValues = definition.variableDefinitions
.filter(({ defaultValue }) => defaultValue)
.map(
({ variable, defaultValue }): { [key: string]: JsonValue } => {
const defaultValueObj: { [key: string]: JsonValue } = {};
valueToObjectRepresentation(
defaultValueObj,
variable.name,
defaultValue as ValueNode,
);
return defaultValueObj;
},
);
return assign({}, ...defaultValues);
}
return {};
}
/**
* Returns the names of all variables declared by the operation.
*/
export function variablesInOperation(
operation: OperationDefinitionNode,
): Set<string> {
const names = new Set<string>();
if (operation.variableDefinitions) {
for (const definition of operation.variableDefinitions) {
names.add(definition.variable.name.value);
}
}
return names;
}

220
node_modules/apollo-utilities/src/index.js.flow generated vendored Normal file
View File

@@ -0,0 +1,220 @@
// @flow
import type {
DirectiveNode,
StringValueNode,
BooleanValueNode,
IntValueNode,
FloatValueNode,
EnumValueNode,
VariableNode,
FieldNode,
FragmentDefinitionNode,
OperationDefinitionNode,
SelectionNode,
DocumentNode,
DefinitionNode,
ValueNode,
NameNode,
} from 'graphql';
declare module 'apollo-utilities' {
// storeUtils
declare export interface IdValue {
type: 'id';
id: string;
generated: boolean;
typename: string | void;
}
declare export interface JsonValue {
type: 'json';
json: any;
}
declare export type ListValue = Array<?IdValue>;
declare export type StoreValue =
| number
| string
| Array<string>
| IdValue
| ListValue
| JsonValue
| null
| void
| Object;
declare export type ScalarValue =
| StringValueNode
| BooleanValueNode
| EnumValueNode;
declare export type NumberValue = IntValueNode | FloatValueNode;
declare type isValueFn = (value: ValueNode) => boolean;
declare export type isScalarValue = isValueFn;
declare export type isNumberValue = isValueFn;
declare export type isStringValue = isValueFn;
declare export type isBooleanValue = isValueFn;
declare export type isIntValue = isValueFn;
declare export type isFloatValue = isValueFn;
declare export type isVariable = isValueFn;
declare export type isObjectValue = isValueFn;
declare export type isListValue = isValueFn;
declare export type isEnumValue = isValueFn;
declare export function valueToObjectRepresentation(
argObj: any,
name: NameNode,
value: ValueNode,
variables?: Object,
): any;
declare export function storeKeyNameFromField(
field: FieldNode,
variables?: Object,
): string;
declare export type Directives = {
[directiveName: string]: {
[argName: string]: any,
},
};
declare export function getStoreKeyName(
fieldName: string,
args?: Object,
directives?: Directives,
): string;
declare export function argumentsObjectFromField(
field: FieldNode | DirectiveNode,
variables: Object,
): ?Object;
declare export function resultKeyNameFromField(field: FieldNode): string;
declare export function isField(selection: SelectionNode): boolean;
declare export function isInlineFragment(selection: SelectionNode): boolean;
declare export function isIdValue(idObject: StoreValue): boolean;
declare export type IdConfig = {
id: string,
typename: string | void,
};
declare export function toIdValue(
id: string | IdConfig,
generated?: boolean,
): IdValue;
declare export function isJsonValue(jsonObject: StoreValue): boolean;
declare export type VariableValue = (node: VariableNode) => any;
declare export function valueFromNode(
node: ValueNode,
onVariable: VariableValue,
): any;
// getFromAST
declare export function getMutationDefinition(
doc: DocumentNode,
): OperationDefinitionNode;
declare export function checkDocument(doc: DocumentNode): void;
declare export function getOperationDefinition(
doc: DocumentNode,
): ?OperationDefinitionNode;
declare export function getOperationDefinitionOrDie(
document: DocumentNode,
): OperationDefinitionNode;
declare export function getOperationName(doc: DocumentNode): ?string;
declare export function getFragmentDefinitions(
doc: DocumentNode,
): Array<FragmentDefinitionNode>;
declare export function getQueryDefinition(
doc: DocumentNode,
): OperationDefinitionNode;
declare export function getFragmentDefinition(
doc: DocumentNode,
): FragmentDefinitionNode;
declare export function getMainDefinition(
queryDoc: DocumentNode,
): OperationDefinitionNode | FragmentDefinitionNode;
declare export interface FragmentMap {
[fragmentName: string]: FragmentDefinitionNode;
}
declare export function createFragmentMap(
fragments: Array<FragmentDefinitionNode>,
): FragmentMap;
declare export function getDefaultValues(
definition: ?OperationDefinitionNode,
): { [key: string]: JsonValue };
// fragments
declare export function getFragmentQueryDocument(
document: DocumentNode,
fragmentName?: string,
): DocumentNode;
declare export function variablesInOperation(
operation: OperationDefinitionNode,
): Set<string>;
// directives
declare type DirectiveInfo = {
[fieldName: string]: { [argName: string]: any },
};
declare export function getDirectiveInfoFromField(
field: FieldNode,
object: Object,
): ?DirectiveInfo;
declare export function shouldInclude(
selection: SelectionNode,
variables: { [name: string]: any },
): boolean;
declare export function flattenSelections(
selection: SelectionNode,
): Array<SelectionNode>;
declare export function getDirectiveNames(doc: DocumentNode): Array<string>;
declare export function hasDirectives(
names: Array<string>,
doc: DocumentNode,
): boolean;
// transform
declare export type RemoveDirectiveConfig = {
name?: string,
test?: (directive: DirectiveNode) => boolean,
};
declare export function removeDirectivesFromDocument(
directives: Array<RemoveDirectiveConfig>,
doc: DocumentNode,
): DocumentNode;
declare export function addTypenameToDocument(doc: DocumentNode): void;
declare export function removeConnectionDirectiveFromDocument(
doc: DocumentNode,
): DocumentNode;
}

16
node_modules/apollo-utilities/src/index.ts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
export * from './directives';
export * from './fragments';
export * from './getFromAST';
export * from './transform';
export * from './storeUtils';
export * from './util/assign';
export * from './util/canUse';
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';

340
node_modules/apollo-utilities/src/storeUtils.ts generated vendored Normal file
View File

@@ -0,0 +1,340 @@
import {
DirectiveNode,
FieldNode,
IntValueNode,
FloatValueNode,
StringValueNode,
BooleanValueNode,
ObjectValueNode,
ListValueNode,
EnumValueNode,
NullValueNode,
VariableNode,
InlineFragmentNode,
ValueNode,
SelectionNode,
NameNode,
} from 'graphql';
import stringify from 'fast-json-stable-stringify';
import { InvariantError } from 'ts-invariant';
export interface IdValue {
type: 'id';
id: string;
generated: boolean;
typename: string | undefined;
}
export interface JsonValue {
type: 'json';
json: any;
}
export type ListValue = Array<null | IdValue>;
export type StoreValue =
| number
| string
| string[]
| IdValue
| ListValue
| JsonValue
| null
| undefined
| void
| Object;
export type ScalarValue = StringValueNode | BooleanValueNode | EnumValueNode;
export function isScalarValue(value: ValueNode): value is ScalarValue {
return ['StringValue', 'BooleanValue', 'EnumValue'].indexOf(value.kind) > -1;
}
export type NumberValue = IntValueNode | FloatValueNode;
export function isNumberValue(value: ValueNode): value is NumberValue {
return ['IntValue', 'FloatValue'].indexOf(value.kind) > -1;
}
function isStringValue(value: ValueNode): value is StringValueNode {
return value.kind === 'StringValue';
}
function isBooleanValue(value: ValueNode): value is BooleanValueNode {
return value.kind === 'BooleanValue';
}
function isIntValue(value: ValueNode): value is IntValueNode {
return value.kind === 'IntValue';
}
function isFloatValue(value: ValueNode): value is FloatValueNode {
return value.kind === 'FloatValue';
}
function isVariable(value: ValueNode): value is VariableNode {
return value.kind === 'Variable';
}
function isObjectValue(value: ValueNode): value is ObjectValueNode {
return value.kind === 'ObjectValue';
}
function isListValue(value: ValueNode): value is ListValueNode {
return value.kind === 'ListValue';
}
function isEnumValue(value: ValueNode): value is EnumValueNode {
return value.kind === 'EnumValue';
}
function isNullValue(value: ValueNode): value is NullValueNode {
return value.kind === 'NullValue';
}
export function valueToObjectRepresentation(
argObj: any,
name: NameNode,
value: ValueNode,
variables?: Object,
) {
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)) {
const nestedArgObj = {};
value.fields.map(obj =>
valueToObjectRepresentation(nestedArgObj, obj.name, obj.value, variables),
);
argObj[name.value] = nestedArgObj;
} else if (isVariable(value)) {
const variableValue = (variables || ({} as any))[value.name.value];
argObj[name.value] = variableValue;
} else if (isListValue(value)) {
argObj[name.value] = value.values.map(listValue => {
const nestedArgArrayObj = {};
valueToObjectRepresentation(
nestedArgArrayObj,
name,
listValue,
variables,
);
return (nestedArgArrayObj as any)[name.value];
});
} else if (isEnumValue(value)) {
argObj[name.value] = (value as EnumValueNode).value;
} else if (isNullValue(value)) {
argObj[name.value] = null;
} else {
throw new InvariantError(
`The inline argument "${name.value}" of kind "${(value as any).kind}"` +
'is not supported. Use variables instead of inline arguments to ' +
'overcome this limitation.',
);
}
}
export function storeKeyNameFromField(
field: FieldNode,
variables?: Object,
): string {
let directivesObj: any = null;
if (field.directives) {
directivesObj = {};
field.directives.forEach(directive => {
directivesObj[directive.name.value] = {};
if (directive.arguments) {
directive.arguments.forEach(({ name, value }) =>
valueToObjectRepresentation(
directivesObj[directive.name.value],
name,
value,
variables,
),
);
}
});
}
let argObj: any = null;
if (field.arguments && field.arguments.length) {
argObj = {};
field.arguments.forEach(({ name, value }) =>
valueToObjectRepresentation(argObj, name, value, variables),
);
}
return getStoreKeyName(field.name.value, argObj, directivesObj);
}
export type Directives = {
[directiveName: string]: {
[argName: string]: any;
};
};
const KNOWN_DIRECTIVES: string[] = [
'connection',
'include',
'skip',
'client',
'rest',
'export',
];
export function getStoreKeyName(
fieldName: string,
args?: Object,
directives?: Directives,
): string {
if (
directives &&
directives['connection'] &&
directives['connection']['key']
) {
if (
directives['connection']['filter'] &&
(directives['connection']['filter'] as string[]).length > 0
) {
const filterKeys = directives['connection']['filter']
? (directives['connection']['filter'] as string[])
: [];
filterKeys.sort();
const queryArgs = args as { [key: string]: any };
const filteredArgs = {} as { [key: string]: any };
filterKeys.forEach(key => {
filteredArgs[key] = queryArgs[key];
});
return `${directives['connection']['key']}(${JSON.stringify(
filteredArgs,
)})`;
} else {
return directives['connection']['key'];
}
}
let completeFieldName: string = fieldName;
if (args) {
// We can't use `JSON.stringify` here since it's non-deterministic,
// and can lead to different store key names being created even though
// the `args` object used during creation has the same properties/values.
const stringifiedArgs: string = stringify(args);
completeFieldName += `(${stringifiedArgs})`;
}
if (directives) {
Object.keys(directives).forEach(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;
}
export function argumentsObjectFromField(
field: FieldNode | DirectiveNode,
variables: Object,
): Object {
if (field.arguments && field.arguments.length) {
const argObj: Object = {};
field.arguments.forEach(({ name, value }) =>
valueToObjectRepresentation(argObj, name, value, variables),
);
return argObj;
}
return null;
}
export function resultKeyNameFromField(field: FieldNode): string {
return field.alias ? field.alias.value : field.name.value;
}
export function isField(selection: SelectionNode): selection is FieldNode {
return selection.kind === 'Field';
}
export function isInlineFragment(
selection: SelectionNode,
): selection is InlineFragmentNode {
return selection.kind === 'InlineFragment';
}
export function isIdValue(idObject: StoreValue): idObject is IdValue {
return idObject &&
(idObject as IdValue | JsonValue).type === 'id' &&
typeof (idObject as IdValue).generated === 'boolean';
}
export type IdConfig = {
id: string;
typename: string | undefined;
};
export function toIdValue(
idConfig: string | IdConfig,
generated = false,
): IdValue {
return {
type: 'id',
generated,
...(typeof idConfig === 'string'
? { id: idConfig, typename: undefined }
: idConfig),
};
}
export function isJsonValue(jsonObject: StoreValue): jsonObject is JsonValue {
return (
jsonObject != null &&
typeof jsonObject === 'object' &&
(jsonObject as IdValue | JsonValue).type === 'json'
);
}
function defaultValueFromVariable(node: VariableNode) {
throw new InvariantError(`Variable nodes are not supported by valueFromNode`);
}
export type VariableValue = (node: VariableNode) => any;
/**
* Evaluate a ValueNode and yield its value in its natural JS form.
*/
export function valueFromNode(
node: ValueNode,
onVariable: VariableValue = defaultValueFromVariable,
): any {
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(v => valueFromNode(v, onVariable));
case 'ObjectValue': {
const value: { [key: string]: any } = {};
for (const field of node.fields) {
value[field.name.value] = valueFromNode(field.value, onVariable);
}
return value;
}
default:
return node.value;
}
}

542
node_modules/apollo-utilities/src/transform.ts generated vendored Normal file
View File

@@ -0,0 +1,542 @@
import {
DocumentNode,
SelectionNode,
SelectionSetNode,
OperationDefinitionNode,
FieldNode,
DirectiveNode,
FragmentDefinitionNode,
ArgumentNode,
FragmentSpreadNode,
VariableDefinitionNode,
VariableNode,
} from 'graphql';
import { visit } from 'graphql/language/visitor';
import {
checkDocument,
getOperationDefinition,
getFragmentDefinition,
getFragmentDefinitions,
createFragmentMap,
FragmentMap,
getMainDefinition,
} from './getFromAST';
import { filterInPlace } from './util/filterInPlace';
import { invariant } from 'ts-invariant';
import { isField, isInlineFragment } from './storeUtils';
export type RemoveNodeConfig<N> = {
name?: string;
test?: (node: N) => boolean;
remove?: boolean;
};
export type GetNodeConfig<N> = {
name?: string;
test?: (node: N) => boolean;
};
export type RemoveDirectiveConfig = RemoveNodeConfig<DirectiveNode>;
export type GetDirectiveConfig = GetNodeConfig<DirectiveNode>;
export type RemoveArgumentsConfig = RemoveNodeConfig<ArgumentNode>;
export type GetFragmentSpreadConfig = GetNodeConfig<FragmentSpreadNode>;
export type RemoveFragmentSpreadConfig = RemoveNodeConfig<FragmentSpreadNode>;
export type RemoveFragmentDefinitionConfig = RemoveNodeConfig<
FragmentDefinitionNode
>;
export type RemoveVariableDefinitionConfig = RemoveNodeConfig<
VariableDefinitionNode
>;
const TYPENAME_FIELD: FieldNode = {
kind: 'Field',
name: {
kind: 'Name',
value: '__typename',
},
};
function isEmpty(
op: OperationDefinitionNode | FragmentDefinitionNode,
fragments: FragmentMap,
): boolean {
return op.selectionSet.selections.every(
selection =>
selection.kind === 'FragmentSpread' &&
isEmpty(fragments[selection.name.value], fragments),
);
}
function nullIfDocIsEmpty(doc: DocumentNode) {
return isEmpty(
getOperationDefinition(doc) || getFragmentDefinition(doc),
createFragmentMap(getFragmentDefinitions(doc)),
)
? null
: doc;
}
function getDirectiveMatcher(
directives: (RemoveDirectiveConfig | GetDirectiveConfig)[],
) {
return function directiveMatcher(directive: DirectiveNode) {
return directives.some(
dir =>
(dir.name && dir.name === directive.name.value) ||
(dir.test && dir.test(directive)),
);
};
}
export function removeDirectivesFromDocument(
directives: RemoveDirectiveConfig[],
doc: DocumentNode,
): DocumentNode | null {
const variablesInUse: Record<string, boolean> = Object.create(null);
let variablesToRemove: RemoveArgumentsConfig[] = [];
const fragmentSpreadsInUse: Record<string, boolean> = Object.create(null);
let fragmentSpreadsToRemove: RemoveFragmentSpreadConfig[] = [];
let modifiedDoc = nullIfDocIsEmpty(
visit(doc, {
Variable: {
enter(node, _key, parent) {
// Store each variable that's referenced as part of an argument
// (excluding operation definition variables), so we know which
// variables are being used. If we later want to remove a variable
// we'll fist check to see if it's being used, before continuing with
// the removal.
if (
(parent as VariableDefinitionNode).kind !== 'VariableDefinition'
) {
variablesInUse[node.name.value] = true;
}
},
},
Field: {
enter(node) {
if (directives && node.directives) {
// If `remove` is set to true for a directive, and a directive match
// is found for a field, remove the field as well.
const shouldRemoveField = directives.some(
directive => directive.remove,
);
if (
shouldRemoveField &&
node.directives &&
node.directives.some(getDirectiveMatcher(directives))
) {
if (node.arguments) {
// Store field argument variables so they can be removed
// from the operation definition.
node.arguments.forEach(arg => {
if (arg.value.kind === 'Variable') {
variablesToRemove.push({
name: (arg.value as VariableNode).name.value,
});
}
});
}
if (node.selectionSet) {
// Store fragment spread names so they can be removed from the
// docuemnt.
getAllFragmentSpreadsFromSelectionSet(node.selectionSet).forEach(
frag => {
fragmentSpreadsToRemove.push({
name: frag.name.value,
});
},
);
}
// Remove the field.
return null;
}
}
},
},
FragmentSpread: {
enter(node) {
// Keep track of referenced fragment spreads. This is used to
// determine if top level fragment definitions should be removed.
fragmentSpreadsInUse[node.name.value] = true;
},
},
Directive: {
enter(node) {
// If a matching directive is found, remove it.
if (getDirectiveMatcher(directives)(node)) {
return null;
}
},
},
}),
);
// If we've removed fields with arguments, make sure the associated
// variables are also removed from the rest of the document, as long as they
// aren't being used elsewhere.
if (
modifiedDoc &&
filterInPlace(variablesToRemove, v => !variablesInUse[v.name]).length
) {
modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);
}
// If we've removed selection sets with fragment spreads, make sure the
// associated fragment definitions are also removed from the rest of the
// document, as long as they aren't being used elsewhere.
if (
modifiedDoc &&
filterInPlace(fragmentSpreadsToRemove, fs => !fragmentSpreadsInUse[fs.name])
.length
) {
modifiedDoc = removeFragmentSpreadFromDocument(
fragmentSpreadsToRemove,
modifiedDoc,
);
}
return modifiedDoc;
}
export function addTypenameToDocument(doc: DocumentNode): DocumentNode {
return visit(checkDocument(doc), {
SelectionSet: {
enter(node, _key, parent) {
// Don't add __typename to OperationDefinitions.
if (
parent &&
(parent as OperationDefinitionNode).kind === 'OperationDefinition'
) {
return;
}
// No changes if no selections.
const { selections } = node;
if (!selections) {
return;
}
// If selections already have a __typename, or are part of an
// introspection query, do nothing.
const skip = selections.some(selection => {
return (
isField(selection) &&
(selection.name.value === '__typename' ||
selection.name.value.lastIndexOf('__', 0) === 0)
);
});
if (skip) {
return;
}
// If this SelectionSet is @export-ed as an input variable, it should
// not have a __typename field (see issue #4691).
const field = parent as FieldNode;
if (
isField(field) &&
field.directives &&
field.directives.some(d => d.name.value === 'export')
) {
return;
}
// Create and return a new SelectionSet with a __typename Field.
return {
...node,
selections: [...selections, TYPENAME_FIELD],
};
},
},
});
}
const connectionRemoveConfig = {
test: (directive: DirectiveNode) => {
const willRemove = directive.name.value === 'connection';
if (willRemove) {
if (
!directive.arguments ||
!directive.arguments.some(arg => arg.name.value === 'key')
) {
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;
},
};
export function removeConnectionDirectiveFromDocument(doc: DocumentNode) {
return removeDirectivesFromDocument(
[connectionRemoveConfig],
checkDocument(doc),
);
}
function hasDirectivesInSelectionSet(
directives: GetDirectiveConfig[],
selectionSet: SelectionSetNode,
nestedCheck = true,
): boolean {
return (
selectionSet &&
selectionSet.selections &&
selectionSet.selections.some(selection =>
hasDirectivesInSelection(directives, selection, nestedCheck),
)
);
}
function hasDirectivesInSelection(
directives: GetDirectiveConfig[],
selection: SelectionNode,
nestedCheck = true,
): boolean {
if (!isField(selection)) {
return true;
}
if (!selection.directives) {
return false;
}
return (
selection.directives.some(getDirectiveMatcher(directives)) ||
(nestedCheck &&
hasDirectivesInSelectionSet(
directives,
selection.selectionSet,
nestedCheck,
))
);
}
export function getDirectivesFromDocument(
directives: GetDirectiveConfig[],
doc: DocumentNode,
): DocumentNode {
checkDocument(doc);
let parentPath: string;
return nullIfDocIsEmpty(
visit(doc, {
SelectionSet: {
enter(node, _key, _parent, path) {
const currentPath = path.join('-');
if (
!parentPath ||
currentPath === parentPath ||
!currentPath.startsWith(parentPath)
) {
if (node.selections) {
const selectionsWithDirectives = node.selections.filter(
selection => hasDirectivesInSelection(directives, selection),
);
if (hasDirectivesInSelectionSet(directives, node, false)) {
parentPath = currentPath;
}
return {
...node,
selections: selectionsWithDirectives,
};
} else {
return null;
}
}
},
},
}),
);
}
function getArgumentMatcher(config: RemoveArgumentsConfig[]) {
return function argumentMatcher(argument: ArgumentNode) {
return config.some(
(aConfig: RemoveArgumentsConfig) =>
argument.value &&
argument.value.kind === 'Variable' &&
argument.value.name &&
(aConfig.name === argument.value.name.value ||
(aConfig.test && aConfig.test(argument))),
);
};
}
export function removeArgumentsFromDocument(
config: RemoveArgumentsConfig[],
doc: DocumentNode,
): DocumentNode {
const argMatcher = getArgumentMatcher(config);
return nullIfDocIsEmpty(
visit(doc, {
OperationDefinition: {
enter(node) {
return {
...node,
// Remove matching top level variables definitions.
variableDefinitions: node.variableDefinitions.filter(
varDef =>
!config.some(arg => arg.name === varDef.variable.name.value),
),
};
},
},
Field: {
enter(node) {
// If `remove` is set to true for an argument, and an argument match
// is found for a field, remove the field as well.
const shouldRemoveField = config.some(argConfig => argConfig.remove);
if (shouldRemoveField) {
let argMatchCount = 0;
node.arguments.forEach(arg => {
if (argMatcher(arg)) {
argMatchCount += 1;
}
});
if (argMatchCount === 1) {
return null;
}
}
},
},
Argument: {
enter(node) {
// Remove all matching arguments.
if (argMatcher(node)) {
return null;
}
},
},
}),
);
}
export function removeFragmentSpreadFromDocument(
config: RemoveFragmentSpreadConfig[],
doc: DocumentNode,
): DocumentNode {
function enter(
node: FragmentSpreadNode | FragmentDefinitionNode,
): null | void {
if (config.some(def => def.name === node.name.value)) {
return null;
}
}
return nullIfDocIsEmpty(
visit(doc, {
FragmentSpread: { enter },
FragmentDefinition: { enter },
}),
);
}
function getAllFragmentSpreadsFromSelectionSet(
selectionSet: SelectionSetNode,
): FragmentSpreadNode[] {
const allFragments: FragmentSpreadNode[] = [];
selectionSet.selections.forEach(selection => {
if (
(isField(selection) || isInlineFragment(selection)) &&
selection.selectionSet
) {
getAllFragmentSpreadsFromSelectionSet(selection.selectionSet).forEach(
frag => allFragments.push(frag),
);
} else if (selection.kind === 'FragmentSpread') {
allFragments.push(selection);
}
});
return allFragments;
}
// If the incoming document is a query, return it as is. Otherwise, build a
// new document containing a query operation based on the selection set
// of the previous main operation.
export function buildQueryFromSelectionSet(
document: DocumentNode,
): DocumentNode {
const definition = getMainDefinition(document);
const definitionOperation = (<OperationDefinitionNode>definition).operation;
if (definitionOperation === 'query') {
// Already a query, so return the existing document.
return document;
}
// Build a new query using the selection set of the main operation.
const modifiedDoc = visit(document, {
OperationDefinition: {
enter(node) {
return {
...node,
operation: 'query',
};
},
},
});
return modifiedDoc;
}
// Remove fields / selection sets that include an @client directive.
export function removeClientSetsFromDocument(
document: DocumentNode,
): DocumentNode | null {
checkDocument(document);
let modifiedDoc = removeDirectivesFromDocument(
[
{
test: (directive: DirectiveNode) => directive.name.value === 'client',
remove: true,
},
],
document,
);
// After a fragment definition has had its @client related document
// sets removed, if the only field it has left is a __typename field,
// remove the entire fragment operation to prevent it from being fired
// on the server.
if (modifiedDoc) {
modifiedDoc = visit(modifiedDoc, {
FragmentDefinition: {
enter(node) {
if (node.selectionSet) {
const isTypenameOnly = node.selectionSet.selections.every(
selection =>
isField(selection) && selection.name.value === '__typename',
);
if (isTypenameOnly) {
return null;
}
}
},
},
});
}
return modifiedDoc;
}

View File

@@ -0,0 +1,47 @@
import { assign } from '../assign';
describe('assign', () => {
it('will merge many objects together', () => {
expect(assign({ a: 1 }, { b: 2 })).toEqual({ a: 1, b: 2 });
expect(assign({ a: 1 }, { b: 2 }, { c: 3 })).toEqual({
a: 1,
b: 2,
c: 3,
});
expect(assign({ a: 1 }, { b: 2 }, { c: 3 }, { d: 4 })).toEqual({
a: 1,
b: 2,
c: 3,
d: 4,
});
});
it('will merge many objects together shallowly', () => {
expect(assign({ x: { a: 1 } }, { x: { b: 2 } })).toEqual({ x: { b: 2 } });
expect(assign({ x: { a: 1 } }, { x: { b: 2 } }, { x: { c: 3 } })).toEqual({
x: { c: 3 },
});
expect(
assign(
{ x: { a: 1 } },
{ x: { b: 2 } },
{ x: { c: 3 } },
{ x: { d: 4 } },
),
).toEqual({ x: { d: 4 } });
});
it('will mutate and return the source objects', () => {
const source1 = { a: 1 };
const source2 = { a: 1 };
const source3 = { a: 1 };
expect(assign(source1, { b: 2 })).toEqual(source1);
expect(assign(source2, { b: 2 }, { c: 3 })).toEqual(source2);
expect(assign(source3, { b: 2 }, { c: 3 }, { d: 4 })).toEqual(source3);
expect(source1).toEqual({ a: 1, b: 2 });
expect(source2).toEqual({ a: 1, b: 2, c: 3 });
expect(source3).toEqual({ a: 1, b: 2, c: 3, d: 4 });
});
});

View File

@@ -0,0 +1,70 @@
import { cloneDeep } from '../cloneDeep';
describe('cloneDeep', () => {
it('will clone primitive values', () => {
expect(cloneDeep(undefined)).toEqual(undefined);
expect(cloneDeep(null)).toEqual(null);
expect(cloneDeep(true)).toEqual(true);
expect(cloneDeep(false)).toEqual(false);
expect(cloneDeep(-1)).toEqual(-1);
expect(cloneDeep(+1)).toEqual(+1);
expect(cloneDeep(0.5)).toEqual(0.5);
expect(cloneDeep('hello')).toEqual('hello');
expect(cloneDeep('world')).toEqual('world');
});
it('will clone objects', () => {
const value1 = {};
const value2 = { a: 1, b: 2, c: 3 };
const value3 = { x: { a: 1, b: 2, c: 3 }, y: { a: 1, b: 2, c: 3 } };
const clonedValue1 = cloneDeep(value1);
const clonedValue2 = cloneDeep(value2);
const clonedValue3 = cloneDeep(value3);
expect(clonedValue1).toEqual(value1);
expect(clonedValue2).toEqual(value2);
expect(clonedValue3).toEqual(value3);
expect(clonedValue1).toEqual(value1);
expect(clonedValue2).toEqual(value2);
expect(clonedValue3).toEqual(value3);
expect(clonedValue3.x).toEqual(value3.x);
expect(clonedValue3.y).toEqual(value3.y);
});
it('will clone arrays', () => {
const value1: Array<number> = [];
const value2 = [1, 2, 3];
const value3 = [[1, 2, 3], [1, 2, 3]];
const clonedValue1 = cloneDeep(value1);
const clonedValue2 = cloneDeep(value2);
const clonedValue3 = cloneDeep(value3);
expect(clonedValue1).toEqual(value1);
expect(clonedValue2).toEqual(value2);
expect(clonedValue3).toEqual(value3);
expect(clonedValue1).toEqual(value1);
expect(clonedValue2).toEqual(value2);
expect(clonedValue3).toEqual(value3);
expect(clonedValue3[0]).toEqual(value3[0]);
expect(clonedValue3[1]).toEqual(value3[1]);
});
it('should not attempt to follow circular references', () => {
const someObject = {
prop1: 'value1',
anotherObject: null,
};
const anotherObject = {
someObject,
};
someObject.anotherObject = anotherObject;
let chk;
expect(() => {
chk = cloneDeep(someObject);
}).not.toThrow();
});
});

View File

@@ -0,0 +1,70 @@
import { isEnv, isProduction, isDevelopment, isTest } from '../environment';
describe('environment', () => {
let keepEnv: string | undefined;
beforeEach(() => {
// save the NODE_ENV
keepEnv = process.env.NODE_ENV;
});
afterEach(() => {
// restore the NODE_ENV
process.env.NODE_ENV = keepEnv;
});
describe('isEnv', () => {
it(`should match when there's a value`, () => {
['production', 'development', 'test'].forEach(env => {
process.env.NODE_ENV = env;
expect(isEnv(env)).toBe(true);
});
});
it(`should treat no proces.env.NODE_ENV as it'd be in development`, () => {
delete process.env.NODE_ENV;
expect(isEnv('development')).toBe(true);
});
});
describe('isProduction', () => {
it('should return true if in production', () => {
process.env.NODE_ENV = 'production';
expect(isProduction()).toBe(true);
});
it('should return false if not in production', () => {
process.env.NODE_ENV = 'test';
expect(!isProduction()).toBe(true);
});
});
describe('isTest', () => {
it('should return true if in test', () => {
process.env.NODE_ENV = 'test';
expect(isTest()).toBe(true);
});
it('should return true if not in test', () => {
process.env.NODE_ENV = 'development';
expect(!isTest()).toBe(true);
});
});
describe('isDevelopment', () => {
it('should return true if in development', () => {
process.env.NODE_ENV = 'development';
expect(isDevelopment()).toBe(true);
});
it('should return true if not in development and environment is defined', () => {
process.env.NODE_ENV = 'test';
expect(!isDevelopment()).toBe(true);
});
it('should make development as the default environment', () => {
delete process.env.NODE_ENV;
expect(isDevelopment()).toBe(true);
});
});
});

View File

@@ -0,0 +1,174 @@
import { isEqual } from '../isEqual';
describe('isEqual', () => {
it('should return true for equal primitive values', () => {
expect(isEqual(undefined, undefined)).toBe(true);
expect(isEqual(null, null)).toBe(true);
expect(isEqual(true, true)).toBe(true);
expect(isEqual(false, false)).toBe(true);
expect(isEqual(-1, -1)).toBe(true);
expect(isEqual(+1, +1)).toBe(true);
expect(isEqual(42, 42)).toBe(true);
expect(isEqual(0, 0)).toBe(true);
expect(isEqual(0.5, 0.5)).toBe(true);
expect(isEqual('hello', 'hello')).toBe(true);
expect(isEqual('world', 'world')).toBe(true);
});
it('should return false for not equal primitive values', () => {
expect(!isEqual(undefined, null)).toBe(true);
expect(!isEqual(null, undefined)).toBe(true);
expect(!isEqual(true, false)).toBe(true);
expect(!isEqual(false, true)).toBe(true);
expect(!isEqual(-1, +1)).toBe(true);
expect(!isEqual(+1, -1)).toBe(true);
expect(!isEqual(42, 42.00000000000001)).toBe(true);
expect(!isEqual(0, 0.5)).toBe(true);
expect(!isEqual('hello', 'world')).toBe(true);
expect(!isEqual('world', 'hello')).toBe(true);
});
it('should return false when comparing primitives with objects', () => {
expect(!isEqual({}, null)).toBe(true);
expect(!isEqual(null, {})).toBe(true);
expect(!isEqual({}, true)).toBe(true);
expect(!isEqual(true, {})).toBe(true);
expect(!isEqual({}, 42)).toBe(true);
expect(!isEqual(42, {})).toBe(true);
expect(!isEqual({}, 'hello')).toBe(true);
expect(!isEqual('hello', {})).toBe(true);
});
it('should correctly compare shallow objects', () => {
expect(isEqual({}, {})).toBe(true);
expect(isEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe(true);
expect(!isEqual({ a: 1, b: 2, c: 3 }, { a: 3, b: 2, c: 1 })).toBe(true);
expect(!isEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 })).toBe(true);
expect(!isEqual({ a: 1, b: 2 }, { a: 1, b: 2, c: 3 })).toBe(true);
});
it('should correctly compare deep objects', () => {
expect(isEqual({ x: {} }, { x: {} })).toBe(true);
expect(
isEqual({ x: { a: 1, b: 2, c: 3 } }, { x: { a: 1, b: 2, c: 3 } }),
).toBe(true);
expect(
!isEqual({ x: { a: 1, b: 2, c: 3 } }, { x: { a: 3, b: 2, c: 1 } }),
).toBe(true);
expect(!isEqual({ x: { a: 1, b: 2, c: 3 } }, { x: { a: 1, b: 2 } })).toBe(
true,
);
expect(!isEqual({ x: { a: 1, b: 2 } }, { x: { a: 1, b: 2, c: 3 } })).toBe(
true,
);
});
it('should correctly compare deep objects without object prototype ', () => {
// Solves https://github.com/apollographql/apollo-client/issues/2132
const objNoProto = Object.create(null);
objNoProto.a = { b: 2, c: [3, 4] };
objNoProto.e = Object.create(null);
objNoProto.e.f = 5;
expect(isEqual(objNoProto, { a: { b: 2, c: [3, 4] }, e: { f: 5 } })).toBe(
true,
);
expect(!isEqual(objNoProto, { a: { b: 2, c: [3, 4] }, e: { f: 6 } })).toBe(
true,
);
expect(!isEqual(objNoProto, { a: { b: 2, c: [3, 4] }, e: null })).toBe(
true,
);
expect(!isEqual(objNoProto, { a: { b: 2, c: [3] }, e: { f: 5 } })).toBe(
true,
);
expect(!isEqual(objNoProto, null)).toBe(true);
});
it('should correctly handle modified prototypes', () => {
Array.prototype.foo = null;
expect(isEqual([1, 2, 3], [1, 2, 3])).toBe(true);
expect(!isEqual([1, 2, 3], [1, 2, 4])).toBe(true);
delete Array.prototype.foo;
});
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);
});
});
});

View File

@@ -0,0 +1,17 @@
import { maybeDeepFreeze } from '../maybeDeepFreeze';
describe('maybeDeepFreeze', () => {
it('should deep freeze', () => {
const foo: any = { bar: undefined };
maybeDeepFreeze(foo);
expect(() => (foo.bar = 1)).toThrow();
expect(foo.bar).toBeUndefined();
});
it('should properly freeze objects without hasOwnProperty', () => {
const foo = Object.create(null);
foo.bar = undefined;
maybeDeepFreeze(foo);
expect(() => (foo.bar = 1)).toThrow();
});
});

View File

@@ -0,0 +1,139 @@
import { mergeDeep, mergeDeepArray } from '../mergeDeep';
describe('mergeDeep', function() {
it('should return an object if first argument falsy', function() {
expect(mergeDeep()).toEqual({});
expect(mergeDeep(null)).toEqual({});
expect(mergeDeep(null, { foo: 42 })).toEqual({ foo: 42 });
});
it('should preserve identity for single arguments', function() {
const arg = Object.create(null);
expect(mergeDeep(arg)).toBe(arg);
});
it('should preserve identity when merging non-conflicting objects', function() {
const a = { a: { name: 'ay' } };
const b = { b: { name: 'bee' } };
const c = mergeDeep(a, b);
expect(c.a).toBe(a.a);
expect(c.b).toBe(b.b);
expect(c).toEqual({
a: { name: 'ay' },
b: { name: 'bee' },
});
});
it('should shallow-copy conflicting fields', function() {
const a = { conflict: { fromA: [1, 2, 3] } };
const b = { conflict: { fromB: [4, 5] } };
const c = mergeDeep(a, b);
expect(c.conflict).not.toBe(a.conflict);
expect(c.conflict).not.toBe(b.conflict);
expect(c.conflict.fromA).toBe(a.conflict.fromA);
expect(c.conflict.fromB).toBe(b.conflict.fromB);
expect(c).toEqual({
conflict: {
fromA: [1, 2, 3],
fromB: [4, 5],
},
});
});
it('should resolve conflicts among more than two objects', function() {
const sources = [];
for (let i = 0; i < 100; ++i) {
sources.push({
['unique' + i]: { value: i },
conflict: {
['from' + i]: { value: i },
nested: {
['nested' + i]: { value: i },
},
},
});
}
const merged = mergeDeep(...sources);
sources.forEach((source, i) => {
expect(merged['unique' + i].value).toBe(i);
expect(source['unique' + i]).toBe(merged['unique' + i]);
expect(merged.conflict).not.toBe(source.conflict);
expect(merged.conflict['from' + i].value).toBe(i);
expect(merged.conflict['from' + i]).toBe(source.conflict['from' + i]);
expect(merged.conflict.nested).not.toBe(source.conflict.nested);
expect(merged.conflict.nested['nested' + i].value).toBe(i);
expect(merged.conflict.nested['nested' + i]).toBe(
source.conflict.nested['nested' + i],
);
});
});
it('can merge array elements', function() {
const a = [{ a: 1 }, { a: 'ay' }, 'a'];
const b = [{ b: 2 }, { b: 'bee' }, 'b'];
const c = [{ c: 3 }, { c: 'cee' }, 'c'];
const d = { 1: { d: 'dee' } };
expect(mergeDeep(a, b, c, d)).toEqual([
{ a: 1, b: 2, c: 3 },
{ a: 'ay', b: 'bee', c: 'cee', d: 'dee' },
'c',
]);
});
it('lets the last conflicting value win', function() {
expect(mergeDeep('a', 'b', 'c')).toBe('c');
expect(
mergeDeep(
{ a: 'a', conflict: 1 },
{ b: 'b', conflict: 2 },
{ c: 'c', conflict: 3 },
),
).toEqual({
a: 'a',
b: 'b',
c: 'c',
conflict: 3,
});
expect(mergeDeep(
['a', ['b', 'c'], 'd'],
[/*empty*/, ['B'], 'D'],
)).toEqual(
['a', ['B', 'c'], 'D'],
);
expect(mergeDeep(
['a', ['b', 'c'], 'd'],
['A', [/*empty*/, 'C']],
)).toEqual(
['A', ['b', 'C'], 'd'],
);
});
it('mergeDeep returns the intersection of its argument types', function() {
const abc = mergeDeep({ str: "hi", a: 1 }, { a: 3, b: 2 }, { b: 1, c: 2 });
// The point of this test is that the following lines type-check without
// resorting to any `any` loopholes:
expect(abc.str.slice(0)).toBe("hi");
expect(abc.a * 2).toBe(6);
expect(abc.b - 0).toBe(1);
expect(abc.c / 2).toBe(1);
});
it('mergeDeepArray returns the supertype of its argument types', function() {
class F {
check() { return "ok" };
}
const fs: F[] = [new F, new F, new F];
// Although mergeDeepArray doesn't have the same tuple type awareness as
// mergeDeep, it does infer that F should be the return type here:
expect(mergeDeepArray(fs).check()).toBe("ok");
});
});

View File

@@ -0,0 +1,15 @@
import { stripSymbols } from '../stripSymbols';
interface SymbolConstructor {
(description?: string | number): symbol;
}
declare const Symbol: SymbolConstructor;
describe('stripSymbols', () => {
it('should strip symbols (only)', () => {
const sym = Symbol('id');
const data = { foo: 'bar', [sym]: 'ROOT_QUERY' };
expect(stripSymbols(data)).toEqual({ foo: 'bar' });
});
});

Some files were not shown because too many files have changed in this diff Show More