UNPKG

@apollo/client

Version:

A fully-featured caching GraphQL client.

42 lines (41 loc) • 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isStreamField = isStreamField; const graphql_1 = require("graphql"); const sizes_js_1 = require("../caching/sizes.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. */ const memoized = (0, memoize_js_1.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 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["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. */ function isStreamField(field, variables) { const result = memoized(field); return typeof result === "function" ? result(variables) : result; } //# sourceMappingURL=isStreamField.cjs.map