@apollo/client
Version:
A fully-featured caching GraphQL client.
37 lines (36 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDeferredFragment = isDeferredFragment;
const graphql_1 = require("graphql");
const sizes_js_1 = require("../caching/sizes.cjs");
const memoize_js_1 = require("./memoize.cjs");
const memoized = (0, memoize_js_1.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 graphql_1.Kind.BOOLEAN:
return arg.value.value;
case graphql_1.Kind.VARIABLE:
const varName = arg.value.name.value;
return (variables) => !!variables?.[varName];
}
}
}
return true;
}, {
max: sizes_js_1.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.
*/
function isDeferredFragment(fragmentSelection, variables) {
const result = memoized(fragmentSelection);
return typeof result === "function" ? result(variables) : result;
}
//# sourceMappingURL=isDeferredFragment.cjs.map