UNPKG

fuse

Version:

The magical GraphQL framework

140 lines (136 loc) 5.91 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/next/rsc.ts var rsc_exports = {}; __export(rsc_exports, { __internal_execute: () => __internal_execute, cacheExchange: () => cacheExchange, createClient: () => createClient, registerClient: () => import_rsc.registerUrql }); module.exports = __toCommonJS(rsc_exports); var import_core2 = require("@urql/core"); var import_graphql = require("graphql"); var import_fuse = require("fuse"); var import_rsc = require("@urql/next/rsc"); __reExport(rsc_exports, require("@urql/core"), module.exports); // src/exchanges/cache.ts var import_core = require("@urql/core"); var import_wonka = require("wonka"); var cacheExchange = ({ forward, client, dispatchDebug }) => { const cache$ = (0, import_core.cacheExchange)({ client, dispatchDebug, forward }); const warned = /* @__PURE__ */ new Set(); return (ops$) => { return (0, import_wonka.pipe)( cache$(ops$), (0, import_wonka.tap)((result) => { if (process.env.NODE_ENV === "production") return; if (warned.has(result.operation.key)) return; if (result.operation.kind === "mutation" && !result.operation.context.additionalTypenames) { Object.entries(result.data).forEach(([key, value]) => { if (value != null && typeof value !== "object") { warned.add(result.operation.key); console.warn( `Saw return of type "${typeof value}" for "${key}", returning scalar values can lead to stale cache-entires. Consider using "additionalTypenames" to correctly evict cache-entries affected by this mutation.` ); } }); } else if (result.operation.kind === "query" && !result.operation.context.additionalTypenames) { Object.entries(result.data).forEach(([key, value]) => { if (value == null) { warned.add(result.operation.key); console.warn( `Saw return value of "null" for "${key}", we aren't able to derive an associated type for this key, this means that a mutation won't be able to evict this query. Consider using "additionalTypenames" to correctly evict this cache-entry.` ); } else if (Array.isArray(value) && value.length === 0) { warned.add(result.operation.key); console.warn( `Saw an empty array for "${key}", we aren't able to derive an associated type for members of this list, this means that a mutation won't be able to evict this query. Consider using "additionalTypenames" to correctly evict this cache-entry.` ); } else if (value != null && typeof value === "object") { const data = value; if (data.nodes && Array.isArray(data.nodes) && data.nodes.length === 0) { warned.add(result.operation.key); console.warn( `Saw an empty array for "${key}.nodes", we aren't able to derive an associated type for members of this list, this means that a mutation won't be able to evict this query. Consider using "additionalTypenames" to correctly evict this cache-entry.` ); } else if (data.edges && Array.isArray(data.edges) && data.edges.length === 0) { warned.add(result.operation.key); console.warn( `Saw an empty array for "${key}.edges", we aren't able to derive an associated type for members of this list, this means that a mutation won't be able to evict this query. Consider using "additionalTypenames" to correctly evict this cache-entry.` ); } } }); } }) ); }; }; // src/next/rsc.ts var convertNullprototype = (obj) => { if (obj == null || typeof obj !== "object") return obj; if (Array.isArray(obj)) { return obj.map(convertNullprototype); } else if (typeof obj === "object") { return Object.keys(obj).reduce( (acc, key) => { acc[key] = convertNullprototype(obj[key]); return acc; }, {} ); } }; var __internal_execute = async (request) => { const params = { query: (0, import_graphql.print)(request.query), variables: request.variables || {} }; const allContext = { ...request.context ? request.context(params) : {}, params }; const result = await (0, import_graphql.execute)({ document: request.query, schema: import_fuse.builder.toSchema(), variableValues: request.variables || {}, contextValue: allContext }); return convertNullprototype(result); }; var createClient = (opts) => { const options = { ...opts, exchanges: opts.exchanges || [import_core2.fetchExchange] }; return (0, import_core2.createClient)(options); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { __internal_execute, cacheExchange, createClient, registerClient, ...require("@urql/core") });