UNPKG

fuse

Version:

The magical GraphQL framework

190 lines (186 loc) 8.18 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); var __objRest = (source, exclude) => { var target = {}; for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop]; if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) { if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop]; } return target; }; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/next/pages.ts var pages_exports = {}; __export(pages_exports, { cacheExchange: () => cacheExchange, initGraphQLClient: () => initGraphQLClient, withGraphQLClient: () => withGraphQLClient }); module.exports = __toCommonJS(pages_exports); var React = __toESM(require("react")); var import_urql = require("urql"); // src/exchanges/cache.ts var import_core = require("@urql/core"); var import_wonka = require("wonka"); var cacheExchange = ({ forward, client: client2, dispatchDebug }) => { const cache$ = (0, import_core.cacheExchange)({ client: client2, dispatchDebug, forward }); const warned = /* @__PURE__ */ new Set(); return (ops$) => { return (0, import_wonka.pipe)( cache$(ops$), (0, import_wonka.tap)((result) => { if (false) 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/pages.ts __reExport(pages_exports, require("urql"), module.exports); var ssr; var client = null; function initGraphQLClient(clientOptions) { const isServer = typeof window === "undefined"; if (isServer || !client) { client = (0, import_urql.createClient)(clientOptions); client.toJSON = () => null; } return client; } function withGraphQLClient(getClientConfig) { return (AppOrPage) => { const WithUrql = (_a) => { var _b = _a, { pageProps, urqlClient, graphqlState } = _b, rest = __objRest(_b, [ "pageProps", "urqlClient", "graphqlState" ]); const urqlServerState = pageProps && pageProps.graphqlState || graphqlState; const client2 = React.useMemo(() => { if (urqlClient) { return urqlClient; } if (!ssr || typeof window === "undefined") { ssr = (0, import_urql.ssrExchange)({ initialState: urqlServerState, isClient: true }); } else if (typeof window === "undefined") { ssr.restoreData(urqlServerState); } const clientConfig = getClientConfig(ssr); return initGraphQLClient(__spreadProps(__spreadValues({}, clientConfig), { exchanges: clientConfig.exchanges || [ cacheExchange, ssr, import_urql.fetchExchange ] })); }, [urqlClient, urqlServerState]); return React.createElement( import_urql.Provider, { value: client2 }, React.createElement(AppOrPage, __spreadProps(__spreadValues({}, rest), { pageProps, urqlClient: client2 })) ); }; const displayName = AppOrPage.displayName || AppOrPage.name || "Component"; WithUrql.displayName = `withUrqlClient(${displayName})`; if (AppOrPage.getLayout) { WithUrql.getLayout = AppOrPage.getLayout; } return WithUrql; }; }