UNPKG

@apollo/client

Version:

A fully-featured caching GraphQL client.

39 lines (38 loc) • 1.31 kB
import { Kind } from "graphql"; import { cacheSizes } from "../caching/sizes.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. */ const memoized = memoize(function (field) { const directive = field.directives?.find((directive) => directive.name.value === "stream"); 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["isStreamField"] || 2000 /* defaultCacheSizes["isStreamField"] */, }); /** * @internal * * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time. */ export function isStreamField(field, variables) { const result = memoized(field); return typeof result === "function" ? result(variables) : result; } //# sourceMappingURL=isStreamField.js.map