@apollo/client
Version:
A fully-featured caching GraphQL client.
36 lines (35 loc) • 1.25 kB
JavaScript
import { Kind } from "graphql";
import { cacheSizes } from "../caching/sizes.js";
import { canonicalStringify } from "./canonicalStringify.js";
import { memoize } from "./memoize.js";
/**
* @internal
*
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
*/
export const isDeferredFragment = 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 Kind.BOOLEAN:
return arg.value.value;
case Kind.VARIABLE:
return !!variables?.[arg.value.name.value];
}
}
}
return true;
});
}, {
max: cacheSizes["isDeferredFragment"] ||
2000 /* defaultCacheSizes["isDeferredFragment"] */,
makeCacheKey: ([selection, variables]) => [
selection,
canonicalStringify(variables),
],
});
//# sourceMappingURL=isDeferredFragment.js.map