Initial Sample.
This commit is contained in:
50
graphql-subscription/node_modules/@apollo/client/utilities/graphql/DocumentTransform.d.ts
generated
vendored
Normal file
50
graphql-subscription/node_modules/@apollo/client/utilities/graphql/DocumentTransform.d.ts
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import type { DocumentNode } from "graphql";
|
||||
export type DocumentTransformCacheKey = ReadonlyArray<unknown>;
|
||||
type TransformFn = (document: DocumentNode) => DocumentNode;
|
||||
interface DocumentTransformOptions {
|
||||
/**
|
||||
* Determines whether to cache the transformed GraphQL document. Caching can speed up repeated calls to the document transform for the same input document. Set to `false` to completely disable caching for the document transform. When disabled, this option takes precedence over the [`getCacheKey`](#getcachekey) option.
|
||||
*
|
||||
* The default value is `true`.
|
||||
*/
|
||||
cache?: boolean;
|
||||
/**
|
||||
* Defines a custom cache key for a GraphQL document that will determine whether to re-run the document transform when given the same input GraphQL document. Returns an array that defines the cache key. Return `undefined` to disable caching for that GraphQL document.
|
||||
*
|
||||
* > **Note:** The items in the array may be any type, but also need to be referentially stable to guarantee a stable cache key.
|
||||
*
|
||||
* The default implementation of this function returns the `document` as the cache key.
|
||||
*/
|
||||
getCacheKey?: (document: DocumentNode) => DocumentTransformCacheKey | undefined;
|
||||
}
|
||||
export declare class DocumentTransform {
|
||||
private readonly transform;
|
||||
private cached;
|
||||
private readonly resultCache;
|
||||
private getCacheKey;
|
||||
static identity(): DocumentTransform;
|
||||
static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & {
|
||||
left: DocumentTransform;
|
||||
right: DocumentTransform;
|
||||
};
|
||||
constructor(transform: TransformFn, options?: DocumentTransformOptions);
|
||||
/**
|
||||
* Resets the internal cache of this transform, if it has one.
|
||||
*/
|
||||
resetCache(): void;
|
||||
private performWork;
|
||||
transformDocument(document: DocumentNode): DocumentNode;
|
||||
concat(otherTransform: DocumentTransform): DocumentTransform;
|
||||
/**
|
||||
* @internal
|
||||
* Used to iterate through all transforms that are concatenations or `split` links.
|
||||
*/
|
||||
readonly left?: DocumentTransform;
|
||||
/**
|
||||
* @internal
|
||||
* Used to iterate through all transforms that are concatenations or `split` links.
|
||||
*/
|
||||
readonly right?: DocumentTransform;
|
||||
}
|
||||
export {};
|
||||
//# sourceMappingURL=DocumentTransform.d.ts.map
|
||||
94
graphql-subscription/node_modules/@apollo/client/utilities/graphql/DocumentTransform.js
generated
vendored
Normal file
94
graphql-subscription/node_modules/@apollo/client/utilities/graphql/DocumentTransform.js
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
import { Trie } from "@wry/trie";
|
||||
import { canUseWeakMap, canUseWeakSet } from "../common/canUse.js";
|
||||
import { checkDocument } from "./getFromAST.js";
|
||||
import { invariant } from "../globals/index.js";
|
||||
import { WeakCache } from "@wry/caches";
|
||||
import { wrap } from "optimism";
|
||||
import { cacheSizes } from "../caching/index.js";
|
||||
function identity(document) {
|
||||
return document;
|
||||
}
|
||||
var DocumentTransform = /** @class */ (function () {
|
||||
function DocumentTransform(transform, options) {
|
||||
if (options === void 0) { options = Object.create(null); }
|
||||
this.resultCache = canUseWeakSet ? new WeakSet() : new Set();
|
||||
this.transform = transform;
|
||||
if (options.getCacheKey) {
|
||||
// Override default `getCacheKey` function, which returns [document].
|
||||
this.getCacheKey = options.getCacheKey;
|
||||
}
|
||||
this.cached = options.cache !== false;
|
||||
this.resetCache();
|
||||
}
|
||||
// This default implementation of getCacheKey can be overridden by providing
|
||||
// options.getCacheKey to the DocumentTransform constructor. In general, a
|
||||
// getCacheKey function may either return an array of keys (often including
|
||||
// the document) to be used as a cache key, or undefined to indicate the
|
||||
// transform for this document should not be cached.
|
||||
DocumentTransform.prototype.getCacheKey = function (document) {
|
||||
return [document];
|
||||
};
|
||||
DocumentTransform.identity = function () {
|
||||
// No need to cache this transform since it just returns the document
|
||||
// unchanged. This should save a bit of memory that would otherwise be
|
||||
// needed to populate the `documentCache` of this transform.
|
||||
return new DocumentTransform(identity, { cache: false });
|
||||
};
|
||||
DocumentTransform.split = function (predicate, left, right) {
|
||||
if (right === void 0) { right = DocumentTransform.identity(); }
|
||||
return Object.assign(new DocumentTransform(function (document) {
|
||||
var documentTransform = predicate(document) ? left : right;
|
||||
return documentTransform.transformDocument(document);
|
||||
},
|
||||
// Reasonably assume both `left` and `right` transforms handle their own caching
|
||||
{ cache: false }), { left: left, right: right });
|
||||
};
|
||||
/**
|
||||
* Resets the internal cache of this transform, if it has one.
|
||||
*/
|
||||
DocumentTransform.prototype.resetCache = function () {
|
||||
var _this = this;
|
||||
if (this.cached) {
|
||||
var stableCacheKeys_1 = new Trie(canUseWeakMap);
|
||||
this.performWork = wrap(DocumentTransform.prototype.performWork.bind(this), {
|
||||
makeCacheKey: function (document) {
|
||||
var cacheKeys = _this.getCacheKey(document);
|
||||
if (cacheKeys) {
|
||||
invariant(Array.isArray(cacheKeys), 66);
|
||||
return stableCacheKeys_1.lookupArray(cacheKeys);
|
||||
}
|
||||
},
|
||||
max: cacheSizes["documentTransform.cache"],
|
||||
cache: (WeakCache),
|
||||
});
|
||||
}
|
||||
};
|
||||
DocumentTransform.prototype.performWork = function (document) {
|
||||
checkDocument(document);
|
||||
return this.transform(document);
|
||||
};
|
||||
DocumentTransform.prototype.transformDocument = function (document) {
|
||||
// If a user passes an already transformed result back to this function,
|
||||
// immediately return it.
|
||||
if (this.resultCache.has(document)) {
|
||||
return document;
|
||||
}
|
||||
var transformedDocument = this.performWork(document);
|
||||
this.resultCache.add(transformedDocument);
|
||||
return transformedDocument;
|
||||
};
|
||||
DocumentTransform.prototype.concat = function (otherTransform) {
|
||||
var _this = this;
|
||||
return Object.assign(new DocumentTransform(function (document) {
|
||||
return otherTransform.transformDocument(_this.transformDocument(document));
|
||||
},
|
||||
// Reasonably assume both transforms handle their own caching
|
||||
{ cache: false }), {
|
||||
left: this,
|
||||
right: otherTransform,
|
||||
});
|
||||
};
|
||||
return DocumentTransform;
|
||||
}());
|
||||
export { DocumentTransform };
|
||||
//# sourceMappingURL=DocumentTransform.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/DocumentTransform.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/DocumentTransform.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
18
graphql-subscription/node_modules/@apollo/client/utilities/graphql/directives.d.ts
generated
vendored
Normal file
18
graphql-subscription/node_modules/@apollo/client/utilities/graphql/directives.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { SelectionNode, DirectiveNode, DocumentNode, ArgumentNode, ASTNode } from "graphql";
|
||||
export type DirectiveInfo = {
|
||||
[fieldName: string]: {
|
||||
[argName: string]: any;
|
||||
};
|
||||
};
|
||||
export declare function shouldInclude({ directives }: SelectionNode, variables?: Record<string, any>): boolean;
|
||||
export declare function getDirectiveNames(root: ASTNode): string[];
|
||||
export declare const hasAnyDirectives: (names: string[], root: ASTNode) => boolean;
|
||||
export declare const hasAllDirectives: (names: string[], root: ASTNode) => boolean;
|
||||
export declare function hasDirectives(names: string[], root: ASTNode, all?: boolean): boolean;
|
||||
export declare function hasClientExports(document: DocumentNode): boolean;
|
||||
export type InclusionDirectives = Array<{
|
||||
directive: DirectiveNode;
|
||||
ifArgument: ArgumentNode;
|
||||
}>;
|
||||
export declare function getInclusionDirectives(directives: ReadonlyArray<DirectiveNode>): InclusionDirectives;
|
||||
//# sourceMappingURL=directives.d.ts.map
|
||||
78
graphql-subscription/node_modules/@apollo/client/utilities/graphql/directives.js
generated
vendored
Normal file
78
graphql-subscription/node_modules/@apollo/client/utilities/graphql/directives.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
import { invariant } from "../globals/index.js";
|
||||
import { visit, BREAK } from "graphql";
|
||||
export function shouldInclude(_a, variables) {
|
||||
var directives = _a.directives;
|
||||
if (!directives || !directives.length) {
|
||||
return true;
|
||||
}
|
||||
return getInclusionDirectives(directives).every(function (_a) {
|
||||
var directive = _a.directive, ifArgument = _a.ifArgument;
|
||||
var evaledValue = false;
|
||||
if (ifArgument.value.kind === "Variable") {
|
||||
evaledValue =
|
||||
variables && variables[ifArgument.value.name.value];
|
||||
invariant(evaledValue !== void 0, 67, directive.name.value);
|
||||
}
|
||||
else {
|
||||
evaledValue = ifArgument.value.value;
|
||||
}
|
||||
return directive.name.value === "skip" ? !evaledValue : evaledValue;
|
||||
});
|
||||
}
|
||||
export function getDirectiveNames(root) {
|
||||
var names = [];
|
||||
visit(root, {
|
||||
Directive: function (node) {
|
||||
names.push(node.name.value);
|
||||
},
|
||||
});
|
||||
return names;
|
||||
}
|
||||
export var hasAnyDirectives = function (names, root) {
|
||||
return hasDirectives(names, root, false);
|
||||
};
|
||||
export var hasAllDirectives = function (names, root) {
|
||||
return hasDirectives(names, root, true);
|
||||
};
|
||||
export function hasDirectives(names, root, all) {
|
||||
var nameSet = new Set(names);
|
||||
var uniqueCount = nameSet.size;
|
||||
visit(root, {
|
||||
Directive: function (node) {
|
||||
if (nameSet.delete(node.name.value) && (!all || !nameSet.size)) {
|
||||
return BREAK;
|
||||
}
|
||||
},
|
||||
});
|
||||
// If we found all the names, nameSet will be empty. If we only care about
|
||||
// finding some of them, the < condition is sufficient.
|
||||
return all ? !nameSet.size : nameSet.size < uniqueCount;
|
||||
}
|
||||
export function hasClientExports(document) {
|
||||
return document && hasDirectives(["client", "export"], document, true);
|
||||
}
|
||||
function isInclusionDirective(_a) {
|
||||
var value = _a.name.value;
|
||||
return value === "skip" || value === "include";
|
||||
}
|
||||
export function getInclusionDirectives(directives) {
|
||||
var result = [];
|
||||
if (directives && directives.length) {
|
||||
directives.forEach(function (directive) {
|
||||
if (!isInclusionDirective(directive))
|
||||
return;
|
||||
var directiveArguments = directive.arguments;
|
||||
var directiveName = directive.name.value;
|
||||
invariant(directiveArguments && directiveArguments.length === 1, 68, directiveName);
|
||||
var ifArgument = directiveArguments[0];
|
||||
invariant(ifArgument.name && ifArgument.name.value === "if", 69, directiveName);
|
||||
var ifValue = 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"), 70, directiveName);
|
||||
result.push({ directive: directive, ifArgument: ifArgument });
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
//# sourceMappingURL=directives.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/directives.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/directives.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
34
graphql-subscription/node_modules/@apollo/client/utilities/graphql/fragments.d.ts
generated
vendored
Normal file
34
graphql-subscription/node_modules/@apollo/client/utilities/graphql/fragments.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { DocumentNode, FragmentDefinitionNode, InlineFragmentNode, SelectionNode } from "graphql";
|
||||
/**
|
||||
* 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 declare function getFragmentQueryDocument(document: DocumentNode, fragmentName?: string): DocumentNode;
|
||||
/**
|
||||
* This is an interface that describes a map from fragment names to fragment definitions.
|
||||
*/
|
||||
export interface FragmentMap {
|
||||
[fragmentName: string]: FragmentDefinitionNode;
|
||||
}
|
||||
export type FragmentMapFunction = (fragmentName: string) => FragmentDefinitionNode | null;
|
||||
export declare function createFragmentMap(fragments?: FragmentDefinitionNode[]): FragmentMap;
|
||||
export declare function getFragmentFromSelection(selection: SelectionNode, fragmentMap?: FragmentMap | FragmentMapFunction): InlineFragmentNode | FragmentDefinitionNode | null;
|
||||
//# sourceMappingURL=fragments.d.ts.map
|
||||
103
graphql-subscription/node_modules/@apollo/client/utilities/graphql/fragments.js
generated
vendored
Normal file
103
graphql-subscription/node_modules/@apollo/client/utilities/graphql/fragments.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
import { __assign, __spreadArray } from "tslib";
|
||||
import { invariant, newInvariantError } from "../globals/index.js";
|
||||
/**
|
||||
* 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, fragmentName) {
|
||||
var 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.
|
||||
var fragments = [];
|
||||
document.definitions.forEach(function (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 newInvariantError(
|
||||
71,
|
||||
definition.operation,
|
||||
definition.name ? " named '".concat(definition.name.value, "'") : ""
|
||||
);
|
||||
}
|
||||
// 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, 72, fragments.length);
|
||||
actualFragmentName = fragments[0].name.value;
|
||||
}
|
||||
// Generate a query document with an operation that simply spreads the
|
||||
// fragment inside of it.
|
||||
var query = __assign(__assign({}, document), { definitions: __spreadArray([
|
||||
{
|
||||
kind: "OperationDefinition",
|
||||
// OperationTypeNode is an enum
|
||||
operation: "query",
|
||||
selectionSet: {
|
||||
kind: "SelectionSet",
|
||||
selections: [
|
||||
{
|
||||
kind: "FragmentSpread",
|
||||
name: {
|
||||
kind: "Name",
|
||||
value: actualFragmentName,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
], document.definitions, true) });
|
||||
return query;
|
||||
}
|
||||
// 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) {
|
||||
if (fragments === void 0) { fragments = []; }
|
||||
var symTable = {};
|
||||
fragments.forEach(function (fragment) {
|
||||
symTable[fragment.name.value] = fragment;
|
||||
});
|
||||
return symTable;
|
||||
}
|
||||
export function getFragmentFromSelection(selection, fragmentMap) {
|
||||
switch (selection.kind) {
|
||||
case "InlineFragment":
|
||||
return selection;
|
||||
case "FragmentSpread": {
|
||||
var fragmentName = selection.name.value;
|
||||
if (typeof fragmentMap === "function") {
|
||||
return fragmentMap(fragmentName);
|
||||
}
|
||||
var fragment = fragmentMap && fragmentMap[fragmentName];
|
||||
invariant(fragment, 73, fragmentName);
|
||||
return fragment || null;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=fragments.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/fragments.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/fragments.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
15
graphql-subscription/node_modules/@apollo/client/utilities/graphql/getFromAST.d.ts
generated
vendored
Normal file
15
graphql-subscription/node_modules/@apollo/client/utilities/graphql/getFromAST.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { DocumentNode, OperationDefinitionNode, FragmentDefinitionNode } from "graphql";
|
||||
export declare function checkDocument(doc: DocumentNode): DocumentNode;
|
||||
export declare function getOperationDefinition(doc: DocumentNode): OperationDefinitionNode | undefined;
|
||||
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;
|
||||
/**
|
||||
* 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 declare function getMainDefinition(queryDoc: DocumentNode): OperationDefinitionNode | FragmentDefinitionNode;
|
||||
export declare function getDefaultValues(definition: OperationDefinitionNode | undefined): Record<string, any>;
|
||||
//# sourceMappingURL=getFromAST.d.ts.map
|
||||
89
graphql-subscription/node_modules/@apollo/client/utilities/graphql/getFromAST.js
generated
vendored
Normal file
89
graphql-subscription/node_modules/@apollo/client/utilities/graphql/getFromAST.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
import { invariant, newInvariantError } from "../globals/index.js";
|
||||
import { valueToObjectRepresentation } from "./storeUtils.js";
|
||||
// Checks the document for errors and throws an exception if there is an error.
|
||||
export function checkDocument(doc) {
|
||||
invariant(doc && doc.kind === "Document", 74);
|
||||
var operations = doc.definitions
|
||||
.filter(function (d) { return d.kind !== "FragmentDefinition"; })
|
||||
.map(function (definition) {
|
||||
if (definition.kind !== "OperationDefinition") {
|
||||
throw newInvariantError(75, definition.kind);
|
||||
}
|
||||
return definition;
|
||||
});
|
||||
invariant(operations.length <= 1, 76, operations.length);
|
||||
return doc;
|
||||
}
|
||||
export function getOperationDefinition(doc) {
|
||||
checkDocument(doc);
|
||||
return doc.definitions.filter(function (definition) {
|
||||
return definition.kind === "OperationDefinition";
|
||||
})[0];
|
||||
}
|
||||
export function getOperationName(doc) {
|
||||
return (doc.definitions
|
||||
.filter(function (definition) {
|
||||
return definition.kind === "OperationDefinition" && !!definition.name;
|
||||
})
|
||||
.map(function (x) { return x.name.value; })[0] || null);
|
||||
}
|
||||
// Returns the FragmentDefinitions from a particular document as an array
|
||||
export function getFragmentDefinitions(doc) {
|
||||
return doc.definitions.filter(function (definition) {
|
||||
return definition.kind === "FragmentDefinition";
|
||||
});
|
||||
}
|
||||
export function getQueryDefinition(doc) {
|
||||
var queryDef = getOperationDefinition(doc);
|
||||
invariant(queryDef && queryDef.operation === "query", 77);
|
||||
return queryDef;
|
||||
}
|
||||
export function getFragmentDefinition(doc) {
|
||||
invariant(doc.kind === "Document", 78);
|
||||
invariant(doc.definitions.length <= 1, 79);
|
||||
var fragmentDef = doc.definitions[0];
|
||||
invariant(fragmentDef.kind === "FragmentDefinition", 80);
|
||||
return fragmentDef;
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
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) {
|
||||
// we do this because we want to allow multiple fragment definitions
|
||||
// to precede an operation definition.
|
||||
fragmentDefinition = definition;
|
||||
}
|
||||
}
|
||||
if (fragmentDefinition) {
|
||||
return fragmentDefinition;
|
||||
}
|
||||
throw newInvariantError(81);
|
||||
}
|
||||
export function getDefaultValues(definition) {
|
||||
var defaultValues = Object.create(null);
|
||||
var defs = definition && definition.variableDefinitions;
|
||||
if (defs && defs.length) {
|
||||
defs.forEach(function (def) {
|
||||
if (def.defaultValue) {
|
||||
valueToObjectRepresentation(defaultValues, def.variable.name, def.defaultValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
return defaultValues;
|
||||
}
|
||||
//# sourceMappingURL=getFromAST.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/getFromAST.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/getFromAST.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
5
graphql-subscription/node_modules/@apollo/client/utilities/graphql/operations.d.ts
generated
vendored
Normal file
5
graphql-subscription/node_modules/@apollo/client/utilities/graphql/operations.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { DocumentNode } from "../../core/index.js";
|
||||
export declare function isMutationOperation(document: DocumentNode): boolean;
|
||||
export declare function isQueryOperation(document: DocumentNode): boolean;
|
||||
export declare function isSubscriptionOperation(document: DocumentNode): boolean;
|
||||
//# sourceMappingURL=operations.d.ts.map
|
||||
15
graphql-subscription/node_modules/@apollo/client/utilities/graphql/operations.js
generated
vendored
Normal file
15
graphql-subscription/node_modules/@apollo/client/utilities/graphql/operations.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { getOperationDefinition } from "./getFromAST.js";
|
||||
function isOperation(document, operation) {
|
||||
var _a;
|
||||
return ((_a = getOperationDefinition(document)) === null || _a === void 0 ? void 0 : _a.operation) === operation;
|
||||
}
|
||||
export function isMutationOperation(document) {
|
||||
return isOperation(document, "mutation");
|
||||
}
|
||||
export function isQueryOperation(document) {
|
||||
return isOperation(document, "query");
|
||||
}
|
||||
export function isSubscriptionOperation(document) {
|
||||
return isOperation(document, "subscription");
|
||||
}
|
||||
//# sourceMappingURL=operations.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/operations.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/operations.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../../src/utilities/graphql/operations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,SAAS,WAAW,CAClB,QAAsB,EACtB,SAAgD;;IAEhD,OAAO,CAAA,MAAA,sBAAsB,CAAC,QAAQ,CAAC,0CAAE,SAAS,MAAK,SAAS,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,QAAsB;IACxD,OAAO,WAAW,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAsB;IACrD,OAAO,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,QAAsB;IAC5D,OAAO,WAAW,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import type { DocumentNode } from \"../../core/index.js\";\nimport { getOperationDefinition } from \"./getFromAST.js\";\n\nfunction isOperation(\n document: DocumentNode,\n operation: \"query\" | \"mutation\" | \"subscription\"\n) {\n return getOperationDefinition(document)?.operation === operation;\n}\n\nexport function isMutationOperation(document: DocumentNode) {\n return isOperation(document, \"mutation\");\n}\n\nexport function isQueryOperation(document: DocumentNode) {\n return isOperation(document, \"query\");\n}\n\nexport function isSubscriptionOperation(document: DocumentNode) {\n return isOperation(document, \"subscription\");\n}\n"]}
|
||||
5
graphql-subscription/node_modules/@apollo/client/utilities/graphql/print.d.ts
generated
vendored
Normal file
5
graphql-subscription/node_modules/@apollo/client/utilities/graphql/print.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { ASTNode } from "graphql";
|
||||
export declare const print: ((ast: ASTNode) => string) & {
|
||||
reset(): void;
|
||||
};
|
||||
//# sourceMappingURL=print.d.ts.map
|
||||
21
graphql-subscription/node_modules/@apollo/client/utilities/graphql/print.js
generated
vendored
Normal file
21
graphql-subscription/node_modules/@apollo/client/utilities/graphql/print.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { print as origPrint } from "graphql";
|
||||
import { AutoCleanedWeakCache, cacheSizes, } from "../caching/index.js";
|
||||
import { registerGlobalCache } from "../caching/getMemoryInternals.js";
|
||||
var printCache;
|
||||
export var print = Object.assign(function (ast) {
|
||||
var result = printCache.get(ast);
|
||||
if (!result) {
|
||||
result = origPrint(ast);
|
||||
printCache.set(ast, result);
|
||||
}
|
||||
return result;
|
||||
}, {
|
||||
reset: function () {
|
||||
printCache = new AutoCleanedWeakCache(cacheSizes.print || 2000 /* defaultCacheSizes.print */);
|
||||
},
|
||||
});
|
||||
print.reset();
|
||||
if (globalThis.__DEV__ !== false) {
|
||||
registerGlobalCache("print", function () { return (printCache ? printCache.size : 0); });
|
||||
}
|
||||
//# sourceMappingURL=print.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/print.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/print.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"print.js","sourceRoot":"","sources":["../../../src/utilities/graphql/print.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EACL,oBAAoB,EACpB,UAAU,GAEX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,IAAI,UAAkD,CAAC;AACvD,MAAM,CAAC,IAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAChC,UAAC,GAAY;IACX,IAAI,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEjC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QACxB,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,EACD;IACE,KAAK;QACH,UAAU,GAAG,IAAI,oBAAoB,CACnC,UAAU,CAAC,KAAK,sCAA2B,CAC5C,CAAC;IACJ,CAAC;CACF,CACF,CAAC;AACF,KAAK,CAAC,KAAK,EAAE,CAAC;AAEd,IAAI,OAAO,EAAE,CAAC;IACZ,mBAAmB,CAAC,OAAO,EAAE,cAAM,OAAA,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAlC,CAAkC,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import type { ASTNode } from \"graphql\";\nimport { print as origPrint } from \"graphql\";\nimport {\n AutoCleanedWeakCache,\n cacheSizes,\n defaultCacheSizes,\n} from \"../caching/index.js\";\nimport { registerGlobalCache } from \"../caching/getMemoryInternals.js\";\n\nlet printCache!: AutoCleanedWeakCache<ASTNode, string>;\nexport const print = Object.assign(\n (ast: ASTNode) => {\n let result = printCache.get(ast);\n\n if (!result) {\n result = origPrint(ast);\n printCache.set(ast, result);\n }\n return result;\n },\n {\n reset() {\n printCache = new AutoCleanedWeakCache<ASTNode, string>(\n cacheSizes.print || defaultCacheSizes.print\n );\n },\n }\n);\nprint.reset();\n\nif (__DEV__) {\n registerGlobalCache(\"print\", () => (printCache ? printCache.size : 0));\n}\n"]}
|
||||
51
graphql-subscription/node_modules/@apollo/client/utilities/graphql/storeUtils.d.ts
generated
vendored
Normal file
51
graphql-subscription/node_modules/@apollo/client/utilities/graphql/storeUtils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import type { DirectiveNode, FieldNode, VariableNode, InlineFragmentNode, ValueNode, SelectionNode, NameNode, SelectionSetNode, DocumentNode } from "graphql";
|
||||
import type { FragmentMap } from "./fragments.js";
|
||||
export interface Reference {
|
||||
readonly __ref: string;
|
||||
}
|
||||
export declare function makeReference(id: string): Reference;
|
||||
export declare function isReference(obj: any): obj is Reference;
|
||||
export type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object;
|
||||
export interface StoreObject {
|
||||
__typename?: string;
|
||||
[storeFieldName: string]: StoreValue;
|
||||
}
|
||||
/**
|
||||
* Workaround for a TypeScript quirk:
|
||||
* types per default have an implicit index signature that makes them
|
||||
* assignable to `StoreObject`.
|
||||
* interfaces do not have that implicit index signature, so they cannot
|
||||
* be assigned to `StoreObject`.
|
||||
* This type just maps over a type or interface that is passed in,
|
||||
* implicitly adding the index signature.
|
||||
* That way, the result can be assigned to `StoreObject`.
|
||||
*
|
||||
* This is important if some user-defined interface is used e.g.
|
||||
* in cache.modify, where the `toReference` method expects a
|
||||
* `StoreObject` as input.
|
||||
*/
|
||||
export type AsStoreObject<T extends {
|
||||
__typename?: string;
|
||||
}> = {
|
||||
[K in keyof T]: T[K];
|
||||
};
|
||||
export declare function isDocumentNode(value: any): value is DocumentNode;
|
||||
export declare function valueToObjectRepresentation(argObj: any, name: NameNode, value: ValueNode, variables?: Object): void;
|
||||
export declare function storeKeyNameFromField(field: FieldNode, variables?: Object): string;
|
||||
export type Directives = {
|
||||
[directiveName: string]: {
|
||||
[argName: string]: any;
|
||||
};
|
||||
};
|
||||
declare let storeKeyNameStringify: (value: any) => string;
|
||||
export declare const getStoreKeyName: ((fieldName: string, args?: Record<string, any> | null, directives?: Directives) => string) & {
|
||||
setStringify(s: typeof storeKeyNameStringify): (value: any) => string;
|
||||
};
|
||||
export declare function argumentsObjectFromField(field: FieldNode | DirectiveNode, variables?: Record<string, any>): Object | null;
|
||||
export declare function resultKeyNameFromField(field: FieldNode): string;
|
||||
export declare function getTypenameFromResult(result: Record<string, any>, selectionSet: SelectionSetNode, fragmentMap?: FragmentMap): string | undefined;
|
||||
export declare function isField(selection: SelectionNode): selection is FieldNode;
|
||||
export declare function isInlineFragment(selection: SelectionNode): selection is InlineFragmentNode;
|
||||
export type VariableValue = (node: VariableNode) => any;
|
||||
export {};
|
||||
//# sourceMappingURL=storeUtils.d.ts.map
|
||||
213
graphql-subscription/node_modules/@apollo/client/utilities/graphql/storeUtils.js
generated
vendored
Normal file
213
graphql-subscription/node_modules/@apollo/client/utilities/graphql/storeUtils.js
generated
vendored
Normal file
@@ -0,0 +1,213 @@
|
||||
import { newInvariantError } from "../globals/index.js";
|
||||
import { isNonNullObject } from "../common/objects.js";
|
||||
import { getFragmentFromSelection } from "./fragments.js";
|
||||
import { canonicalStringify } from "../common/canonicalStringify.js";
|
||||
export function makeReference(id) {
|
||||
return { __ref: String(id) };
|
||||
}
|
||||
export function isReference(obj) {
|
||||
return Boolean(obj && typeof obj === "object" && typeof obj.__ref === "string");
|
||||
}
|
||||
export function isDocumentNode(value) {
|
||||
return (isNonNullObject(value) &&
|
||||
value.kind === "Document" &&
|
||||
Array.isArray(value.definitions));
|
||||
}
|
||||
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";
|
||||
}
|
||||
export 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 newInvariantError(82, name.value, value.kind);
|
||||
}
|
||||
}
|
||||
export 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",
|
||||
"nonreactive",
|
||||
];
|
||||
// Default stable JSON.stringify implementation used by getStoreKeyName. Can be
|
||||
// updated/replaced with something better by calling
|
||||
// getStoreKeyName.setStringify(newStringifyFunction).
|
||||
var storeKeyNameStringify = canonicalStringify;
|
||||
export var getStoreKeyName = Object.assign(function (fieldName, args, directives) {
|
||||
if (args &&
|
||||
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 filteredArgs_1 = {};
|
||||
filterKeys.forEach(function (key) {
|
||||
filteredArgs_1[key] = args[key];
|
||||
});
|
||||
return "".concat(directives["connection"]["key"], "(").concat(storeKeyNameStringify(filteredArgs_1), ")");
|
||||
}
|
||||
else {
|
||||
return directives["connection"]["key"];
|
||||
}
|
||||
}
|
||||
var completeFieldName = 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.
|
||||
var stringifiedArgs = storeKeyNameStringify(args);
|
||||
completeFieldName += "(".concat(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 += "@".concat(key, "(").concat(storeKeyNameStringify(directives[key]), ")");
|
||||
}
|
||||
else {
|
||||
completeFieldName += "@".concat(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
return completeFieldName;
|
||||
}, {
|
||||
setStringify: function (s) {
|
||||
var previous = storeKeyNameStringify;
|
||||
storeKeyNameStringify = s;
|
||||
return previous;
|
||||
},
|
||||
});
|
||||
export 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;
|
||||
}
|
||||
export function resultKeyNameFromField(field) {
|
||||
return field.alias ? field.alias.value : field.name.value;
|
||||
}
|
||||
export function getTypenameFromResult(result, selectionSet, fragmentMap) {
|
||||
var fragments;
|
||||
for (var _i = 0, _a = selectionSet.selections; _i < _a.length; _i++) {
|
||||
var selection = _a[_i];
|
||||
if (isField(selection)) {
|
||||
if (selection.name.value === "__typename") {
|
||||
return result[resultKeyNameFromField(selection)];
|
||||
}
|
||||
}
|
||||
else if (fragments) {
|
||||
fragments.push(selection);
|
||||
}
|
||||
else {
|
||||
fragments = [selection];
|
||||
}
|
||||
}
|
||||
if (typeof result.__typename === "string") {
|
||||
return result.__typename;
|
||||
}
|
||||
if (fragments) {
|
||||
for (var _b = 0, fragments_1 = fragments; _b < fragments_1.length; _b++) {
|
||||
var selection = fragments_1[_b];
|
||||
var typename = getTypenameFromResult(result, getFragmentFromSelection(selection, fragmentMap).selectionSet, fragmentMap);
|
||||
if (typeof typename === "string") {
|
||||
return typename;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export function isField(selection) {
|
||||
return selection.kind === "Field";
|
||||
}
|
||||
export function isInlineFragment(selection) {
|
||||
return selection.kind === "InlineFragment";
|
||||
}
|
||||
//# sourceMappingURL=storeUtils.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/storeUtils.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/storeUtils.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
27
graphql-subscription/node_modules/@apollo/client/utilities/graphql/transform.d.ts
generated
vendored
Normal file
27
graphql-subscription/node_modules/@apollo/client/utilities/graphql/transform.d.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { DocumentNode, FieldNode, DirectiveNode, FragmentDefinitionNode, ArgumentNode, FragmentSpreadNode, VariableDefinitionNode, ASTNode } from "graphql";
|
||||
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>;
|
||||
export declare function removeDirectivesFromDocument(directives: RemoveDirectiveConfig[], doc: DocumentNode): DocumentNode | null;
|
||||
export declare const addTypenameToDocument: (<TNode extends ASTNode>(doc: TNode) => TNode) & {
|
||||
added(field: FieldNode): boolean;
|
||||
};
|
||||
export declare function removeConnectionDirectiveFromDocument(doc: DocumentNode): DocumentNode | null;
|
||||
export declare function removeArgumentsFromDocument(config: RemoveArgumentsConfig[], doc: DocumentNode): DocumentNode | null;
|
||||
export declare function removeFragmentSpreadFromDocument(config: RemoveFragmentSpreadConfig[], doc: DocumentNode): DocumentNode | null;
|
||||
export declare function buildQueryFromSelectionSet(document: DocumentNode): DocumentNode;
|
||||
export declare function removeClientSetsFromDocument(document: DocumentNode): DocumentNode | null;
|
||||
//# sourceMappingURL=transform.d.ts.map
|
||||
482
graphql-subscription/node_modules/@apollo/client/utilities/graphql/transform.js
generated
vendored
Normal file
482
graphql-subscription/node_modules/@apollo/client/utilities/graphql/transform.js
generated
vendored
Normal file
@@ -0,0 +1,482 @@
|
||||
import { __assign, __spreadArray } from "tslib";
|
||||
import { invariant } from "../globals/index.js";
|
||||
import { visit, Kind } from "graphql";
|
||||
import { checkDocument, getOperationDefinition, getFragmentDefinition, getFragmentDefinitions, getMainDefinition, } from "./getFromAST.js";
|
||||
import { isField } from "./storeUtils.js";
|
||||
import { createFragmentMap } from "./fragments.js";
|
||||
import { isArray, isNonEmptyArray } from "../common/arrays.js";
|
||||
var TYPENAME_FIELD = {
|
||||
kind: Kind.FIELD,
|
||||
name: {
|
||||
kind: Kind.NAME,
|
||||
value: "__typename",
|
||||
},
|
||||
};
|
||||
function isEmpty(op, fragmentMap) {
|
||||
return (!op ||
|
||||
op.selectionSet.selections.every(function (selection) {
|
||||
return selection.kind === Kind.FRAGMENT_SPREAD &&
|
||||
isEmpty(fragmentMap[selection.name.value], fragmentMap);
|
||||
}));
|
||||
}
|
||||
function nullIfDocIsEmpty(doc) {
|
||||
return (isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc)))) ?
|
||||
null
|
||||
: doc;
|
||||
}
|
||||
function getDirectiveMatcher(configs) {
|
||||
var names = new Map();
|
||||
var tests = new Map();
|
||||
configs.forEach(function (directive) {
|
||||
if (directive) {
|
||||
if (directive.name) {
|
||||
names.set(directive.name, directive);
|
||||
}
|
||||
else if (directive.test) {
|
||||
tests.set(directive.test, directive);
|
||||
}
|
||||
}
|
||||
});
|
||||
return function (directive) {
|
||||
var config = names.get(directive.name.value);
|
||||
if (!config && tests.size) {
|
||||
tests.forEach(function (testConfig, test) {
|
||||
if (test(directive)) {
|
||||
config = testConfig;
|
||||
}
|
||||
});
|
||||
}
|
||||
return config;
|
||||
};
|
||||
}
|
||||
function makeInUseGetterFunction(defaultKey) {
|
||||
var map = new Map();
|
||||
return function inUseGetterFunction(key) {
|
||||
if (key === void 0) { key = defaultKey; }
|
||||
var inUse = map.get(key);
|
||||
if (!inUse) {
|
||||
map.set(key, (inUse = {
|
||||
// Variable and fragment spread names used directly within this
|
||||
// operation or fragment definition, as identified by key. These sets
|
||||
// will be populated during the first traversal of the document in
|
||||
// removeDirectivesFromDocument below.
|
||||
variables: new Set(),
|
||||
fragmentSpreads: new Set(),
|
||||
}));
|
||||
}
|
||||
return inUse;
|
||||
};
|
||||
}
|
||||
export function removeDirectivesFromDocument(directives, doc) {
|
||||
checkDocument(doc);
|
||||
// Passing empty strings to makeInUseGetterFunction means we handle anonymous
|
||||
// operations as if their names were "". Anonymous fragment definitions are
|
||||
// not supposed to be possible, but the same default naming strategy seems
|
||||
// appropriate for that case as well.
|
||||
var getInUseByOperationName = makeInUseGetterFunction("");
|
||||
var getInUseByFragmentName = makeInUseGetterFunction("");
|
||||
var getInUse = function (ancestors) {
|
||||
for (var p = 0, ancestor = void 0; p < ancestors.length && (ancestor = ancestors[p]); ++p) {
|
||||
if (isArray(ancestor))
|
||||
continue;
|
||||
if (ancestor.kind === Kind.OPERATION_DEFINITION) {
|
||||
// If an operation is anonymous, we use the empty string as its key.
|
||||
return getInUseByOperationName(ancestor.name && ancestor.name.value);
|
||||
}
|
||||
if (ancestor.kind === Kind.FRAGMENT_DEFINITION) {
|
||||
return getInUseByFragmentName(ancestor.name.value);
|
||||
}
|
||||
}
|
||||
globalThis.__DEV__ !== false && invariant.error(83);
|
||||
return null;
|
||||
};
|
||||
var operationCount = 0;
|
||||
for (var i = doc.definitions.length - 1; i >= 0; --i) {
|
||||
if (doc.definitions[i].kind === Kind.OPERATION_DEFINITION) {
|
||||
++operationCount;
|
||||
}
|
||||
}
|
||||
var directiveMatcher = getDirectiveMatcher(directives);
|
||||
var shouldRemoveField = function (nodeDirectives) {
|
||||
return isNonEmptyArray(nodeDirectives) &&
|
||||
nodeDirectives
|
||||
.map(directiveMatcher)
|
||||
.some(function (config) { return config && config.remove; });
|
||||
};
|
||||
var originalFragmentDefsByPath = new Map();
|
||||
// Any time the first traversal of the document below makes a change like
|
||||
// removing a fragment (by returning null), this variable should be set to
|
||||
// true. Once it becomes true, it should never be set to false again. If this
|
||||
// variable remains false throughout the traversal, then we can return the
|
||||
// original doc immediately without any modifications.
|
||||
var firstVisitMadeChanges = false;
|
||||
var fieldOrInlineFragmentVisitor = {
|
||||
enter: function (node) {
|
||||
if (shouldRemoveField(node.directives)) {
|
||||
firstVisitMadeChanges = true;
|
||||
return null;
|
||||
}
|
||||
},
|
||||
};
|
||||
var docWithoutDirectiveSubtrees = visit(doc, {
|
||||
// These two AST node types share the same implementation, defined above.
|
||||
Field: fieldOrInlineFragmentVisitor,
|
||||
InlineFragment: fieldOrInlineFragmentVisitor,
|
||||
VariableDefinition: {
|
||||
enter: function () {
|
||||
// VariableDefinition nodes do not count as variables in use, though
|
||||
// they do contain Variable nodes that might be visited below. To avoid
|
||||
// counting variable declarations as usages, we skip visiting the
|
||||
// contents of this VariableDefinition node by returning false.
|
||||
return false;
|
||||
},
|
||||
},
|
||||
Variable: {
|
||||
enter: function (node, _key, _parent, _path, ancestors) {
|
||||
var inUse = getInUse(ancestors);
|
||||
if (inUse) {
|
||||
inUse.variables.add(node.name.value);
|
||||
}
|
||||
},
|
||||
},
|
||||
FragmentSpread: {
|
||||
enter: function (node, _key, _parent, _path, ancestors) {
|
||||
if (shouldRemoveField(node.directives)) {
|
||||
firstVisitMadeChanges = true;
|
||||
return null;
|
||||
}
|
||||
var inUse = getInUse(ancestors);
|
||||
if (inUse) {
|
||||
inUse.fragmentSpreads.add(node.name.value);
|
||||
}
|
||||
// We might like to remove this FragmentSpread by returning null here if
|
||||
// the corresponding FragmentDefinition node is also going to be removed
|
||||
// by the logic below, but we can't control the relative order of those
|
||||
// events, so we have to postpone the removal of dangling FragmentSpread
|
||||
// nodes until after the current visit of the document has finished.
|
||||
},
|
||||
},
|
||||
FragmentDefinition: {
|
||||
enter: function (node, _key, _parent, path) {
|
||||
originalFragmentDefsByPath.set(JSON.stringify(path), node);
|
||||
},
|
||||
leave: function (node, _key, _parent, path) {
|
||||
var originalNode = originalFragmentDefsByPath.get(JSON.stringify(path));
|
||||
if (node === originalNode) {
|
||||
// If the FragmentNode received by this leave function is identical to
|
||||
// the one received by the corresponding enter function (above), then
|
||||
// the visitor must not have made any changes within this
|
||||
// FragmentDefinition node. This fragment definition may still be
|
||||
// removed if there are no ...spread references to it, but it won't be
|
||||
// removed just because it has only a __typename field.
|
||||
return node;
|
||||
}
|
||||
if (
|
||||
// This logic applies only if the document contains one or more
|
||||
// operations, since removing all fragments from a document containing
|
||||
// only fragments makes the document useless.
|
||||
operationCount > 0 &&
|
||||
node.selectionSet.selections.every(function (selection) {
|
||||
return selection.kind === Kind.FIELD &&
|
||||
selection.name.value === "__typename";
|
||||
})) {
|
||||
// This is a somewhat opinionated choice: if a FragmentDefinition ends
|
||||
// up having no fields other than __typename, we remove the whole
|
||||
// fragment definition, and later prune ...spread references to it.
|
||||
getInUseByFragmentName(node.name.value).removed = true;
|
||||
firstVisitMadeChanges = true;
|
||||
return null;
|
||||
}
|
||||
},
|
||||
},
|
||||
Directive: {
|
||||
leave: function (node) {
|
||||
// If a matching directive is found, remove the directive itself. Note
|
||||
// that this does not remove the target (field, argument, etc) of the
|
||||
// directive, but only the directive itself.
|
||||
if (directiveMatcher(node)) {
|
||||
firstVisitMadeChanges = true;
|
||||
return null;
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!firstVisitMadeChanges) {
|
||||
// If our first pass did not change anything about the document, then there
|
||||
// is no cleanup we need to do, and we can return the original doc.
|
||||
return doc;
|
||||
}
|
||||
// Utility for making sure inUse.transitiveVars is recursively populated.
|
||||
// Because this logic assumes inUse.fragmentSpreads has been completely
|
||||
// populated and inUse.removed has been set if appropriate,
|
||||
// populateTransitiveVars must be called after that information has been
|
||||
// collected by the first traversal of the document.
|
||||
var populateTransitiveVars = function (inUse) {
|
||||
if (!inUse.transitiveVars) {
|
||||
inUse.transitiveVars = new Set(inUse.variables);
|
||||
if (!inUse.removed) {
|
||||
inUse.fragmentSpreads.forEach(function (childFragmentName) {
|
||||
populateTransitiveVars(getInUseByFragmentName(childFragmentName)).transitiveVars.forEach(function (varName) {
|
||||
inUse.transitiveVars.add(varName);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
return inUse;
|
||||
};
|
||||
// Since we've been keeping track of fragment spreads used by particular
|
||||
// operations and fragment definitions, we now need to compute the set of all
|
||||
// spreads used (transitively) by any operations in the document.
|
||||
var allFragmentNamesUsed = new Set();
|
||||
docWithoutDirectiveSubtrees.definitions.forEach(function (def) {
|
||||
if (def.kind === Kind.OPERATION_DEFINITION) {
|
||||
populateTransitiveVars(getInUseByOperationName(def.name && def.name.value)).fragmentSpreads.forEach(function (childFragmentName) {
|
||||
allFragmentNamesUsed.add(childFragmentName);
|
||||
});
|
||||
}
|
||||
else if (def.kind === Kind.FRAGMENT_DEFINITION &&
|
||||
// If there are no operations in the document, then all fragment
|
||||
// definitions count as usages of their own fragment names. This heuristic
|
||||
// prevents accidentally removing all fragment definitions from the
|
||||
// document just because it contains no operations that use the fragments.
|
||||
operationCount === 0 &&
|
||||
!getInUseByFragmentName(def.name.value).removed) {
|
||||
allFragmentNamesUsed.add(def.name.value);
|
||||
}
|
||||
});
|
||||
// Now that we have added all fragment spreads used by operations to the
|
||||
// allFragmentNamesUsed set, we can complete the set by transitively adding
|
||||
// all fragment spreads used by those fragments, and so on.
|
||||
allFragmentNamesUsed.forEach(function (fragmentName) {
|
||||
// Once all the childFragmentName strings added here have been seen already,
|
||||
// the top-level allFragmentNamesUsed.forEach loop will terminate.
|
||||
populateTransitiveVars(getInUseByFragmentName(fragmentName)).fragmentSpreads.forEach(function (childFragmentName) {
|
||||
allFragmentNamesUsed.add(childFragmentName);
|
||||
});
|
||||
});
|
||||
var fragmentWillBeRemoved = function (fragmentName) {
|
||||
return !!(
|
||||
// A fragment definition will be removed if there are no spreads that refer
|
||||
// to it, or the fragment was explicitly removed because it had no fields
|
||||
// other than __typename.
|
||||
(!allFragmentNamesUsed.has(fragmentName) ||
|
||||
getInUseByFragmentName(fragmentName).removed));
|
||||
};
|
||||
var enterVisitor = {
|
||||
enter: function (node) {
|
||||
if (fragmentWillBeRemoved(node.name.value)) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
};
|
||||
return nullIfDocIsEmpty(visit(docWithoutDirectiveSubtrees, {
|
||||
// If the fragment is going to be removed, then leaving any dangling
|
||||
// FragmentSpread nodes with the same name would be a mistake.
|
||||
FragmentSpread: enterVisitor,
|
||||
// This is where the fragment definition is actually removed.
|
||||
FragmentDefinition: enterVisitor,
|
||||
OperationDefinition: {
|
||||
leave: function (node) {
|
||||
// Upon leaving each operation in the depth-first AST traversal, prune
|
||||
// any variables that are declared by the operation but unused within.
|
||||
if (node.variableDefinitions) {
|
||||
var usedVariableNames_1 = populateTransitiveVars(
|
||||
// If an operation is anonymous, we use the empty string as its key.
|
||||
getInUseByOperationName(node.name && node.name.value)).transitiveVars;
|
||||
// According to the GraphQL spec, all variables declared by an
|
||||
// operation must either be used by that operation or used by some
|
||||
// fragment included transitively into that operation:
|
||||
// https://spec.graphql.org/draft/#sec-All-Variables-Used
|
||||
//
|
||||
// To stay on the right side of this validation rule, if/when we
|
||||
// remove the last $var references from an operation or its fragments,
|
||||
// we must also remove the corresponding $var declaration from the
|
||||
// enclosing operation. This pruning applies only to operations and
|
||||
// not fragment definitions, at the moment. Fragments may be able to
|
||||
// declare variables eventually, but today they can only consume them.
|
||||
if (usedVariableNames_1.size < node.variableDefinitions.length) {
|
||||
return __assign(__assign({}, node), { variableDefinitions: node.variableDefinitions.filter(function (varDef) {
|
||||
return usedVariableNames_1.has(varDef.variable.name.value);
|
||||
}) });
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}));
|
||||
}
|
||||
export var addTypenameToDocument = Object.assign(function (doc) {
|
||||
return visit(doc, {
|
||||
SelectionSet: {
|
||||
enter: function (node, _key, parent) {
|
||||
// Don't add __typename to OperationDefinitions.
|
||||
if (parent &&
|
||||
parent.kind ===
|
||||
Kind.OPERATION_DEFINITION) {
|
||||
return;
|
||||
}
|
||||
// No changes if no selections.
|
||||
var selections = node.selections;
|
||||
if (!selections) {
|
||||
return;
|
||||
}
|
||||
// If selections already have a __typename, or are part of an
|
||||
// introspection query, do nothing.
|
||||
var skip = selections.some(function (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).
|
||||
var field = parent;
|
||||
if (isField(field) &&
|
||||
field.directives &&
|
||||
field.directives.some(function (d) { return d.name.value === "export"; })) {
|
||||
return;
|
||||
}
|
||||
// Create and return a new SelectionSet with a __typename Field.
|
||||
return __assign(__assign({}, node), { selections: __spreadArray(__spreadArray([], selections, true), [TYPENAME_FIELD], false) });
|
||||
},
|
||||
},
|
||||
});
|
||||
}, {
|
||||
added: function (field) {
|
||||
return field === 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"; })) {
|
||||
globalThis.__DEV__ !== false && invariant.warn(84);
|
||||
}
|
||||
}
|
||||
return willRemove;
|
||||
},
|
||||
};
|
||||
export 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 getArgumentMatcher(config) {
|
||||
return function argumentMatcher(argument) {
|
||||
return config.some(function (aConfig) {
|
||||
return argument.value &&
|
||||
argument.value.kind === Kind.VARIABLE &&
|
||||
argument.value.name &&
|
||||
(aConfig.name === argument.value.name.value ||
|
||||
(aConfig.test && aConfig.test(argument)));
|
||||
});
|
||||
};
|
||||
}
|
||||
export function removeArgumentsFromDocument(config, doc) {
|
||||
var argMatcher = getArgumentMatcher(config);
|
||||
return nullIfDocIsEmpty(visit(doc, {
|
||||
OperationDefinition: {
|
||||
enter: function (node) {
|
||||
return __assign(__assign({}, node), {
|
||||
// Remove matching top level variables definitions.
|
||||
variableDefinitions: node.variableDefinitions ?
|
||||
node.variableDefinitions.filter(function (varDef) {
|
||||
return !config.some(function (arg) { return arg.name === varDef.variable.name.value; });
|
||||
})
|
||||
: [] });
|
||||
},
|
||||
},
|
||||
Field: {
|
||||
enter: function (node) {
|
||||
// If `remove` is set to true for an argument, and an argument match
|
||||
// is found for a field, remove the field as well.
|
||||
var shouldRemoveField = config.some(function (argConfig) { return argConfig.remove; });
|
||||
if (shouldRemoveField) {
|
||||
var argMatchCount_1 = 0;
|
||||
if (node.arguments) {
|
||||
node.arguments.forEach(function (arg) {
|
||||
if (argMatcher(arg)) {
|
||||
argMatchCount_1 += 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (argMatchCount_1 === 1) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
Argument: {
|
||||
enter: function (node) {
|
||||
// Remove all matching arguments.
|
||||
if (argMatcher(node)) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
},
|
||||
}));
|
||||
}
|
||||
export 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 },
|
||||
}));
|
||||
}
|
||||
// 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) {
|
||||
var definition = getMainDefinition(document);
|
||||
var definitionOperation = 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.
|
||||
var modifiedDoc = visit(document, {
|
||||
OperationDefinition: {
|
||||
enter: function (node) {
|
||||
return __assign(__assign({}, node), { operation: "query" });
|
||||
},
|
||||
},
|
||||
});
|
||||
return modifiedDoc;
|
||||
}
|
||||
// Remove fields / selection sets that include an @client directive.
|
||||
export function removeClientSetsFromDocument(document) {
|
||||
checkDocument(document);
|
||||
var modifiedDoc = removeDirectivesFromDocument([
|
||||
{
|
||||
test: function (directive) { return directive.name.value === "client"; },
|
||||
remove: true,
|
||||
},
|
||||
], document);
|
||||
return modifiedDoc;
|
||||
}
|
||||
//# sourceMappingURL=transform.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/transform.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/utilities/graphql/transform.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user