@apollo/client
Version:
A fully-featured caching GraphQL client.
39 lines (38 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDeferredFragment = void 0;
const graphql_1 = require("graphql");
const sizes_js_1 = require("../caching/sizes.cjs");
const canonicalStringify_js_1 = require("./canonicalStringify.cjs");
const memoize_js_1 = require("./memoize.cjs");
/**
* @internal
*
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
*/
exports.isDeferredFragment = (0, memoize_js_1.memoize)(function isDeferredFragment(fragmentSelection, variables) {
return !!fragmentSelection.directives?.some((directive) => {
if (directive.name.value !== "defer") {
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:
return !!variables?.[arg.value.name.value];
}
}
}
return true;
});
}, {
max: sizes_js_1.cacheSizes["isDeferredFragment"] ||
2000 /* defaultCacheSizes["isDeferredFragment"] */,
makeCacheKey: ([selection, variables]) => [
selection,
(0, canonicalStringify_js_1.canonicalStringify)(variables),
],
});
//# sourceMappingURL=isDeferredFragment.cjs.map