@apollo/client
Version:
A fully-featured caching GraphQL client.
34 lines (33 loc) • 1.23 kB
JavaScript
import { Kind } from "graphql";
import { cacheSizes } from "../caching/sizes.js";
import { memoize } from "./memoize.js";
const memoized = memoize(function (fragmentSelection) {
const directive = fragmentSelection.directives?.find((directive) => directive.name.value === "defer");
if (!directive)
return false;
for (const arg of directive.arguments ?? []) {
if (arg.name.value === "if") {
switch (arg.value.kind) {
case Kind.BOOLEAN:
return arg.value.value;
case Kind.VARIABLE:
const varName = arg.value.name.value;
return (variables) => !!variables?.[varName];
}
}
}
return true;
}, {
max: cacheSizes["isDeferredFragment"] ||
2000 /* defaultCacheSizes["isDeferredFragment"] */,
});
/**
* @internal
*
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
*/
export function isDeferredFragment(fragmentSelection, variables) {
const result = memoized(fragmentSelection);
return typeof result === "function" ? result(variables) : result;
}
//# sourceMappingURL=isDeferredFragment.js.map