feat(smart-app): implement complete mobile app MVP

- App.tsx: full navigation (Auth stack + Main tabs with 5 screens)
- Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen
- HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors
- MapScreen: interactive map with layer toggles (6 layers)
- MarketplaceScreen: categories (6), products (5), search
- ChatScreen: AI chat with quick prompts (4), bot responses
- ProfileScreen: user info, stats, menu (9 items), logout
- AlertsScreen: alert list with severity, acknowledge
- SensorsScreen: sensor list with type filters (6 types), search
- ZonesScreen: zone cards with stats
- SettingsScreen: language picker (FR/EN/ES/DE), privacy, about
- Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n
- Hooks: useSensors, useAlerts, useNotifications, useLocation
- Components: Card, Button, LoadingSpinner, ErrorBoundary, Header
- Services: iotService, notificationService (with axios API client)
- Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN)
- Theme: colors.ts with full design system (Blue Ocean palette)
- Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
This commit is contained in:
Eric FELIXINE
2026-06-01 18:00:35 -04:00
parent 08ca495bde
commit e30ae8ed09
35578 changed files with 3703534 additions and 43 deletions

View File

@@ -0,0 +1,434 @@
# @urql/core
## 2.3.6
### Patch Changes
- Extend peer dependency range of `graphql` to include `^16.0.0`.
As always when upgrading across many packages of `urql`, especially including `@urql/core` we recommend you to deduplicate dependencies after upgrading, using `npm dedupe` or `npx yarn-deduplicate`, by [@kitten](https://github.com/kitten) (See [#2133](https://github.com/FormidableLabs/urql/pull/2133))
## 2.3.5
### Patch Changes
- ⚠️ Fix issue where `maskTypename` would ignore array shapes, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#2074](https://github.com/FormidableLabs/urql/pull/2074))
## 2.3.4
### Patch Changes
- Prevent `Buffer` from being polyfilled by an automatic detection in Webpack. Instead of referencing the `Buffer` global we now simply check the constructor name, by [@kitten](https://github.com/kitten) (See [#2027](https://github.com/FormidableLabs/urql/pull/2027))
- ⚠️ Fix error-type of an `ExecutionResult` to line up with subscription-libs, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#1998](https://github.com/FormidableLabs/urql/pull/1998))
## 2.3.3
### Patch Changes
- Adding option to `ssrExchange` to include the `extensions` field of operation results in the cache, by [@dios-david](https://github.com/dios-david) (See [#1985](https://github.com/FormidableLabs/urql/pull/1985))
## 2.3.2
### Patch Changes
- ⚠️ Fix issue where the ssr-exchange would loop due to checking network-only revalidations, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#1944](https://github.com/FormidableLabs/urql/pull/1944))
## 2.3.1
### Patch Changes
- ⚠️ Fix mark `query.__key` as non-enumerable so `formatDocument` does not restore previous invocations when cloning the gql-ast, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#1870](https://github.com/FormidableLabs/urql/pull/1870))
- ⚠️ Fix: update toPromise to exclude `hasNext` results. This change ensures that
when we call toPromise() on a query we wont serve an incomplete result, the
user will expect to receive a non-stale full-result when using toPromise(), by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#1880](https://github.com/FormidableLabs/urql/pull/1880))
## 2.3.0
### Minor Changes
- Add **experimental** support for `@defer` and `@stream` responses for GraphQL. This implements the ["GraphQL Defer and Stream Directives"](https://github.com/graphql/graphql-spec/blob/4fd39e0/rfcs/DeferStream.md) and ["Incremental Delivery over HTTP"](https://github.com/graphql/graphql-over-http/blob/290b0e2/rfcs/IncrementalDelivery.md) specifications. If a GraphQL API supports `multipart/mixed` responses for deferred and streamed delivery of GraphQL results, `@urql/core` (and all its derived fetch implementations) will attempt to stream results. This is _only supported_ on browsers [supporting streamed fetch responses](https://developer.mozilla.org/en-US/docs/Web/API/Response/body), which excludes IE11.
The implementation of streamed multipart responses is derived from [`meros` by `@maraisr`](https://github.com/maraisr/meros), and is subject to change if the RFCs end up changing, by [@kitten](https://github.com/kitten) (See [#1854](https://github.com/FormidableLabs/urql/pull/1854))
## 2.2.0
### Minor Changes
- Add a `staleWhileRevalidate` option to the `ssrExchange`, which allows the client to immediately refetch a new result on hydration, which may be used for cached / stale SSR or SSG pages. This is different from using `cache-and-network` by default (which isn't recommended) as the `ssrExchange` typically acts like a "replacement fetch request", by [@kitten](https://github.com/kitten) (See [#1852](https://github.com/FormidableLabs/urql/pull/1852))
### Patch Changes
- ⚠️ Fix prevent mangling embedded strings in queries sent using the `GET` method, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#1851](https://github.com/FormidableLabs/urql/pull/1851))
- The [single-source behavior previously](https://github.com/FormidableLabs/urql/pull/1515) wasn't effective for implementations like React,
where the issue presents itself when the state of an operation is first polled. This led to the operation being torn down erroneously.
We now ensure that operations started at the same time still use a shared single-source, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#1850](https://github.com/FormidableLabs/urql/pull/1850))
## 2.1.6
### Patch Changes
- Warn for invalid operation passed to query/subscription/mutation, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#1829](https://github.com/FormidableLabs/urql/pull/1829))
## 2.1.5
### Patch Changes
- Prevent `ssrExchange().restoreData()` from adding results to the exchange that have already been invalidated. This may happen when `restoreData()` is called repeatedly, e.g. per page. When a prior run has already invalidated an SSR result then the result is 'migrated' to the user's `cacheExchange`, which means that `restoreData()` should never attempt to re-add it again, by [@kitten](https://github.com/kitten) (See [#1776](https://github.com/FormidableLabs/urql/pull/1776))
- ⚠️ Fix accidental change in passive `stale: true`, where a `cache-first` operation issued by Graphcache wouldn't yield an affected query and update its result to reflect the loading state with `stale: true`. This is a regression from `v2.1.0` and mostly becomes unexpected when `cache.invalidate(...)` is used, by [@kitten](https://github.com/kitten) (See [#1755](https://github.com/FormidableLabs/urql/pull/1755))
## 2.1.4
### Patch Changes
- Prevent stale results from being emitted by promisified query sources, e.g. `client.query(...).toPromise()` yielding a partial result with `stale: true` set. Instead, `.toPromise()` will now filter out stale results, by [@kitten](https://github.com/kitten) (See [#1709](https://github.com/FormidableLabs/urql/pull/1709))
## 2.1.3
### Patch Changes
- Treat empty variables the same as no variables in `@urql/core`'s `createRequest`, by [@kitten](https://github.com/kitten) (See [#1695](https://github.com/FormidableLabs/urql/pull/1695))
## 2.1.2
### Patch Changes
- ⚠️ Fix a condition under which the `Client` would hang when a query is started and consumed with `toPromise()`, by [@kitten](https://github.com/kitten) (See [#1634](https://github.com/FormidableLabs/urql/pull/1634))
- Refactor `Client` to hide some implementation details and to reduce size, by [@kitten](https://github.com/kitten) (See [#1638](https://github.com/FormidableLabs/urql/pull/1638))
## 2.1.1
### Patch Changes
- ⚠️ Fix a regression in `@urql/core@2.1.1` that prevented concurrent operations from being dispatched with differing request policies, which for instance prevented the explicit `executeQuery` calls on bindings to fail, by [@kitten](https://github.com/kitten) (See [#1626](https://github.com/FormidableLabs/urql/pull/1626))
## 2.1.0
### Minor Changes
- With the "single-source behavior" the `Client` will now also avoid executing an operation if it's already active, has a previous result available, and is either run with the `cache-first` or `cache-only` request policies. This is similar to a "short circuiting" behavior, where unnecessary work is avoided by not issuing more operations into the exchange pipeline than expected, by [@kitten](https://github.com/kitten) (See [#1600](https://github.com/FormidableLabs/urql/pull/1600))
- Add consistent "single-source behavior" which makes the `Client` more forgiving when duplicate
sources are used, which previously made it difficult to use the same operation across an app
together with `cache-and-network`; This was a rare use-case, and it isn't recommended to overfetch
data across an app, however, the new `Client` implementation of shared sources ensures that when an
operation is active that the `Client` distributes the last known result for the active operation to
any new usages of it (which is called “replaying stale results”) (See [#1515](https://github.com/FormidableLabs/urql/pull/1515))
### Patch Changes
- Remove closure-compiler from the build step (See [#1570](https://github.com/FormidableLabs/urql/pull/1570))
- ⚠️ Fix inconsistency in generating keys for `DocumentNode`s, especially when using GraphQL Code Generator, which could cause SSR serialization to fail, by [@zenflow](https://github.com/zenflow) (See [#1509](https://github.com/FormidableLabs/urql/pull/1509))
## 2.0.0
### Major Changes
- **Breaking**: Remove `pollInterval` feature from `OperationContext`. Instead consider using a source that uses `Wonka.interval` and `Wonka.switchMap` over `client.query()`'s source, by [@kitten](https://github.com/kitten) (See [#1374](https://github.com/FormidableLabs/urql/pull/1374))
- Remove deprecated `operationName` property from `Operation`s. The new `Operation.kind` property is now preferred. If you're creating new operations you may also use the `makeOperation` utility instead.
When upgrading `@urql/core` please ensure that your package manager didn't install any duplicates of it. You may deduplicate it manually using `npx yarn-deduplicate` (for Yarn) or `npm dedupe` (for npm), by [@kitten](https://github.com/kitten) (See [#1357](https://github.com/FormidableLabs/urql/pull/1357))
### Minor Changes
- Reemit an `OperationResult` as `stale: true` if it's being reexecuted as `network-only` operation to give bindings immediate feedback on background refetches, by [@kitten](https://github.com/kitten) (See [#1375](https://github.com/FormidableLabs/urql/pull/1375))
## 1.16.2
### Patch Changes
- Add a workaround for `graphql-tag/loader`, which provides filtered query documents (where the original document contains multiple operations) without updating or providing a correct `document.loc.source.body` string, by [@kitten](https://github.com/kitten) (See [#1315](https://github.com/FormidableLabs/urql/pull/1315))
## 1.16.1
### Patch Changes
- Add fragment deduplication to `gql` tag. Identical fragments can now be interpolated multiple times without a warning being triggered or them being duplicated in `gql`'s output, by [@kitten](https://github.com/kitten) (See [#1225](https://github.com/FormidableLabs/urql/pull/1225))
## 1.16.0
### Minor Changes
- Add a built-in `gql` tag function helper to `@urql/core`. This behaves similarly to `graphql-tag` but only warns about _locally_ duplicated fragment names rather than globally. It also primes `@urql/core`'s key cache with the parsed `DocumentNode`, by [@kitten](https://github.com/kitten) (See [#1187](https://github.com/FormidableLabs/urql/pull/1187))
### Patch Changes
- ⚠️ Fix edge case in `formatDocument`, which fails to add a `__typename` field if it has been aliased to a different name, by [@kitten](https://github.com/kitten) (See [#1186](https://github.com/FormidableLabs/urql/pull/1186))
- Cache results of `formatDocument` by the input document's key, by [@kitten](https://github.com/kitten) (See [#1186](https://github.com/FormidableLabs/urql/pull/1186))
## 1.15.2
### Patch Changes
- Don't add `undefined` to any property of the `ssrExchange`'s serialized results, as this would crash in Next.js, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#1168](https://github.com/FormidableLabs/urql/pull/1168))
## 1.15.1
### Patch Changes
- Export `getOperationName` from `@urql/core` and use it in `@urql/exchange-execute`, fixing several imports, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#1135](https://github.com/FormidableLabs/urql/pull/1135))
## 1.15.0
### Minor Changes
- Improve the Suspense implementation, which fixes edge-cases when Suspense is used with subscriptions, partially disabled, or _used on the client-side_. It has now been ensured that client-side suspense functions without the deprecated `suspenseExchange` and uncached results are loaded consistently. As part of this work, the `Client` itself does now never throw Suspense promises anymore, which is functionality that either way has no place outside of the React/Preact bindings, by [@kitten](https://github.com/kitten) (See [#1123](https://github.com/FormidableLabs/urql/pull/1123))
### Patch Changes
- Use `Record` over `object` type for subscription operation variables. The `object` type is currently hard to use ([see this issue](https://github.com/microsoft/TypeScript/issues/21732)), by [@enisdenjo](https://github.com/enisdenjo) (See [#1119](https://github.com/FormidableLabs/urql/pull/1119))
- Add support for `TypedDocumentNode` to infer the type of the `OperationResult` and `Operation` for all methods, functions, and hooks that either directly or indirectly accept a `DocumentNode`. See [`graphql-typed-document-node` and the corresponding blog post for more information.](https://github.com/dotansimha/graphql-typed-document-node), by [@kitten](https://github.com/kitten) (See [#1113](https://github.com/FormidableLabs/urql/pull/1113))
- Refactor `useSource` hooks which powers `useQuery` and `useSubscription` to improve various edge case behaviour. This will not change the behaviour of these hooks dramatically but avoid unnecessary state updates when any updates are obviously equivalent and the hook will furthermore improve continuation from mount to effects, which will fix cases where the state between the mounting and effect phase may slightly change, by [@kitten](https://github.com/kitten) (See [#1104](https://github.com/FormidableLabs/urql/pull/1104))
## 1.14.1
### Patch Changes
- ⚠️ Fix the production build overwriting the development build. Specifically in the previous release we mistakenly replaced all development bundles with production bundles. This doesn't have any direct influence on how these packages work, but prevented development warnings from being logged or full errors from being thrown, by [@kitten](https://github.com/kitten) (See [#1097](https://github.com/FormidableLabs/urql/pull/1097))
## 1.14.0
This version of `@urql/core` renames `Operation.operationName` to `Operation.kind`. For now the old
property is merely deprecated and will issue a warning if it's used directly. That said, all
exchanges that are released today also need this new version of `@urql/core@>=1.14.0`, so if you
upgrade to any of the following packages, you will also need to upgrade `@urql/core`. If you upgrade
and see the deprecation warning, check whether all following exchanges have been upgraded:
- `@urql/exchange-auth@0.1.2`
- `@urql/exchange-execute@1.0.2`
- `@urql/exchange-graphcache@3.1.8`
- `@urql/exchange-multipart-fetch@0.1.10`
- `@urql/exchange-persisted-fetch@1.2.2`
- `@urql/exchange-populate@0.2.1`
- `@urql/exchange-refocus@0.2.1`
- `@urql/exchange-retry@0.1.9`
- `@urql/exchange-suspense@1.9.2`
Once you've upgraded `@urql/core` please also ensure that your package manager hasn't accidentally
duplicated the `@urql/core` package. If you're using `npm` you can do so by running `npm dedupe`,
and if you use `yarn` you can do so by running `yarn-deduplicate`.
If you have a custom exchange, you can mute the deprecation warning by using `Operation.kind` rather
than `Operation.operationName`. If these exchanges are copying or altering operations by spreading
them this will also trigger the warning, which you can fix by using [the new `makeOperation` helper
function.](https://formidable.com/open-source/urql/docs/api/core/#makeoperation)
### Minor Changes
- Deprecate the `Operation.operationName` property in favor of `Operation.kind`. This name was
previously confusing as `operationName` was effectively referring to two different things. You can
safely upgrade to this new version, however to mute all deprecation warnings you will have to
**upgrade** all `urql` packages you use. If you have custom exchanges that spread operations, please
use [the new `makeOperation` helper
function](https://formidable.com/open-source/urql/docs/api/core/#makeoperation) instead, by [@bkonkle](https://github.com/bkonkle) (See [#1045](https://github.com/FormidableLabs/urql/pull/1045))
### Patch Changes
- Add missing `.mjs` extension to all imports from `graphql` to fix Webpack 5 builds, which require extension-specific import paths for ESM bundles and packages. **This change allows you to safely upgrade to Webpack 5.**, by [@kitten](https://github.com/kitten) (See [#1094](https://github.com/FormidableLabs/urql/pull/1094))
## 1.13.1
### Patch Changes
- Allow `client.reexecuteOperation` to be called with mutations which skip the active operation minimums, by [@kitten](https://github.com/kitten) (See [#1011](https://github.com/FormidableLabs/urql/pull/1011))
## 1.13.0
Please note that this release changes the data structure of the `ssrExchange`'s
output. We don't treat this as a breaking change, since this data is considered
a private structure, but if your tests or other code relies on this, please check
the type changes and update it.
### Minor Changes
- Adds an error exchange to urql-core. This allows tapping into all graphql errors within the urql client. Useful for logging, debugging, handling authentication errors etc, by [@kadikraman](https://github.com/kadikraman) (See [#947](https://github.com/FormidableLabs/urql/pull/947))
### Patch Changes
- ⚠️ Fix condition where mutated result data would be picked up by the `ssrExchange`, for instance as a result of mutations by Graphcache. Instead the `ssrExchange` now serializes data early, by [@kitten](https://github.com/kitten) (See [#962](https://github.com/FormidableLabs/urql/pull/962))
- Omit the `Content-Type: application/json` HTTP header when using GET in the `fetchExchange`, `persistedFetchExchange`, or `multipartFetchExchange`, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#957](https://github.com/FormidableLabs/urql/pull/957))
## 1.12.3
### Patch Changes
- Remove whitespace and comments from string-queries, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#911](https://github.com/FormidableLabs/urql/pull/911))
- Remove redundant whitespaces when using GET for graphql queries, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#908](https://github.com/FormidableLabs/urql/pull/908))
## 1.12.2
### Patch Changes
- ⚠️ Fix `formatDocument` mutating parts of the `DocumentNode` which may be shared by other documents and queries. Also ensure that a formatted document will always generate the same key in `createRequest` as the original document, by [@kitten](https://github.com/kitten) (See [#880](https://github.com/FormidableLabs/urql/pull/880))
- ⚠️ Fix `ssrExchange` invalidating results on the client-side too eagerly, by delaying invalidation by a tick, by [@kitten](https://github.com/kitten) (See [#885](https://github.com/FormidableLabs/urql/pull/885))
## 1.12.1
### Patch Changes
- ⚠️ Fix timing for out-of-band `client.reexecuteOperation` calls. This would surface in asynchronous caching scenarios, where no result would be delivered by the cache synchronously, while it still calls `client.reexecuteOperation` for e.g. a `network-only` request, which happens for `cache-and-network`. This issue becomes especially obvious in highly synchronous frameworks like Svelte, by [@kitten](https://github.com/kitten) (See [#860](https://github.com/FormidableLabs/urql/pull/860))
- Replace unnecessary `scheduleTask` polyfill with inline `Promise.resolve().then(fn)` calls, by [@kitten](https://github.com/kitten) (See [#861](https://github.com/FormidableLabs/urql/pull/861))
## 1.12.0
As always, please ensure that you deduplicate `@urql/core` when upgrading. Additionally
deduplicating the versions of `wonka` that you have installed may also reduce your bundlesize.
### Minor Changes
- Expose a `client.subscription` shortcut method, similar to `client.query` and `client.mutation`, by [@FredyC](https://github.com/FredyC) (See [#838](https://github.com/FormidableLabs/urql/pull/838))
### Patch Changes
- Upgrade to a minimum version of wonka@^4.0.14 to work around issues with React Native's minification builds, which use uglify-es and could lead to broken bundles, by [@kitten](https://github.com/kitten) (See [#842](https://github.com/FormidableLabs/urql/pull/842))
## 1.11.8
### Patch Changes
- Add operationName to GET queries, by [@jakubriedl](https://github.com/jakubriedl) (See [#798](https://github.com/FormidableLabs/urql/pull/798))
## 1.11.7
### Patch Changes
- Add `source` debug name to all `dispatchDebug` calls during build time to identify events by which exchange dispatched them, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#780](https://github.com/FormidableLabs/urql/pull/780))
## 1.11.6
### Patch Changes
- Add a `"./package.json"` entry to the `package.json`'s `"exports"` field for Node 14. This seems to be required by packages like `rollup-plugin-svelte` to function properly, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#771](https://github.com/FormidableLabs/urql/pull/771))
## 1.11.5
### Patch Changes
- Hoist variables in unminified build output for Metro Bundler builds which otherwise fails for `process.env.NODE_ENV` if-clauses, by [@kitten](https://github.com/kitten) (See [#737](https://github.com/FormidableLabs/urql/pull/737))
- Add a babel-plugin that removes empty imports from the final build output, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#735](https://github.com/FormidableLabs/urql/pull/735))
## 1.11.4
### Patch Changes
Sorry for the many updates; Please only upgrade to `>=1.11.4` and don't use the deprecated `1.11.3`
and `1.11.2` release.
- ⚠️ Fix nested package path for @urql/core/internal and @urql/exchange-graphcache/extras, by [@kitten](https://github.com/kitten) (See [#734](https://github.com/FormidableLabs/urql/pull/734))
## 1.11.3
### Patch Changes
- Make the extension of the main export unknown, which fixes a Webpack issue where the resolver won't pick `module` fields in `package.json` files once it's importing from another `.mjs` file, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#733](https://github.com/FormidableLabs/urql/pull/733))
## 1.11.1
### Patch Changes
- ⚠️ Fix missing `@urql/core/internal` entrypoint in the npm-release, which was previously not included, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#731](https://github.com/FormidableLabs/urql/pull/731))
## 1.11.0
### Minor Changes
- Add debugging events to exchanges that add more detailed information on what is happening
internally, which will be displayed by devtools like the urql [Chrome / Firefox extension](https://github.com/FormidableLabs/urql-devtools), by [@andyrichardson](https://github.com/andyrichardson) (See [#608](https://github.com/FormidableLabs/urql/pull/608))
- Add @urql/core/internal entrypoint for internally shared utilities and start sharing fetchExchange-related code, by [@kitten](https://github.com/kitten) (See [#722](https://github.com/FormidableLabs/urql/pull/722))
### Patch Changes
- ⚠️ Fix stringifyVariables breaking on x.toJSON scalars, by [@kitten](https://github.com/kitten) (See [#718](https://github.com/FormidableLabs/urql/pull/718))
## 1.10.9
### Patch Changes
- Pick modules from graphql package, instead of importing from graphql/index.mjs, by [@kitten](https://github.com/kitten) (See [#700](https://github.com/FormidableLabs/urql/pull/700))
## 1.10.8
### Patch Changes
- Add graphql@^15.0.0 to peer dependency range, by [@kitten](https://github.com/kitten) (See [#688](https://github.com/FormidableLabs/urql/pull/688))
- ⚠️ Fix non-2xx results never being parsed as GraphQL results. This can result in valid GraphQLErrors being hidden, which should take precedence over generic HTTP NetworkErrors, by [@kitten](https://github.com/kitten) (See [#678](https://github.com/FormidableLabs/urql/pull/678))
## 1.10.7
### Patch Changes
- ⚠️ Fix oversight in edge case for #662. The operation queue wasn't marked as being active which caused `stale` results and `cache-and-network` operations from reissuing operations immediately (unqueued essentially) which would then be filtered out by the `dedupExchange`, by [@kitten](https://github.com/kitten) (See [#669](https://github.com/FormidableLabs/urql/pull/669))
## 1.10.6
### Patch Changes
- ⚠️ Fix critical bug in operation queueing that can lead to unexpected teardowns and swallowed operations. This would happen when a teardown operation kicks off the queue, by [@kitten](https://github.com/kitten) (See [#662](https://github.com/FormidableLabs/urql/pull/662))
## 1.10.5
### Patch Changes
- Refactor a couple of core helpers for minor bundlesize savings, by [@kitten](https://github.com/kitten) (See [#658](https://github.com/FormidableLabs/urql/pull/658))
- Add support for variables that contain non-plain objects without any enumerable keys, e.g. `File` or `Blob`. In this case `stringifyVariables` will now use a stable (but random) key, which means that mutations containing `File`s — or other objects like this — will now be distinct, as they should be, by [@kitten](https://github.com/kitten) (See [#650](https://github.com/FormidableLabs/urql/pull/650))
## 1.10.4
### Patch Changes
- ⚠️ Fix node resolution when using Webpack, which experiences a bug where it only resolves
`package.json:main` instead of `module` when an `.mjs` file imports a package, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#642](https://github.com/FormidableLabs/urql/pull/642))
## 1.10.3
### Patch Changes
- ⚠️ Fix Node.js Module support for v13 (experimental-modules) and v14. If your bundler doesn't support
`.mjs` files and fails to resolve the new version, please double check your configuration for
Webpack, or similar tools, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#637](https://github.com/FormidableLabs/urql/pull/637))
## 1.10.2
### Patch Changes
- Add a guard to "maskTypenames" so a null value isn't considered an object, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#621](https://github.com/FormidableLabs/urql/pull/621))
## 1.10.1
### Patch Changes
- ⚠️ Fix Rollup bundle output being written to .es.js instead of .esm.js, by [@kitten](https://github.com/kitten) (See [#609](https://github.com/FormidableLabs/urql/pull/609))
## 1.10.0
### Minor Changes
- Add `additionalTypenames` to the `OperationContext`, which allows the document cache to invalidate efficiently when the `__typename` is unknown at the initial fetch, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#601](https://github.com/FormidableLabs/urql/pull/601)) [You can learn more about this change in our docs.](https://formidable.com/open-source/urql/docs/basics/document-caching/#adding-typenames)
### Patch Changes
- Add missing GraphQLError serialization for extensions and path field to ssrExchange, by [@kitten](https://github.com/kitten) (See [#607](https://github.com/FormidableLabs/urql/pull/607))
## 1.9.2
### Patch Changes
- Prevent active teardowns for queries on subscriptionExchange, by [@kitten](https://github.com/kitten) (See [#577](https://github.com/FormidableLabs/urql/pull/577))
## 1.9.1
### Patch Changes
- ⚠️ Fix `cache-only` operations being forwarded and triggering fetch requests, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#551](https://github.com/FormidableLabs/urql/pull/551))
- Adds a one-tick delay to the subscriptionExchange to prevent unnecessary early tear downs, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#542](https://github.com/FormidableLabs/urql/pull/542))
- Add enableAllOperations option to subscriptionExchange to let it handle queries and mutations as well, by [@kitten](https://github.com/kitten) (See [#544](https://github.com/FormidableLabs/urql/pull/544))
## 1.9.0
### Minor Changes
- Adds the `maskTypename` export to urql-core, this deeply masks typenames from the given payload.
Masking `__typename` properties is also available as a `maskTypename` option on the `Client`. Setting this to true will
strip typenames from results, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#533](https://github.com/FormidableLabs/urql/pull/533))
- Add support for sending queries using GET instead of POST method (See [#519](https://github.com/FormidableLabs/urql/pull/519))
- Add client.readQuery method (See [#518](https://github.com/FormidableLabs/urql/pull/518))
### Patch Changes
- ⚠️ Fix ssrExchange not serialising networkError on CombinedErrors correctly. (See [#515](https://github.com/FormidableLabs/urql/pull/515))
- Add explicit error when creating Client without a URL in development. (See [#512](https://github.com/FormidableLabs/urql/pull/512))

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 20182020 Formidable
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,5 @@
# @urql/core
> The shared core for the highly customizable and versatile GraphQL client, urql
More documentation is available at [formidable.com/open-source/urql](https://formidable.com/open-source/urql/).

View File

@@ -0,0 +1,432 @@
import { GraphQLError as e } from "graphql/error/GraphQLError.mjs";
import { Kind as r } from "graphql/language/kinds.mjs";
import { parse as t } from "graphql/language/parser.mjs";
import { print as n } from "graphql/language/printer.mjs";
import { make as o } from "wonka";
function rehydrateGraphQlError(r) {
if ("string" == typeof r) {
return new e(r);
} else if ("object" == typeof r && r.message) {
return new e(r.message, r.nodes, r.source, r.positions, r.path, r, r.extensions || {});
} else {
return r;
}
}
var a = function(e) {
function CombinedError(r) {
var t = r.networkError;
var n = r.response;
var o = (r.graphQLErrors || []).map(rehydrateGraphQlError);
var a = function generateErrorMessage(e, r) {
var t = "";
if (void 0 !== e) {
return t = "[Network] " + e.message;
}
if (void 0 !== r) {
r.forEach((function(e) {
t += "[GraphQL] " + e.message + "\n";
}));
}
return t.trim();
}(t, o);
e.call(this, a);
this.name = "CombinedError";
this.message = a;
this.graphQLErrors = o;
this.networkError = t;
this.response = n;
}
if (e) {
CombinedError.__proto__ = e;
}
(CombinedError.prototype = Object.create(e && e.prototype)).constructor = CombinedError;
CombinedError.prototype.toString = function toString() {
return this.message;
};
return CombinedError;
}(Error);
function phash(e, r) {
e |= 0;
for (var t = 0, n = 0 | r.length; t < n; t++) {
e = (e << 5) + e + r.charCodeAt(t);
}
return e;
}
function hash(e) {
return phash(5381, e) >>> 0;
}
var i = new Set;
var s = new WeakMap;
function stringify(e) {
if (null === e || i.has(e)) {
return "null";
} else if ("object" != typeof e) {
return JSON.stringify(e) || "";
} else if (e.toJSON) {
return stringify(e.toJSON());
} else if (Array.isArray(e)) {
var r = "[";
for (var t = 0, n = e.length; t < n; t++) {
if (t > 0) {
r += ",";
}
var o = stringify(e[t]);
r += o.length > 0 ? o : "null";
}
return r += "]";
}
var a = Object.keys(e).sort();
if (!a.length && e.constructor && e.constructor !== Object) {
var u = s.get(e) || Math.random().toString(36).slice(2);
s.set(e, u);
return '{"__key":"' + u + '"}';
}
i.add(e);
var f = "{";
for (var c = 0, l = a.length; c < l; c++) {
var h = a[c];
var p = stringify(e[h]);
if (p) {
if (f.length > 1) {
f += ",";
}
f += stringify(h) + ":" + p;
}
}
i.delete(e);
return f += "}";
}
function stringifyVariables(e) {
i.clear();
return stringify(e);
}
function stringifyDocument(e) {
var r = ("string" != typeof e ? e.loc && e.loc.source.body || n(e) : e).replace(/([\s,]|#[^\n\r]+)+/g, " ").trim();
if ("string" != typeof e) {
var t = "definitions" in e && getOperationName(e);
if (t) {
r = "# " + t + "\n" + r;
}
if (!e.loc) {
e.loc = {
start: 0,
end: r.length,
source: {
body: r,
name: "gql",
locationOffset: {
line: 1,
column: 1
}
}
};
}
}
return r;
}
var u = new Map;
function keyDocument(e) {
var r;
var n;
if ("string" == typeof e) {
r = hash(stringifyDocument(e));
n = u.get(r) || t(e, {
noLocation: !0
});
} else {
r = e.__key || hash(stringifyDocument(e));
n = u.get(r) || e;
}
if (!n.loc) {
stringifyDocument(n);
}
n.__key = r;
u.set(r, n);
return n;
}
function createRequest(e, r) {
if (!r) {
r = {};
}
var t = keyDocument(e);
return {
key: phash(t.__key, stringifyVariables(r)) >>> 0,
query: t,
variables: r
};
}
function getOperationName(e) {
for (var t = 0, n = e.definitions.length; t < n; t++) {
var o = e.definitions[t];
if (o.kind === r.OPERATION_DEFINITION && o.name) {
return o.name.value;
}
}
}
function getOperationType(e) {
for (var t = 0, n = e.definitions.length; t < n; t++) {
var o = e.definitions[t];
if (o.kind === r.OPERATION_DEFINITION) {
return o.operation;
}
}
}
function _extends() {
return (_extends = Object.assign || function(e) {
for (var r = 1; r < arguments.length; r++) {
var t = arguments[r];
for (var n in t) {
if (Object.prototype.hasOwnProperty.call(t, n)) {
e[n] = t[n];
}
}
}
return e;
}).apply(this, arguments);
}
function makeResult(e, r, t) {
if (!("data" in r) && !("errors" in r) || "path" in r) {
throw new Error("No Content");
}
return {
operation: e,
data: r.data,
error: Array.isArray(r.errors) ? new a({
graphQLErrors: r.errors,
response: t
}) : void 0,
extensions: "object" == typeof r.extensions && r.extensions || void 0,
hasNext: !!r.hasNext
};
}
function mergeResultPatch(e, r, t) {
var n = _extends({}, e);
n.hasNext = !!r.hasNext;
if (!("path" in r)) {
if ("data" in r) {
n.data = r.data;
}
return n;
}
if (Array.isArray(r.errors)) {
n.error = new a({
graphQLErrors: n.error ? n.error.graphQLErrors.concat(r.errors) : r.errors,
response: t
});
}
var o = n.data = _extends({}, n.data);
var i = 0;
var s;
while (i < r.path.length) {
o = o[s = r.path[i++]] = Array.isArray(o[s]) ? [].concat(o[s]) : _extends({}, o[s]);
}
_extends(o, r.data);
return n;
}
function makeErrorResult(e, r, t) {
return {
operation: e,
data: void 0,
error: new a({
networkError: r,
response: t
}),
extensions: void 0
};
}
function shouldUseGet(e) {
return "query" === e.kind && !!e.context.preferGetMethod;
}
function makeFetchBody(e) {
return {
query: n(e.query),
operationName: getOperationName(e.query),
variables: e.variables || void 0,
extensions: void 0
};
}
function makeFetchURL(e, r) {
var t = shouldUseGet(e);
var n = e.context.url;
if (!t || !r) {
return n;
}
var o = [];
if (r.operationName) {
o.push("operationName=" + encodeURIComponent(r.operationName));
}
if (r.query) {
o.push("query=" + encodeURIComponent(r.query.replace(/#[^\n\r]+/g, " ").trim()));
}
if (r.variables) {
o.push("variables=" + encodeURIComponent(stringifyVariables(r.variables)));
}
if (r.extensions) {
o.push("extensions=" + encodeURIComponent(stringifyVariables(r.extensions)));
}
return n + "?" + o.join("&");
}
function makeFetchOptions(e, r) {
var t = shouldUseGet(e);
var n = "function" == typeof e.context.fetchOptions ? e.context.fetchOptions() : e.context.fetchOptions || {};
return _extends({}, n, {
body: !t && r ? JSON.stringify(r) : void 0,
method: t ? "GET" : "POST",
headers: t ? n.headers : _extends({}, {
"content-type": "application/json"
}, n.headers)
});
}
var f = "undefined" != typeof Symbol ? Symbol.asyncIterator : null;
var c = "undefined" != typeof TextDecoder ? new TextDecoder : null;
var l = /content-type:[^\r\n]*application\/json/i;
var h = /boundary="?([^=";]+)"?/i;
function executeIncrementalFetch(e, r, t) {
var n = t.headers && t.headers.get("Content-Type") || "";
if (!/multipart\/mixed/i.test(n)) {
return t.json().then((function(n) {
e(makeResult(r, n, t));
}));
}
var o = "---";
var a = n.match(h);
if (a) {
o = "--" + a[1];
}
var i;
var cancel = function() {};
if (f && t[f]) {
var s = t[f]();
i = s.next.bind(s);
} else if ("body" in t && t.body) {
var u = t.body.getReader();
cancel = u.cancel.bind(u);
i = u.read.bind(u);
} else {
throw new TypeError("Streaming requests unsupported");
}
var p = "";
var d = !0;
var m = null;
var v = null;
return i().then((function next(n) {
if (!n.done) {
var a = function toString(e) {
return "Buffer" === e.constructor.name ? e.toString() : c.decode(e);
}(n.value);
var s = a.indexOf(o);
if (s > -1) {
s += p.length;
} else {
s = p.indexOf(o);
}
p += a;
while (s > -1) {
var u = p.slice(0, s);
var f = p.slice(s + o.length);
if (d) {
d = !1;
} else {
var h = u.indexOf("\r\n\r\n") + 4;
var g = u.slice(0, h);
var y = u.slice(h, u.lastIndexOf("\r\n"));
var x = void 0;
if (l.test(g)) {
try {
x = JSON.parse(y);
m = v = v ? mergeResultPatch(v, x, t) : makeResult(r, x, t);
} catch (e) {}
}
if ("--" === f.slice(0, 2) || x && !x.hasNext) {
if (!v) {
return e(makeResult(r, {}, t));
}
break;
}
}
s = (p = f).indexOf(o);
}
}
if (m) {
e(m);
m = null;
}
if (!n.done && (!v || v.hasNext)) {
return i().then(next);
}
})).finally(cancel);
}
function makeFetchSource(e, r, t) {
var n = "manual" === t.redirect ? 400 : 300;
var a = e.context.fetch;
return o((function(o) {
var i = o.next;
var s = o.complete;
var u = "undefined" != typeof AbortController ? new AbortController : null;
if (u) {
t.signal = u.signal;
}
var f = !1;
var c = !1;
var l;
Promise.resolve().then((function() {
if (f) {
return;
}
return (a || fetch)(r, t);
})).then((function(r) {
if (!r) {
return;
}
c = (l = r).status < 200 || l.status >= n;
return executeIncrementalFetch(i, e, l);
})).then(s).catch((function(r) {
if ("AbortError" !== r.name) {
var t = makeErrorResult(e, c ? new Error(l.statusText) : r, l);
i(t);
s();
}
}));
return function() {
f = !0;
if (u) {
u.abort();
}
};
}));
}
export { a as C, _extends as _, makeErrorResult as a, makeFetchBody as b, makeFetchURL as c, makeFetchOptions as d, makeFetchSource as e, createRequest as f, getOperationType as g, stringifyVariables as h, mergeResultPatch as i, getOperationName as j, keyDocument as k, makeResult as m, stringifyDocument as s };
//# sourceMappingURL=01e1547d.mjs.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,442 @@
var e = require("graphql");
var r = require("wonka");
function rehydrateGraphQlError(r) {
if ("string" == typeof r) {
return new e.GraphQLError(r);
} else if ("object" == typeof r && r.message) {
return new e.GraphQLError(r.message, r.nodes, r.source, r.positions, r.path, r, r.extensions || {});
} else {
return r;
}
}
var t = function(e) {
function CombinedError(r) {
var t = r.networkError;
var n = r.response;
var o = (r.graphQLErrors || []).map(rehydrateGraphQlError);
var a = function generateErrorMessage(e, r) {
var t = "";
if (void 0 !== e) {
return t = "[Network] " + e.message;
}
if (void 0 !== r) {
r.forEach((function(e) {
t += "[GraphQL] " + e.message + "\n";
}));
}
return t.trim();
}(t, o);
e.call(this, a);
this.name = "CombinedError";
this.message = a;
this.graphQLErrors = o;
this.networkError = t;
this.response = n;
}
if (e) {
CombinedError.__proto__ = e;
}
(CombinedError.prototype = Object.create(e && e.prototype)).constructor = CombinedError;
CombinedError.prototype.toString = function toString() {
return this.message;
};
return CombinedError;
}(Error);
function phash(e, r) {
e |= 0;
for (var t = 0, n = 0 | r.length; t < n; t++) {
e = (e << 5) + e + r.charCodeAt(t);
}
return e;
}
function hash(e) {
return phash(5381, e) >>> 0;
}
var n = new Set;
var o = new WeakMap;
function stringify(e) {
if (null === e || n.has(e)) {
return "null";
} else if ("object" != typeof e) {
return JSON.stringify(e) || "";
} else if (e.toJSON) {
return stringify(e.toJSON());
} else if (Array.isArray(e)) {
var r = "[";
for (var t = 0, a = e.length; t < a; t++) {
if (t > 0) {
r += ",";
}
var i = stringify(e[t]);
r += i.length > 0 ? i : "null";
}
return r += "]";
}
var s = Object.keys(e).sort();
if (!s.length && e.constructor && e.constructor !== Object) {
var u = o.get(e) || Math.random().toString(36).slice(2);
o.set(e, u);
return '{"__key":"' + u + '"}';
}
n.add(e);
var f = "{";
for (var c = 0, l = s.length; c < l; c++) {
var p = s[c];
var h = stringify(e[p]);
if (h) {
if (f.length > 1) {
f += ",";
}
f += stringify(p) + ":" + h;
}
}
n.delete(e);
return f += "}";
}
function stringifyVariables(e) {
n.clear();
return stringify(e);
}
function stringifyDocument(r) {
var t = ("string" != typeof r ? r.loc && r.loc.source.body || e.print(r) : r).replace(/([\s,]|#[^\n\r]+)+/g, " ").trim();
if ("string" != typeof r) {
var n = "definitions" in r && getOperationName(r);
if (n) {
t = "# " + n + "\n" + t;
}
if (!r.loc) {
r.loc = {
start: 0,
end: t.length,
source: {
body: t,
name: "gql",
locationOffset: {
line: 1,
column: 1
}
}
};
}
}
return t;
}
var a = new Map;
function keyDocument(r) {
var t;
var n;
if ("string" == typeof r) {
t = hash(stringifyDocument(r));
n = a.get(t) || e.parse(r, {
noLocation: !0
});
} else {
t = r.__key || hash(stringifyDocument(r));
n = a.get(t) || r;
}
if (!n.loc) {
stringifyDocument(n);
}
n.__key = t;
a.set(t, n);
return n;
}
function getOperationName(r) {
for (var t = 0, n = r.definitions.length; t < n; t++) {
var o = r.definitions[t];
if (o.kind === e.Kind.OPERATION_DEFINITION && o.name) {
return o.name.value;
}
}
}
function _extends() {
return (_extends = Object.assign || function(e) {
for (var r = 1; r < arguments.length; r++) {
var t = arguments[r];
for (var n in t) {
if (Object.prototype.hasOwnProperty.call(t, n)) {
e[n] = t[n];
}
}
}
return e;
}).apply(this, arguments);
}
function makeResult(e, r, n) {
if (!("data" in r) && !("errors" in r) || "path" in r) {
throw new Error("No Content");
}
return {
operation: e,
data: r.data,
error: Array.isArray(r.errors) ? new t({
graphQLErrors: r.errors,
response: n
}) : void 0,
extensions: "object" == typeof r.extensions && r.extensions || void 0,
hasNext: !!r.hasNext
};
}
function mergeResultPatch(e, r, n) {
var o = _extends({}, e);
o.hasNext = !!r.hasNext;
if (!("path" in r)) {
if ("data" in r) {
o.data = r.data;
}
return o;
}
if (Array.isArray(r.errors)) {
o.error = new t({
graphQLErrors: o.error ? o.error.graphQLErrors.concat(r.errors) : r.errors,
response: n
});
}
var a = o.data = _extends({}, o.data);
var i = 0;
var s;
while (i < r.path.length) {
a = a[s = r.path[i++]] = Array.isArray(a[s]) ? [].concat(a[s]) : _extends({}, a[s]);
}
_extends(a, r.data);
return o;
}
function makeErrorResult(e, r, n) {
return {
operation: e,
data: void 0,
error: new t({
networkError: r,
response: n
}),
extensions: void 0
};
}
function shouldUseGet(e) {
return "query" === e.kind && !!e.context.preferGetMethod;
}
var i = "undefined" != typeof Symbol ? Symbol.asyncIterator : null;
var s = "undefined" != typeof TextDecoder ? new TextDecoder : null;
var u = /content-type:[^\r\n]*application\/json/i;
var f = /boundary="?([^=";]+)"?/i;
function executeIncrementalFetch(e, r, t) {
var n = t.headers && t.headers.get("Content-Type") || "";
if (!/multipart\/mixed/i.test(n)) {
return t.json().then((function(n) {
e(makeResult(r, n, t));
}));
}
var o = "---";
var a = n.match(f);
if (a) {
o = "--" + a[1];
}
var c;
var cancel = function() {};
if (i && t[i]) {
var l = t[i]();
c = l.next.bind(l);
} else if ("body" in t && t.body) {
var p = t.body.getReader();
cancel = p.cancel.bind(p);
c = p.read.bind(p);
} else {
throw new TypeError("Streaming requests unsupported");
}
var h = "";
var d = !0;
var v = null;
var y = null;
return c().then((function next(n) {
if (!n.done) {
var a = function toString(e) {
return "Buffer" === e.constructor.name ? e.toString() : s.decode(e);
}(n.value);
var i = a.indexOf(o);
if (i > -1) {
i += h.length;
} else {
i = h.indexOf(o);
}
h += a;
while (i > -1) {
var f = h.slice(0, i);
var l = h.slice(i + o.length);
if (d) {
d = !1;
} else {
var p = f.indexOf("\r\n\r\n") + 4;
var m = f.slice(0, p);
var g = f.slice(p, f.lastIndexOf("\r\n"));
var x = void 0;
if (u.test(m)) {
try {
x = JSON.parse(g);
v = y = y ? mergeResultPatch(y, x, t) : makeResult(r, x, t);
} catch (e) {}
}
if ("--" === l.slice(0, 2) || x && !x.hasNext) {
if (!y) {
return e(makeResult(r, {}, t));
}
break;
}
}
i = (h = l).indexOf(o);
}
}
if (v) {
e(v);
v = null;
}
if (!n.done && (!y || y.hasNext)) {
return c().then(next);
}
})).finally(cancel);
}
exports.CombinedError = t;
exports._extends = _extends;
exports.createRequest = function createRequest(e, r) {
if (!r) {
r = {};
}
var t = keyDocument(e);
return {
key: phash(t.__key, stringifyVariables(r)) >>> 0,
query: t,
variables: r
};
};
exports.getOperationName = getOperationName;
exports.getOperationType = function getOperationType(r) {
for (var t = 0, n = r.definitions.length; t < n; t++) {
var o = r.definitions[t];
if (o.kind === e.Kind.OPERATION_DEFINITION) {
return o.operation;
}
}
};
exports.keyDocument = keyDocument;
exports.makeErrorResult = makeErrorResult;
exports.makeFetchBody = function makeFetchBody(r) {
return {
query: e.print(r.query),
operationName: getOperationName(r.query),
variables: r.variables || void 0,
extensions: void 0
};
};
exports.makeFetchOptions = function makeFetchOptions(e, r) {
var t = shouldUseGet(e);
var n = "function" == typeof e.context.fetchOptions ? e.context.fetchOptions() : e.context.fetchOptions || {};
return _extends({}, n, {
body: !t && r ? JSON.stringify(r) : void 0,
method: t ? "GET" : "POST",
headers: t ? n.headers : _extends({}, {
"content-type": "application/json"
}, n.headers)
});
};
exports.makeFetchSource = function makeFetchSource(e, t, n) {
var o = "manual" === n.redirect ? 400 : 300;
var a = e.context.fetch;
return r.make((function(r) {
var i = r.next;
var s = r.complete;
var u = "undefined" != typeof AbortController ? new AbortController : null;
if (u) {
n.signal = u.signal;
}
var f = !1;
var c = !1;
var l;
Promise.resolve().then((function() {
if (f) {
return;
}
return (a || fetch)(t, n);
})).then((function(r) {
if (!r) {
return;
}
c = (l = r).status < 200 || l.status >= o;
return executeIncrementalFetch(i, e, l);
})).then(s).catch((function(r) {
if ("AbortError" !== r.name) {
var t = makeErrorResult(e, c ? new Error(l.statusText) : r, l);
i(t);
s();
}
}));
return function() {
f = !0;
if (u) {
u.abort();
}
};
}));
};
exports.makeFetchURL = function makeFetchURL(e, r) {
var t = shouldUseGet(e);
var n = e.context.url;
if (!t || !r) {
return n;
}
var o = [];
if (r.operationName) {
o.push("operationName=" + encodeURIComponent(r.operationName));
}
if (r.query) {
o.push("query=" + encodeURIComponent(r.query.replace(/#[^\n\r]+/g, " ").trim()));
}
if (r.variables) {
o.push("variables=" + encodeURIComponent(stringifyVariables(r.variables)));
}
if (r.extensions) {
o.push("extensions=" + encodeURIComponent(stringifyVariables(r.extensions)));
}
return n + "?" + o.join("&");
};
exports.makeResult = makeResult;
exports.mergeResultPatch = mergeResultPatch;
exports.stringifyDocument = stringifyDocument;
exports.stringifyVariables = stringifyVariables;
//# sourceMappingURL=878a8849.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,51 @@
import { Source, Subscription } from 'wonka';
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
import { DocumentNode } from 'graphql';
import { Exchange, GraphQLRequest, Operation, OperationContext, OperationResult, OperationType, RequestPolicy, PromisifiedSource, DebugEvent } from './types';
/** Options for configuring the URQL [client]{@link Client}. */
export interface ClientOptions {
/** Target endpoint URL such as `https://my-target:8080/graphql`. */
url: string;
/** Any additional options to pass to fetch. */
fetchOptions?: RequestInit | (() => RequestInit);
/** An alternative fetch implementation. */
fetch?: typeof fetch;
/** An ordered array of Exchanges. */
exchanges?: Exchange[];
/** Activates support for Suspense. */
suspense?: boolean;
/** The default request policy for requests. */
requestPolicy?: RequestPolicy;
/** Use HTTP GET for queries. */
preferGetMethod?: boolean;
/** Mask __typename from results. */
maskTypename?: boolean;
}
export interface Client {
new (options: ClientOptions): Client;
operations$: Source<Operation>;
/** Start an operation from an exchange */
reexecuteOperation: (operation: Operation) => void;
/** Event target for monitoring, e.g. for @urql/devtools */
subscribeToDebugTarget?: (onEvent: (e: DebugEvent) => void) => Subscription;
url: string;
fetch?: typeof fetch;
fetchOptions?: RequestInit | (() => RequestInit);
suspense: boolean;
requestPolicy: RequestPolicy;
preferGetMethod: boolean;
maskTypename: boolean;
createOperationContext(opts?: Partial<OperationContext> | undefined): OperationContext;
createRequestOperation<Data = any, Variables = object>(kind: OperationType, request: GraphQLRequest<Data, Variables>, opts?: Partial<OperationContext> | undefined): Operation<Data, Variables>;
/** Executes an Operation by sending it through the exchange pipeline It returns an observable that emits all related exchange results and keeps track of this observable's subscribers. A teardown signal will be emitted when no subscribers are listening anymore. */
executeRequestOperation<Data = any, Variables = object>(operation: Operation<Data, Variables>): Source<OperationResult<Data, Variables>>;
query<Data = any, Variables extends object = {}>(query: DocumentNode | TypedDocumentNode<Data, Variables> | string, variables?: Variables, context?: Partial<OperationContext>): PromisifiedSource<OperationResult<Data, Variables>>;
readQuery<Data = any, Variables extends object = {}>(query: DocumentNode | TypedDocumentNode<Data, Variables> | string, variables?: Variables, context?: Partial<OperationContext>): OperationResult<Data, Variables> | null;
executeQuery<Data = any, Variables = object>(query: GraphQLRequest<Data, Variables>, opts?: Partial<OperationContext> | undefined): Source<OperationResult<Data, Variables>>;
subscription<Data = any, Variables extends object = {}>(query: DocumentNode | TypedDocumentNode<Data, Variables> | string, variables?: Variables, context?: Partial<OperationContext>): Source<OperationResult<Data, Variables>>;
executeSubscription<Data = any, Variables = object>(query: GraphQLRequest<Data, Variables>, opts?: Partial<OperationContext> | undefined): Source<OperationResult<Data, Variables>>;
mutation<Data = any, Variables extends object = {}>(query: DocumentNode | TypedDocumentNode<Data, Variables> | string, variables?: Variables, context?: Partial<OperationContext>): PromisifiedSource<OperationResult<Data, Variables>>;
executeMutation<Data = any, Variables = object>(query: GraphQLRequest<Data, Variables>, opts?: Partial<OperationContext> | undefined): Source<OperationResult<Data, Variables>>;
}
export declare const Client: new (opts: ClientOptions) => Client;
export declare const createClient: (opts: ClientOptions) => Client;

View File

@@ -0,0 +1,4 @@
import { Client } from '../client';
import { Exchange, Operation } from '../types';
export declare const cacheExchange: Exchange;
export declare const reexecuteOperation: (client: Client, operation: Operation) => void;

View File

@@ -0,0 +1,3 @@
import { Exchange, ExchangeInput } from '../types';
/** This composes an array of Exchanges into a single ExchangeIO function */
export declare const composeExchanges: (exchanges: Exchange[]) => ({ client, forward, dispatchDebug, }: ExchangeInput) => import("../types").ExchangeIO;

View File

@@ -0,0 +1,2 @@
import { Exchange } from '../types';
export declare const debugExchange: Exchange;

View File

@@ -0,0 +1,3 @@
import { Exchange } from '../types';
/** A default exchange for debouncing GraphQL requests. */
export declare const dedupExchange: Exchange;

View File

@@ -0,0 +1,5 @@
import { Exchange, Operation } from '../types';
import { CombinedError } from '../utils';
export declare const errorExchange: ({ onError, }: {
onError: (error: CombinedError, operation: Operation) => void;
}) => Exchange;

View File

@@ -0,0 +1,4 @@
import { ExchangeIO, ExchangeInput } from '../types';
/** This is always the last exchange in the chain; No operation should ever reach it */
export declare const fallbackExchange: ({ dispatchDebug, }: Pick<ExchangeInput, 'dispatchDebug'>) => ExchangeIO;
export declare const fallbackExchangeIO: ExchangeIO;

View File

@@ -0,0 +1,3 @@
import { Exchange } from '../types';
/** A default exchange for fetching GraphQL requests. */
export declare const fetchExchange: Exchange;

View File

@@ -0,0 +1,10 @@
export { ssrExchange } from './ssr';
export { cacheExchange } from './cache';
export { subscriptionExchange } from './subscription';
export { debugExchange } from './debug';
export { dedupExchange } from './dedup';
export { fetchExchange } from './fetch';
export { fallbackExchangeIO } from './fallback';
export { composeExchanges } from './compose';
export { errorExchange } from './error';
export declare const defaultExchanges: import("..").Exchange[];

View File

@@ -0,0 +1,28 @@
import { GraphQLError } from 'graphql';
import { Exchange } from '../types';
export interface SerializedResult {
hasNext?: boolean;
data?: string | undefined;
extensions?: string | undefined;
error?: {
graphQLErrors: Array<Partial<GraphQLError> | string>;
networkError?: string;
};
}
export interface SSRData {
[key: string]: SerializedResult;
}
export interface SSRExchangeParams {
isClient?: boolean;
initialState?: SSRData;
staleWhileRevalidate?: boolean;
includeExtensions?: boolean;
}
export interface SSRExchange extends Exchange {
/** Rehydrates cached data */
restoreData(data: SSRData): void;
/** Extracts cached data */
extractData(): SSRData;
}
/** The ssrExchange can be created to capture data during SSR and also to rehydrate it on the client */
export declare const ssrExchange: (params?: SSRExchangeParams | undefined) => SSRExchange;

View File

@@ -0,0 +1,26 @@
import { Exchange, ExecutionResult, OperationContext } from '../types';
export interface ObserverLike<T> {
next: (value: T) => void;
error: (err: any) => void;
complete: () => void;
}
/** An abstract observable interface conforming to: https://github.com/tc39/proposal-observable */
export interface ObservableLike<T> {
subscribe(observer: ObserverLike<T>): {
unsubscribe: () => void;
};
}
export interface SubscriptionOperation {
query: string;
variables?: Record<string, unknown>;
key: string;
context: OperationContext;
}
export declare type SubscriptionForwarder = (operation: SubscriptionOperation) => ObservableLike<ExecutionResult>;
/** This is called to create a subscription and needs to be hooked up to a transport client. */
export interface SubscriptionExchangeOpts {
forwardSubscription: SubscriptionForwarder;
/** This flag may be turned on to allow your subscriptions-transport to handle all operation types */
enableAllOperations?: boolean;
}
export declare const subscriptionExchange: ({ forwardSubscription, enableAllOperations, }: SubscriptionExchangeOpts) => Exchange;

View File

@@ -0,0 +1,5 @@
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
import { DocumentNode } from 'graphql';
declare function gql<Data = any, Variables = object>(strings: TemplateStringsArray, ...interpolations: Array<TypedDocumentNode | DocumentNode | string>): TypedDocumentNode<Data, Variables>;
declare function gql<Data = any, Variables = object>(string: string): TypedDocumentNode<Data, Variables>;
export { gql };

View File

@@ -0,0 +1,6 @@
export { TypedDocumentNode } from '@graphql-typed-document-node/core';
export { gql } from './gql';
export * from './client';
export * from './exchanges';
export * from './types';
export { CombinedError, stringifyVariables, createRequest, makeResult, makeErrorResult, mergeResultPatch, formatDocument, maskTypename, makeOperation, getOperationName, } from './utils';

View File

@@ -0,0 +1,14 @@
import { DocumentNode } from 'graphql';
import { Operation } from '../types';
export interface FetchBody {
query?: string;
operationName: string | undefined;
variables: undefined | Record<string, any>;
extensions: undefined | Record<string, any>;
}
export declare const makeFetchBody: (request: {
query: DocumentNode;
variables?: object;
}) => FetchBody;
export declare const makeFetchURL: (operation: Operation, body?: FetchBody | undefined) => string;
export declare const makeFetchOptions: (operation: Operation, body?: FetchBody | undefined) => RequestInit;

View File

@@ -0,0 +1,3 @@
import { Source } from 'wonka';
import { Operation, OperationResult } from '../types';
export declare const makeFetchSource: (operation: Operation, url: string, fetchOptions: RequestInit) => Source<OperationResult>;

View File

@@ -0,0 +1,2 @@
export * from './fetchOptions';
export * from './fetchSource';

View File

@@ -0,0 +1,121 @@
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
import { GraphQLError, DocumentNode } from 'graphql';
import { Source } from 'wonka';
import { Client } from './client';
import { CombinedError } from './utils/error';
export declare type ExecutionResult = {
errors?: Array<Partial<GraphQLError> | string | Error> | readonly GraphQLError[];
data?: null | Record<string, any>;
extensions?: Record<string, any>;
hasNext?: boolean;
} | {
errors?: Array<Partial<GraphQLError> | string | Error> | readonly GraphQLError[];
data: any;
path: (string | number)[];
hasNext?: boolean;
};
export declare type PromisifiedSource<T = any> = Source<T> & {
toPromise: () => Promise<T>;
};
/** The type of GraphQL operation being executed. */
export declare type OperationType = 'subscription' | 'query' | 'mutation' | 'teardown';
/** The strategy that is used to request results from network and/or the cache. */
export declare type RequestPolicy = 'cache-first' | 'cache-only' | 'network-only' | 'cache-and-network';
/** How the operation has */
export declare type CacheOutcome = 'miss' | 'partial' | 'hit';
/** A Graphql query, mutation, or subscription. */
export interface GraphQLRequest<Data = any, Variables = object> {
/** Unique identifier of the request. */
key: number;
query: DocumentNode | TypedDocumentNode<Data, Variables>;
variables?: Variables;
}
/** Metadata that is only available in development for devtools. */
export interface OperationDebugMeta {
source?: string;
cacheOutcome?: CacheOutcome;
networkLatency?: number;
startTime?: number;
}
/** Additional metadata passed to [exchange]{@link Exchange} functions. */
export interface OperationContext {
[key: string]: any;
additionalTypenames?: string[];
fetch?: typeof fetch;
fetchOptions?: RequestInit | (() => RequestInit);
requestPolicy: RequestPolicy;
url: string;
meta?: OperationDebugMeta;
suspense?: boolean;
preferGetMethod?: boolean;
}
/** A [query]{@link Query} or [mutation]{@link Mutation} with additional metadata for use during transmission. */
export interface Operation<Data = any, Variables = any> extends GraphQLRequest<Data, Variables> {
readonly kind: OperationType;
context: OperationContext;
}
/** Resulting data from an [operation]{@link Operation}. */
export interface OperationResult<Data = any, Variables = any> {
/** The [operation]{@link Operation} which has been executed. */
operation: Operation<Data, Variables>;
/** The data returned from the Graphql server. */
data?: Data;
/** Any errors resulting from the operation. */
error?: CombinedError;
/** Optional extensions return by the Graphql server. */
extensions?: Record<string, any>;
/** Optional stale flag added by exchanges that return stale results. */
stale?: boolean;
/** Optional hasNext flag indicating deferred/streamed results are following. */
hasNext?: boolean;
}
/** Input parameters for to an Exchange factory function. */
export interface ExchangeInput {
client: Client;
forward: ExchangeIO;
dispatchDebug: <T extends keyof DebugEventTypes | string>(t: DebugEventArg<T>) => void;
}
/** Function responsible for listening for streamed [operations]{@link Operation}. */
export declare type Exchange = (input: ExchangeInput) => ExchangeIO;
/** Function responsible for receiving an observable [operation]{@link Operation} and returning a [result]{@link OperationResult}. */
export declare type ExchangeIO = (ops$: Source<Operation>) => Source<OperationResult>;
/** Debug event types (interfaced for declaration merging). */
export interface DebugEventTypes {
cacheHit: {
value: any;
};
cacheInvalidation: {
typenames: string[];
response: OperationResult;
};
fetchRequest: {
url: string;
fetchOptions: RequestInit;
};
fetchSuccess: {
url: string;
fetchOptions: RequestInit;
value: object;
};
fetchError: {
url: string;
fetchOptions: RequestInit;
value: Error;
};
retryRetrying: {
retryCount: number;
};
}
export declare type DebugEventArg<T extends keyof DebugEventTypes | string> = {
type: T;
message: string;
operation: Operation;
} & (T extends keyof DebugEventTypes ? {
data: DebugEventTypes[T];
} : {
data?: any;
});
export declare type DebugEvent<T extends keyof DebugEventTypes | string = string> = DebugEventArg<T> & {
timestamp: number;
source: string;
};

View File

@@ -0,0 +1,15 @@
import { GraphQLError } from 'graphql';
/** An error which can consist of GraphQL errors and Network errors. */
export declare class CombinedError extends Error {
name: string;
message: string;
graphQLErrors: GraphQLError[];
networkError?: Error;
response?: any;
constructor({ networkError, graphQLErrors, response, }: {
networkError?: Error;
graphQLErrors?: Array<string | Partial<GraphQLError> | Error>;
response?: any;
});
toString(): string;
}

View File

@@ -0,0 +1,2 @@
export declare const phash: (h: number, x: string) => number;
export declare const hash: (x: string) => number;

View File

@@ -0,0 +1,9 @@
export * from './error';
export * from './request';
export * from './result';
export * from './typenames';
export * from './stringifyVariables';
export * from './maskTypename';
export * from './streamUtils';
export * from './operation';
export declare const noop: () => void;

View File

@@ -0,0 +1 @@
export declare const maskTypename: (data: any) => any;

View File

@@ -0,0 +1,6 @@
import { GraphQLRequest, Operation, OperationContext, OperationType } from '../types';
declare function makeOperation<Data = any, Variables = object>(kind: OperationType, request: GraphQLRequest<Data, Variables>, context: OperationContext): Operation<Data, Variables>;
declare function makeOperation<Data = any, Variables = object>(kind: OperationType, request: Operation<Data, Variables>, context?: OperationContext): Operation<Data, Variables>;
export { makeOperation };
/** Spreads the provided metadata to the source operation's meta property in context. */
export declare const addMetadata: (operation: Operation, meta: OperationContext['meta']) => Operation<any, any>;

View File

@@ -0,0 +1,17 @@
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
import { DefinitionNode, DocumentNode } from 'graphql';
import { GraphQLRequest } from '../types';
export interface KeyedDocumentNode extends DocumentNode {
__key: number;
}
export declare const stringifyDocument: (node: string | DefinitionNode | DocumentNode) => string;
export declare const keyDocument: (q: string | DocumentNode) => KeyedDocumentNode;
export declare const createRequest: <Data = any, Variables = object>(q: string | DocumentNode | TypedDocumentNode<Data, Variables>, vars?: Variables | undefined) => GraphQLRequest<Data, Variables>;
/**
* Finds the Name value from the OperationDefinition of a Document
*/
export declare const getOperationName: (query: DocumentNode) => string | undefined;
/**
* Finds the operation-type
*/
export declare const getOperationType: (query: DocumentNode) => string | undefined;

View File

@@ -0,0 +1,4 @@
import { ExecutionResult, Operation, OperationResult } from '../types';
export declare const makeResult: (operation: Operation, result: ExecutionResult, response?: any) => OperationResult;
export declare const mergeResultPatch: (prevResult: OperationResult, patch: ExecutionResult, response?: any) => OperationResult;
export declare const makeErrorResult: (operation: Operation, error: Error, response?: any) => OperationResult;

View File

@@ -0,0 +1,3 @@
import { Source } from 'wonka';
import { OperationResult, PromisifiedSource } from '../types';
export declare function withPromise<T extends OperationResult>(source$: Source<T>): PromisifiedSource<T>;

View File

@@ -0,0 +1 @@
export declare const stringifyVariables: (x: any) => string;

View File

@@ -0,0 +1,3 @@
import { DocumentNode } from 'graphql';
export declare const collectTypesFromResponse: (response: object) => string[];
export declare const formatDocument: <T extends DocumentNode>(node: T) => T;

View File

@@ -0,0 +1,10 @@
var e = require("./878a8849.js");
exports.makeFetchBody = e.makeFetchBody;
exports.makeFetchOptions = e.makeFetchOptions;
exports.makeFetchSource = e.makeFetchSource;
exports.makeFetchURL = e.makeFetchURL;
//# sourceMappingURL=urql-core-internal.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"urql-core-internal.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}

View File

@@ -0,0 +1,2 @@
var e=require("./d354e5b3.min.js");exports.makeFetchBody=e.makeFetchBody,exports.makeFetchOptions=e.makeFetchOptions,exports.makeFetchSource=e.makeFetchSource,exports.makeFetchURL=e.makeFetchURL;
//# sourceMappingURL=urql-core-internal.min.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"urql-core-internal.min.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,2 @@
export{b as makeFetchBody,d as makeFetchOptions,e as makeFetchSource,c as makeFetchURL}from"./16a45cc7.min.mjs";
//# sourceMappingURL=urql-core-internal.min.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"urql-core-internal.min.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,2 @@
export { b as makeFetchBody, d as makeFetchOptions, e as makeFetchSource, c as makeFetchURL } from "./01e1547d.mjs";
//# sourceMappingURL=urql-core-internal.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"urql-core-internal.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,833 @@
var e = require("graphql");
var t = require("./878a8849.js");
var r = require("wonka");
function collectTypes(e, t) {
if (Array.isArray(e)) {
for (var r = 0; r < e.length; r++) {
collectTypes(e[r], t);
}
} else if ("object" == typeof e && null !== e) {
for (var n in e) {
if ("__typename" === n && "string" == typeof e[n]) {
t[e[n]] = 0;
} else {
collectTypes(e[n], t);
}
}
}
return t;
}
function collectTypesFromResponse(e) {
return Object.keys(collectTypes(e, {}));
}
var formatNode = function(r) {
if (r.selectionSet && !r.selectionSet.selections.some((function(t) {
return t.kind === e.Kind.FIELD && "__typename" === t.name.value && !t.alias;
}))) {
return t._extends({}, r, {
selectionSet: t._extends({}, r.selectionSet, {
selections: r.selectionSet.selections.concat([ {
kind: e.Kind.FIELD,
name: {
kind: e.Kind.NAME,
value: "__typename"
}
} ])
})
});
}
};
var n = new Map;
function formatDocument(r) {
var a = t.keyDocument(r);
var o = n.get(a.__key);
if (!o) {
o = e.visit(a, {
Field: formatNode,
InlineFragment: formatNode
});
Object.defineProperty(o, "__key", {
value: a.__key,
enumerable: !1
});
n.set(a.__key, o);
}
return o;
}
function maskTypename(e) {
if (!e || "object" != typeof e) {
return e;
}
return Object.keys(e).reduce((function(t, r) {
var n = e[r];
if ("__typename" === r) {
Object.defineProperty(t, "__typename", {
enumerable: !1,
value: n
});
} else if (Array.isArray(n)) {
t[r] = n.map(maskTypename);
} else if (n && "object" == typeof n && "__typename" in n) {
t[r] = maskTypename(n);
} else {
t[r] = n;
}
return t;
}), Array.isArray(e) ? [] : {});
}
function withPromise(e) {
e.toPromise = function() {
return r.toPromise(r.take(1)(r.filter((function(e) {
return !e.stale && !e.hasNext;
}))(e)));
};
return e;
}
function makeOperation(e, t, r) {
if (!r) {
r = t.context;
}
return {
key: t.key,
query: t.query,
variables: t.variables,
kind: e,
context: r
};
}
function addMetadata(e, r) {
return makeOperation(e.kind, e, t._extends({}, e.context, {
meta: t._extends({}, e.context.meta, r)
}));
}
function noop() {}
function applyDefinitions(r, n, a) {
for (var o = 0; o < a.length; o++) {
if (a[o].kind === e.Kind.FRAGMENT_DEFINITION) {
var i = a[o].name.value;
var u = t.stringifyDocument(a[o]);
if (!r.has(i)) {
r.set(i, u);
n.push(a[o]);
} else if ("production" !== process.env.NODE_ENV && r.get(i) !== u) {
console.warn("[WARNING: Duplicate Fragment] A fragment with name `" + i + "` already exists in this document.\nWhile fragment names may not be unique across your source, each name must be unique per document.");
}
} else {
n.push(a[o]);
}
}
}
function shouldSkip(e) {
var t = e.kind;
return "mutation" !== t && "query" !== t;
}
function cacheExchange(e) {
var n = e.forward;
var a = e.client;
var o = e.dispatchDebug;
var i = new Map;
var u = Object.create(null);
function mapTypeNames(e) {
var t = makeOperation(e.kind, e);
t.query = formatDocument(e.query);
return t;
}
function isOperationCached(e) {
var t = e.context.requestPolicy;
return "query" === e.kind && "network-only" !== t && ("cache-only" === t || i.has(e.key));
}
return function(e) {
var c = r.share(e);
var s = r.map((function(e) {
var r = i.get(e.key);
"production" !== process.env.NODE_ENV && o(t._extends({}, {
operation: e
}, r ? {
type: "cacheHit",
message: "The result was successfully retried from the cache"
} : {
type: "cacheMiss",
message: "The result could not be retrieved from the cache"
}));
var n = t._extends({}, r, {
operation: addMetadata(e, {
cacheOutcome: r ? "hit" : "miss"
})
});
if ("cache-and-network" === e.context.requestPolicy) {
n.stale = !0;
reexecuteOperation(a, e);
}
return n;
}))(r.filter((function(e) {
return !shouldSkip(e) && isOperationCached(e);
}))(c));
var p = r.tap((function(e) {
var t = e.operation;
if (!t) {
return;
}
var r = collectTypesFromResponse(e.data).concat(t.context.additionalTypenames || []);
if ("mutation" === e.operation.kind) {
var n = new Set;
"production" !== process.env.NODE_ENV && o({
type: "cacheInvalidation",
message: "The following typenames have been invalidated: " + r,
operation: t,
data: {
typenames: r,
response: e
},
source: "cacheExchange"
});
for (var c = 0; c < r.length; c++) {
var s = r[c];
var p = u[s] || (u[s] = new Set);
p.forEach((function(e) {
n.add(e);
}));
p.clear();
}
n.forEach((function(e) {
if (i.has(e)) {
t = i.get(e).operation;
i.delete(e);
reexecuteOperation(a, t);
}
}));
} else if ("query" === t.kind && e.data) {
i.set(t.key, e);
for (var f = 0; f < r.length; f++) {
var l = r[f];
(u[l] || (u[l] = new Set)).add(t.key);
}
}
}))(n(r.filter((function(e) {
return "query" !== e.kind || "cache-only" !== e.context.requestPolicy;
}))(r.map((function(e) {
return addMetadata(e, {
cacheOutcome: "miss"
});
}))(r.merge([ r.map(mapTypeNames)(r.filter((function(e) {
return !shouldSkip(e) && !isOperationCached(e);
}))(c)), r.filter((function(e) {
return shouldSkip(e);
}))(c) ])))));
return r.merge([ s, p ]);
};
}
function reexecuteOperation(e, r) {
return e.reexecuteOperation(makeOperation(r.kind, r, t._extends({}, r.context, {
requestPolicy: "network-only"
})));
}
var a = new Set;
function dedupExchange(e) {
var t = e.forward;
var n = e.dispatchDebug;
var a = new Set;
function filterIncomingOperation(e) {
var t = e.key;
var r = e.kind;
if ("teardown" === r) {
a.delete(t);
return !0;
}
if ("query" !== r && "subscription" !== r) {
return !0;
}
var o = a.has(t);
a.add(t);
if (o) {
"production" !== process.env.NODE_ENV && n({
type: "dedup",
message: "An operation has been deduped.",
operation: e,
source: "dedupExchange"
});
}
return !o;
}
function afterOperationResult(e) {
if (!e.hasNext) {
a.delete(e.operation.key);
}
}
return function(e) {
var n = r.filter(filterIncomingOperation)(e);
return r.tap(afterOperationResult)(t(n));
};
}
function fetchExchange(e) {
var n = e.forward;
var a = e.dispatchDebug;
return function(e) {
var o = r.share(e);
var i = r.mergeMap((function(e) {
var n = e.key;
var i = r.filter((function(e) {
return "teardown" === e.kind && e.key === n;
}))(o);
var u = t.makeFetchBody(e);
var c = t.makeFetchURL(e, u);
var s = t.makeFetchOptions(e, u);
"production" !== process.env.NODE_ENV && a({
type: "fetchRequest",
message: "A fetch request is being executed.",
operation: e,
data: {
url: c,
fetchOptions: s
},
source: "fetchExchange"
});
return r.onPush((function(t) {
var r = !t.data ? t.error : void 0;
"production" !== process.env.NODE_ENV && a({
type: r ? "fetchError" : "fetchSuccess",
message: "A " + (r ? "failed" : "successful") + " fetch response has been returned.",
operation: e,
data: {
url: c,
fetchOptions: s,
value: r || t
},
source: "fetchExchange"
});
}))(r.takeUntil(i)(t.makeFetchSource(e, c, s)));
}))(r.filter((function(e) {
return "query" === e.kind || "mutation" === e.kind;
}))(o));
var u = n(r.filter((function(e) {
return "query" !== e.kind && "mutation" !== e.kind;
}))(o));
return r.merge([ i, u ]);
};
}
function fallbackExchange(e) {
var t = e.dispatchDebug;
return function(e) {
return r.filter((function() {
return !1;
}))(r.tap((function(e) {
if ("teardown" !== e.kind && "production" !== process.env.NODE_ENV) {
var r = 'No exchange has handled operations of kind "' + e.kind + "\". Check whether you've added an exchange responsible for these operations.";
"production" !== process.env.NODE_ENV && t({
type: "fallbackCatch",
message: r,
operation: e,
source: "fallbackExchange"
});
console.warn(r);
}
}))(e));
};
}
var o = fallbackExchange({
dispatchDebug: noop
});
function composeExchanges(e) {
return function(r) {
var n = r.client;
var a = r.dispatchDebug;
return e.reduceRight((function(e, r) {
return r({
client: n,
forward: e,
dispatchDebug: function dispatchDebug$1(e) {
"production" !== process.env.NODE_ENV && a(t._extends({}, {
timestamp: Date.now(),
source: r.name
}, e));
}
});
}), r.forward);
};
}
var i = [ dedupExchange, cacheExchange, fetchExchange ];
var u = function Client(e) {
if ("production" !== process.env.NODE_ENV && !e.url) {
throw new Error("You are creating an urql-client without a url.");
}
var n = new Map;
var a = new Map;
var o = [];
var u = r.makeSubject();
var c = u.source;
var s = u.next;
var p = !1;
function dispatchOperation(e) {
p = !0;
if (e) {
s(e);
}
while (e = o.shift()) {
s(e);
}
p = !1;
}
function makeResultSource(e) {
var i = r.filter((function(t) {
return t.operation.kind === e.kind && t.operation.key === e.key;
}))(k);
if (l.maskTypename) {
i = r.map((function(e) {
return t._extends({}, e, {
data: maskTypename(e.data)
});
}))(i);
}
if ("mutation" === e.kind) {
return r.take(1)(r.onStart((function() {
return dispatchOperation(e);
}))(i));
}
return r.share(r.onEnd((function() {
n.delete(e.key);
a.delete(e.key);
for (var t = o.length - 1; t >= 0; t--) {
if (o[t].key === e.key) {
o.splice(t, 1);
}
}
dispatchOperation(makeOperation("teardown", e, e.context));
}))(r.onPush((function(t) {
n.set(e.key, t);
}))(r.switchMap((function(n) {
if ("query" !== e.kind || n.stale) {
return r.fromValue(n);
}
return r.merge([ r.fromValue(n), r.map((function() {
return t._extends({}, n, {
stale: !0
});
}))(r.take(1)(r.filter((function(t) {
return "query" === t.kind && t.key === e.key && "cache-only" !== t.context.requestPolicy;
}))(c))) ]);
}))(r.takeUntil(r.filter((function(t) {
return "teardown" === t.kind && t.key === e.key;
}))(c))(i)))));
}
var f = this instanceof Client ? this : Object.create(Client.prototype);
var l = t._extends(f, {
url: e.url,
fetchOptions: e.fetchOptions,
fetch: e.fetch,
suspense: !!e.suspense,
requestPolicy: e.requestPolicy || "cache-first",
preferGetMethod: !!e.preferGetMethod,
maskTypename: !!e.maskTypename,
operations$: c,
reexecuteOperation: function reexecuteOperation(e) {
if ("mutation" === e.kind || a.has(e.key)) {
o.push(e);
if (!p) {
Promise.resolve().then(dispatchOperation);
}
}
},
createOperationContext: function createOperationContext(e) {
if (!e) {
e = {};
}
return t._extends({}, {
url: l.url,
fetchOptions: l.fetchOptions,
fetch: l.fetch,
preferGetMethod: l.preferGetMethod
}, e, {
suspense: e.suspense || !1 !== e.suspense && l.suspense,
requestPolicy: e.requestPolicy || l.requestPolicy
});
},
createRequestOperation: function createRequestOperation(e, r, n) {
var a = t.getOperationType(r.query);
if ("production" !== process.env.NODE_ENV && "teardown" !== e && a !== e) {
throw new Error('Expected operation of type "' + e + '" but found "' + a + '"');
}
return makeOperation(e, r, l.createOperationContext(n));
},
executeRequestOperation: function executeRequestOperation(e) {
if ("mutation" === e.kind) {
return makeResultSource(e);
}
return r.make((function(o) {
var i = a.get(e.key);
if (!i) {
a.set(e.key, i = makeResultSource(e));
}
var u = "cache-and-network" === e.context.requestPolicy || "network-only" === e.context.requestPolicy;
return r.subscribe(o.next)(r.onEnd(o.complete)(r.onStart((function() {
var r = n.get(e.key);
if ("subscription" === e.kind) {
return dispatchOperation(e);
} else if (u) {
dispatchOperation(e);
}
if (null != r && r === n.get(e.key)) {
o.next(u ? t._extends({}, r, {
stale: !0
}) : r);
} else if (!u) {
dispatchOperation(e);
}
}))(i))).unsubscribe;
}));
},
executeQuery: function executeQuery(e, t) {
var r = l.createRequestOperation("query", e, t);
return l.executeRequestOperation(r);
},
executeSubscription: function executeSubscription(e, t) {
var r = l.createRequestOperation("subscription", e, t);
return l.executeRequestOperation(r);
},
executeMutation: function executeMutation(e, t) {
var r = l.createRequestOperation("mutation", e, t);
return l.executeRequestOperation(r);
},
query: function query(e, r, n) {
if (!n || "boolean" != typeof n.suspense) {
n = t._extends({}, n, {
suspense: !1
});
}
return withPromise(l.executeQuery(t.createRequest(e, r), n));
},
readQuery: function readQuery(e, t, n) {
var a = null;
r.subscribe((function(e) {
a = e;
}))(l.query(e, t, n)).unsubscribe();
return a;
},
subscription: function subscription(e, r, n) {
return l.executeSubscription(t.createRequest(e, r), n);
},
mutation: function mutation(e, r, n) {
return withPromise(l.executeMutation(t.createRequest(e, r), n));
}
});
var d = noop;
if ("production" !== process.env.NODE_ENV) {
var h = r.makeSubject();
var v = h.next;
var m = h.source;
l.subscribeToDebugTarget = function(e) {
return r.subscribe(e)(m);
};
d = v;
}
var y = composeExchanges(void 0 !== e.exchanges ? e.exchanges : i);
var k = r.share(y({
client: l,
dispatchDebug: d,
forward: fallbackExchange({
dispatchDebug: d
})
})(c));
r.publish(k);
return l;
};
var c = u;
exports.CombinedError = t.CombinedError;
exports.createRequest = t.createRequest;
exports.getOperationName = t.getOperationName;
exports.makeErrorResult = t.makeErrorResult;
exports.makeResult = t.makeResult;
exports.mergeResultPatch = t.mergeResultPatch;
exports.stringifyVariables = t.stringifyVariables;
exports.Client = u;
exports.cacheExchange = cacheExchange;
exports.composeExchanges = composeExchanges;
exports.createClient = c;
exports.debugExchange = function debugExchange(e) {
var t = e.forward;
if ("production" === process.env.NODE_ENV) {
return function(e) {
return t(e);
};
} else {
return function(e) {
return r.tap((function(e) {
return console.log("[Exchange debug]: Completed operation: ", e);
}))(t(r.tap((function(e) {
return console.log("[Exchange debug]: Incoming operation: ", e);
}))(e)));
};
}
};
exports.dedupExchange = dedupExchange;
exports.defaultExchanges = i;
exports.errorExchange = function errorExchange(e) {
var t = e.onError;
return function(e) {
var n = e.forward;
return function(e) {
return r.tap((function(e) {
var r = e.error;
if (r) {
t(r, e.operation);
}
}))(n(e));
};
};
};
exports.fallbackExchangeIO = o;
exports.fetchExchange = fetchExchange;
exports.formatDocument = formatDocument;
exports.gql = function gql() {
var r = arguments;
var n = new Map;
var a = [];
var o = [];
var i = Array.isArray(arguments[0]) ? arguments[0][0] : arguments[0] || "";
for (var u = 1; u < arguments.length; u++) {
var c = r[u];
if (c && c.definitions) {
o.push.apply(o, c.definitions);
} else {
i += c;
}
i += r[0][u];
}
applyDefinitions(n, a, t.keyDocument(i).definitions);
applyDefinitions(n, a, o);
return t.keyDocument({
kind: e.Kind.DOCUMENT,
definitions: a
});
};
exports.makeOperation = makeOperation;
exports.maskTypename = maskTypename;
exports.ssrExchange = function ssrExchange(e) {
var n = !(!e || !e.staleWhileRevalidate);
var o = !(!e || !e.includeExtensions);
var i = {};
var u = [];
function invalidate(e) {
u.push(e.operation.key);
if (1 === u.length) {
Promise.resolve().then((function() {
var e;
while (e = u.shift()) {
i[e] = null;
}
}));
}
}
var ssr = function(u) {
var c = u.client;
var s = u.forward;
return function(u) {
var p = e && "boolean" == typeof e.isClient ? !!e.isClient : !c.suspense;
var f = r.share(u);
var l = s(r.filter((function(e) {
return !i[e.key] || !!i[e.key].hasNext;
}))(f));
var d = r.map((function(e) {
var r = function deserializeResult(e, r, n) {
return {
operation: e,
data: r.data ? JSON.parse(r.data) : void 0,
extensions: n && r.extensions ? JSON.parse(r.extensions) : void 0,
error: r.error ? new t.CombinedError({
networkError: r.error.networkError ? new Error(r.error.networkError) : void 0,
graphQLErrors: r.error.graphQLErrors
}) : void 0,
hasNext: r.hasNext
};
}(e, i[e.key], o);
if (n && !a.has(e.key)) {
r.stale = !0;
a.add(e.key);
reexecuteOperation(c, e);
}
return r;
}))(r.filter((function(e) {
return !!i[e.key];
}))(f));
if (!p) {
l = r.tap((function(e) {
var t = e.operation;
if ("mutation" !== t.kind) {
var r = function serializeResult(e, t) {
var r = e.hasNext;
var n = e.data;
var a = e.extensions;
var o = e.error;
var i = {};
if (void 0 !== n) {
i.data = JSON.stringify(n);
}
if (t && void 0 !== a) {
i.extensions = JSON.stringify(a);
}
if (r) {
i.hasNext = !0;
}
if (o) {
i.error = {
graphQLErrors: o.graphQLErrors.map((function(e) {
if (!e.path && !e.extensions) {
return e.message;
}
return {
message: e.message,
path: e.path,
extensions: e.extensions
};
}))
};
if (o.networkError) {
i.error.networkError = "" + o.networkError;
}
}
return i;
}(e, o);
i[t.key] = r;
}
}))(l);
} else {
d = r.tap(invalidate)(d);
}
return r.merge([ l, d ]);
};
};
ssr.restoreData = function(e) {
for (var t in e) {
if (null !== i[t]) {
i[t] = e[t];
}
}
};
ssr.extractData = function() {
var e = {};
for (var t in i) {
if (null != i[t]) {
e[t] = i[t];
}
}
return e;
};
if (e && e.initialState) {
ssr.restoreData(e.initialState);
}
return ssr;
};
exports.subscriptionExchange = function subscriptionExchange(n) {
var a = n.forwardSubscription;
var o = n.enableAllOperations;
return function(n) {
var i = n.client;
var u = n.forward;
function isSubscriptionOperation(e) {
var t = e.kind;
return "subscription" === t || !!o && ("query" === t || "mutation" === t);
}
return function(n) {
var o = r.share(n);
var c = r.mergeMap((function(n) {
var u = n.key;
var c = r.filter((function(e) {
return "teardown" === e.kind && e.key === u;
}))(o);
return r.takeUntil(c)(function createSubscriptionSource(n) {
var o = a({
key: n.key.toString(36),
query: e.print(n.query),
variables: n.variables,
context: t._extends({}, n.context)
});
return r.make((function(e) {
var r = e.next;
var a = e.complete;
var u = !1;
var c;
Promise.resolve().then((function() {
if (u) {
return;
}
c = o.subscribe({
next: function(e) {
return r(t.makeResult(n, e));
},
error: function(e) {
return r(t.makeErrorResult(n, e));
},
complete: function() {
if (!u) {
u = !0;
if ("subscription" === n.kind) {
i.reexecuteOperation(makeOperation("teardown", n, n.context));
}
a();
}
}
});
}));
return function() {
u = !0;
if (c) {
c.unsubscribe();
}
};
}));
}(n));
}))(r.filter(isSubscriptionOperation)(o));
var s = u(r.filter((function(e) {
return !isSubscriptionOperation(e);
}))(o));
return r.merge([ c, s ]);
};
};
};
//# sourceMappingURL=urql-core.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,805 @@
import { visit as e } from "graphql/language/visitor.mjs";
import { Kind as r } from "graphql/language/kinds.mjs";
import { print as n } from "graphql/language/printer.mjs";
import { k as t, _ as o, s as u, C as c, m as s, a as p, b as l, c as d, d as v, e as y, g as k, f as g } from "./01e1547d.mjs";
export { C as CombinedError, f as createRequest, j as getOperationName, a as makeErrorResult, m as makeResult, i as mergeResultPatch, h as stringifyVariables } from "./01e1547d.mjs";
import { toPromise as x, take as E, filter as O, share as b, map as w, tap as q, merge as N, mergeMap as D, takeUntil as _, make as S, onPush as R, makeSubject as T, subscribe as P, onEnd as M, onStart as A, publish as V, switchMap as I, fromValue as F } from "wonka";
function collectTypes(e, r) {
if (Array.isArray(e)) {
for (var n = 0; n < e.length; n++) {
collectTypes(e[n], r);
}
} else if ("object" == typeof e && null !== e) {
for (var t in e) {
if ("__typename" === t && "string" == typeof e[t]) {
r[e[t]] = 0;
} else {
collectTypes(e[t], r);
}
}
}
return r;
}
function collectTypesFromResponse(e) {
return Object.keys(collectTypes(e, {}));
}
var formatNode = function(e) {
if (e.selectionSet && !e.selectionSet.selections.some((function(e) {
return e.kind === r.FIELD && "__typename" === e.name.value && !e.alias;
}))) {
return o({}, e, {
selectionSet: o({}, e.selectionSet, {
selections: e.selectionSet.selections.concat([ {
kind: r.FIELD,
name: {
kind: r.NAME,
value: "__typename"
}
} ])
})
});
}
};
var Q = new Map;
function formatDocument(r) {
var n = t(r);
var a = Q.get(n.__key);
if (!a) {
a = e(n, {
Field: formatNode,
InlineFragment: formatNode
});
Object.defineProperty(a, "__key", {
value: n.__key,
enumerable: !1
});
Q.set(n.__key, a);
}
return a;
}
function maskTypename(e) {
if (!e || "object" != typeof e) {
return e;
}
return Object.keys(e).reduce((function(r, n) {
var t = e[n];
if ("__typename" === n) {
Object.defineProperty(r, "__typename", {
enumerable: !1,
value: t
});
} else if (Array.isArray(t)) {
r[n] = t.map(maskTypename);
} else if (t && "object" == typeof t && "__typename" in t) {
r[n] = maskTypename(t);
} else {
r[n] = t;
}
return r;
}), Array.isArray(e) ? [] : {});
}
function withPromise(e) {
e.toPromise = function() {
return x(E(1)(O((function(e) {
return !e.stale && !e.hasNext;
}))(e)));
};
return e;
}
function makeOperation(e, r, n) {
if (!n) {
n = r.context;
}
return {
key: r.key,
query: r.query,
variables: r.variables,
kind: e,
context: n
};
}
function addMetadata(e, r) {
return makeOperation(e.kind, e, o({}, e.context, {
meta: o({}, e.context.meta, r)
}));
}
function noop() {}
function applyDefinitions(e, n, t) {
for (var a = 0; a < t.length; a++) {
if (t[a].kind === r.FRAGMENT_DEFINITION) {
var o = t[a].name.value;
var i = u(t[a]);
if (!e.has(o)) {
e.set(o, i);
n.push(t[a]);
} else if ("production" !== process.env.NODE_ENV && e.get(o) !== i) {
console.warn("[WARNING: Duplicate Fragment] A fragment with name `" + o + "` already exists in this document.\nWhile fragment names may not be unique across your source, each name must be unique per document.");
}
} else {
n.push(t[a]);
}
}
}
function gql() {
var e = arguments;
var n = new Map;
var a = [];
var o = [];
var i = Array.isArray(arguments[0]) ? arguments[0][0] : arguments[0] || "";
for (var u = 1; u < arguments.length; u++) {
var c = e[u];
if (c && c.definitions) {
o.push.apply(o, c.definitions);
} else {
i += c;
}
i += e[0][u];
}
applyDefinitions(n, a, t(i).definitions);
applyDefinitions(n, a, o);
return t({
kind: r.DOCUMENT,
definitions: a
});
}
function shouldSkip(e) {
var r = e.kind;
return "mutation" !== r && "query" !== r;
}
function cacheExchange(e) {
var r = e.forward;
var n = e.client;
var t = e.dispatchDebug;
var a = new Map;
var i = Object.create(null);
function mapTypeNames(e) {
var r = makeOperation(e.kind, e);
r.query = formatDocument(e.query);
return r;
}
function isOperationCached(e) {
var r = e.context.requestPolicy;
return "query" === e.kind && "network-only" !== r && ("cache-only" === r || a.has(e.key));
}
return function(e) {
var u = b(e);
var c = w((function(e) {
var r = a.get(e.key);
"production" !== process.env.NODE_ENV && t(o({}, {
operation: e
}, r ? {
type: "cacheHit",
message: "The result was successfully retried from the cache"
} : {
type: "cacheMiss",
message: "The result could not be retrieved from the cache"
}));
var i = o({}, r, {
operation: addMetadata(e, {
cacheOutcome: r ? "hit" : "miss"
})
});
if ("cache-and-network" === e.context.requestPolicy) {
i.stale = !0;
reexecuteOperation(n, e);
}
return i;
}))(O((function(e) {
return !shouldSkip(e) && isOperationCached(e);
}))(u));
var s = q((function(e) {
var r = e.operation;
if (!r) {
return;
}
var o = collectTypesFromResponse(e.data).concat(r.context.additionalTypenames || []);
if ("mutation" === e.operation.kind) {
var u = new Set;
"production" !== process.env.NODE_ENV && t({
type: "cacheInvalidation",
message: "The following typenames have been invalidated: " + o,
operation: r,
data: {
typenames: o,
response: e
},
source: "cacheExchange"
});
for (var c = 0; c < o.length; c++) {
var s = o[c];
var f = i[s] || (i[s] = new Set);
f.forEach((function(e) {
u.add(e);
}));
f.clear();
}
u.forEach((function(e) {
if (a.has(e)) {
r = a.get(e).operation;
a.delete(e);
reexecuteOperation(n, r);
}
}));
} else if ("query" === r.kind && e.data) {
a.set(r.key, e);
for (var p = 0; p < o.length; p++) {
var l = o[p];
(i[l] || (i[l] = new Set)).add(r.key);
}
}
}))(r(O((function(e) {
return "query" !== e.kind || "cache-only" !== e.context.requestPolicy;
}))(w((function(e) {
return addMetadata(e, {
cacheOutcome: "miss"
});
}))(N([ w(mapTypeNames)(O((function(e) {
return !shouldSkip(e) && !isOperationCached(e);
}))(u)), O((function(e) {
return shouldSkip(e);
}))(u) ])))));
return N([ c, s ]);
};
}
function reexecuteOperation(e, r) {
return e.reexecuteOperation(makeOperation(r.kind, r, o({}, r.context, {
requestPolicy: "network-only"
})));
}
var G = new Set;
function ssrExchange(e) {
var r = !(!e || !e.staleWhileRevalidate);
var n = !(!e || !e.includeExtensions);
var t = {};
var a = [];
function invalidate(e) {
a.push(e.operation.key);
if (1 === a.length) {
Promise.resolve().then((function() {
var e;
while (e = a.shift()) {
t[e] = null;
}
}));
}
}
var ssr = function(a) {
var o = a.client;
var i = a.forward;
return function(a) {
var u = e && "boolean" == typeof e.isClient ? !!e.isClient : !o.suspense;
var s = b(a);
var f = i(O((function(e) {
return !t[e.key] || !!t[e.key].hasNext;
}))(s));
var p = w((function(e) {
var a = function deserializeResult(e, r, n) {
return {
operation: e,
data: r.data ? JSON.parse(r.data) : void 0,
extensions: n && r.extensions ? JSON.parse(r.extensions) : void 0,
error: r.error ? new c({
networkError: r.error.networkError ? new Error(r.error.networkError) : void 0,
graphQLErrors: r.error.graphQLErrors
}) : void 0,
hasNext: r.hasNext
};
}(e, t[e.key], n);
if (r && !G.has(e.key)) {
a.stale = !0;
G.add(e.key);
reexecuteOperation(o, e);
}
return a;
}))(O((function(e) {
return !!t[e.key];
}))(s));
if (!u) {
f = q((function(e) {
var r = e.operation;
if ("mutation" !== r.kind) {
var a = function serializeResult(e, r) {
var n = e.hasNext;
var t = e.data;
var a = e.extensions;
var o = e.error;
var i = {};
if (void 0 !== t) {
i.data = JSON.stringify(t);
}
if (r && void 0 !== a) {
i.extensions = JSON.stringify(a);
}
if (n) {
i.hasNext = !0;
}
if (o) {
i.error = {
graphQLErrors: o.graphQLErrors.map((function(e) {
if (!e.path && !e.extensions) {
return e.message;
}
return {
message: e.message,
path: e.path,
extensions: e.extensions
};
}))
};
if (o.networkError) {
i.error.networkError = "" + o.networkError;
}
}
return i;
}(e, n);
t[r.key] = a;
}
}))(f);
} else {
p = q(invalidate)(p);
}
return N([ f, p ]);
};
};
ssr.restoreData = function(e) {
for (var r in e) {
if (null !== t[r]) {
t[r] = e[r];
}
}
};
ssr.extractData = function() {
var e = {};
for (var r in t) {
if (null != t[r]) {
e[r] = t[r];
}
}
return e;
};
if (e && e.initialState) {
ssr.restoreData(e.initialState);
}
return ssr;
}
function subscriptionExchange(e) {
var r = e.forwardSubscription;
var t = e.enableAllOperations;
return function(e) {
var a = e.client;
var i = e.forward;
function isSubscriptionOperation(e) {
var r = e.kind;
return "subscription" === r || !!t && ("query" === r || "mutation" === r);
}
return function(e) {
var t = b(e);
var u = D((function(e) {
var i = e.key;
var u = O((function(e) {
return "teardown" === e.kind && e.key === i;
}))(t);
return _(u)(function createSubscriptionSource(e) {
var t = r({
key: e.key.toString(36),
query: n(e.query),
variables: e.variables,
context: o({}, e.context)
});
return S((function(r) {
var n = r.next;
var o = r.complete;
var i = !1;
var u;
Promise.resolve().then((function() {
if (i) {
return;
}
u = t.subscribe({
next: function(r) {
return n(s(e, r));
},
error: function(r) {
return n(p(e, r));
},
complete: function() {
if (!i) {
i = !0;
if ("subscription" === e.kind) {
a.reexecuteOperation(makeOperation("teardown", e, e.context));
}
o();
}
}
});
}));
return function() {
i = !0;
if (u) {
u.unsubscribe();
}
};
}));
}(e));
}))(O(isSubscriptionOperation)(t));
var c = i(O((function(e) {
return !isSubscriptionOperation(e);
}))(t));
return N([ u, c ]);
};
};
}
function debugExchange(e) {
var r = e.forward;
if ("production" === process.env.NODE_ENV) {
return function(e) {
return r(e);
};
} else {
return function(e) {
return q((function(e) {
return console.log("[Exchange debug]: Completed operation: ", e);
}))(r(q((function(e) {
return console.log("[Exchange debug]: Incoming operation: ", e);
}))(e)));
};
}
}
function dedupExchange(e) {
var r = e.forward;
var n = e.dispatchDebug;
var t = new Set;
function filterIncomingOperation(e) {
var r = e.key;
var a = e.kind;
if ("teardown" === a) {
t.delete(r);
return !0;
}
if ("query" !== a && "subscription" !== a) {
return !0;
}
var o = t.has(r);
t.add(r);
if (o) {
"production" !== process.env.NODE_ENV && n({
type: "dedup",
message: "An operation has been deduped.",
operation: e,
source: "dedupExchange"
});
}
return !o;
}
function afterOperationResult(e) {
if (!e.hasNext) {
t.delete(e.operation.key);
}
}
return function(e) {
var n = O(filterIncomingOperation)(e);
return q(afterOperationResult)(r(n));
};
}
function fetchExchange(e) {
var r = e.forward;
var n = e.dispatchDebug;
return function(e) {
var t = b(e);
var a = D((function(e) {
var r = e.key;
var a = O((function(e) {
return "teardown" === e.kind && e.key === r;
}))(t);
var o = l(e);
var i = d(e, o);
var u = v(e, o);
"production" !== process.env.NODE_ENV && n({
type: "fetchRequest",
message: "A fetch request is being executed.",
operation: e,
data: {
url: i,
fetchOptions: u
},
source: "fetchExchange"
});
return R((function(r) {
var t = !r.data ? r.error : void 0;
"production" !== process.env.NODE_ENV && n({
type: t ? "fetchError" : "fetchSuccess",
message: "A " + (t ? "failed" : "successful") + " fetch response has been returned.",
operation: e,
data: {
url: i,
fetchOptions: u,
value: t || r
},
source: "fetchExchange"
});
}))(_(a)(y(e, i, u)));
}))(O((function(e) {
return "query" === e.kind || "mutation" === e.kind;
}))(t));
var o = r(O((function(e) {
return "query" !== e.kind && "mutation" !== e.kind;
}))(t));
return N([ a, o ]);
};
}
function fallbackExchange(e) {
var r = e.dispatchDebug;
return function(e) {
return O((function() {
return !1;
}))(q((function(e) {
if ("teardown" !== e.kind && "production" !== process.env.NODE_ENV) {
var n = 'No exchange has handled operations of kind "' + e.kind + "\". Check whether you've added an exchange responsible for these operations.";
"production" !== process.env.NODE_ENV && r({
type: "fallbackCatch",
message: n,
operation: e,
source: "fallbackExchange"
});
console.warn(n);
}
}))(e));
};
}
var L = fallbackExchange({
dispatchDebug: noop
});
function composeExchanges(e) {
return function(r) {
var n = r.client;
var t = r.dispatchDebug;
return e.reduceRight((function(e, r) {
return r({
client: n,
forward: e,
dispatchDebug: function dispatchDebug$1(e) {
"production" !== process.env.NODE_ENV && t(o({}, {
timestamp: Date.now(),
source: r.name
}, e));
}
});
}), r.forward);
};
}
function errorExchange(e) {
var r = e.onError;
return function(e) {
var n = e.forward;
return function(e) {
return q((function(e) {
var n = e.error;
if (n) {
r(n, e.operation);
}
}))(n(e));
};
};
}
var J = [ dedupExchange, cacheExchange, fetchExchange ];
var W = function Client(e) {
if ("production" !== process.env.NODE_ENV && !e.url) {
throw new Error("You are creating an urql-client without a url.");
}
var r = new Map;
var n = new Map;
var t = [];
var a = T();
var i = a.source;
var u = a.next;
var c = !1;
function dispatchOperation(e) {
c = !0;
if (e) {
u(e);
}
while (e = t.shift()) {
u(e);
}
c = !1;
}
function makeResultSource(e) {
var a = O((function(r) {
return r.operation.kind === e.kind && r.operation.key === e.key;
}))(y);
if (f.maskTypename) {
a = w((function(e) {
return o({}, e, {
data: maskTypename(e.data)
});
}))(a);
}
if ("mutation" === e.kind) {
return E(1)(A((function() {
return dispatchOperation(e);
}))(a));
}
return b(M((function() {
r.delete(e.key);
n.delete(e.key);
for (var a = t.length - 1; a >= 0; a--) {
if (t[a].key === e.key) {
t.splice(a, 1);
}
}
dispatchOperation(makeOperation("teardown", e, e.context));
}))(R((function(n) {
r.set(e.key, n);
}))(I((function(r) {
if ("query" !== e.kind || r.stale) {
return F(r);
}
return N([ F(r), w((function() {
return o({}, r, {
stale: !0
});
}))(E(1)(O((function(r) {
return "query" === r.kind && r.key === e.key && "cache-only" !== r.context.requestPolicy;
}))(i))) ]);
}))(_(O((function(r) {
return "teardown" === r.kind && r.key === e.key;
}))(i))(a)))));
}
var s = this instanceof Client ? this : Object.create(Client.prototype);
var f = o(s, {
url: e.url,
fetchOptions: e.fetchOptions,
fetch: e.fetch,
suspense: !!e.suspense,
requestPolicy: e.requestPolicy || "cache-first",
preferGetMethod: !!e.preferGetMethod,
maskTypename: !!e.maskTypename,
operations$: i,
reexecuteOperation: function reexecuteOperation(e) {
if ("mutation" === e.kind || n.has(e.key)) {
t.push(e);
if (!c) {
Promise.resolve().then(dispatchOperation);
}
}
},
createOperationContext: function createOperationContext(e) {
if (!e) {
e = {};
}
return o({}, {
url: f.url,
fetchOptions: f.fetchOptions,
fetch: f.fetch,
preferGetMethod: f.preferGetMethod
}, e, {
suspense: e.suspense || !1 !== e.suspense && f.suspense,
requestPolicy: e.requestPolicy || f.requestPolicy
});
},
createRequestOperation: function createRequestOperation(e, r, n) {
var t = k(r.query);
if ("production" !== process.env.NODE_ENV && "teardown" !== e && t !== e) {
throw new Error('Expected operation of type "' + e + '" but found "' + t + '"');
}
return makeOperation(e, r, f.createOperationContext(n));
},
executeRequestOperation: function executeRequestOperation(e) {
if ("mutation" === e.kind) {
return makeResultSource(e);
}
return S((function(t) {
var a = n.get(e.key);
if (!a) {
n.set(e.key, a = makeResultSource(e));
}
var i = "cache-and-network" === e.context.requestPolicy || "network-only" === e.context.requestPolicy;
return P(t.next)(M(t.complete)(A((function() {
var n = r.get(e.key);
if ("subscription" === e.kind) {
return dispatchOperation(e);
} else if (i) {
dispatchOperation(e);
}
if (null != n && n === r.get(e.key)) {
t.next(i ? o({}, n, {
stale: !0
}) : n);
} else if (!i) {
dispatchOperation(e);
}
}))(a))).unsubscribe;
}));
},
executeQuery: function executeQuery(e, r) {
var n = f.createRequestOperation("query", e, r);
return f.executeRequestOperation(n);
},
executeSubscription: function executeSubscription(e, r) {
var n = f.createRequestOperation("subscription", e, r);
return f.executeRequestOperation(n);
},
executeMutation: function executeMutation(e, r) {
var n = f.createRequestOperation("mutation", e, r);
return f.executeRequestOperation(n);
},
query: function query(e, r, n) {
if (!n || "boolean" != typeof n.suspense) {
n = o({}, n, {
suspense: !1
});
}
return withPromise(f.executeQuery(g(e, r), n));
},
readQuery: function readQuery(e, r, n) {
var t = null;
P((function(e) {
t = e;
}))(f.query(e, r, n)).unsubscribe();
return t;
},
subscription: function subscription(e, r, n) {
return f.executeSubscription(g(e, r), n);
},
mutation: function mutation(e, r, n) {
return withPromise(f.executeMutation(g(e, r), n));
}
});
var p = noop;
if ("production" !== process.env.NODE_ENV) {
var l = T();
var d = l.next;
var h = l.source;
f.subscribeToDebugTarget = function(e) {
return P(e)(h);
};
p = d;
}
var v = composeExchanges(void 0 !== e.exchanges ? e.exchanges : J);
var y = b(v({
client: f,
dispatchDebug: p,
forward: fallbackExchange({
dispatchDebug: p
})
})(i));
V(y);
return f;
};
var z = W;
export { W as Client, cacheExchange, composeExchanges, z as createClient, debugExchange, dedupExchange, J as defaultExchanges, errorExchange, L as fallbackExchangeIO, fetchExchange, formatDocument, gql, makeOperation, maskTypename, ssrExchange, subscriptionExchange };
//# sourceMappingURL=urql-core.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,21 @@
{
"name": "urql-core-internal",
"private": true,
"version": "0.0.0",
"main": "../dist/urql-core-internal",
"module": "../dist/urql-core-internal.mjs",
"types": "../dist/types/internal/index.d.ts",
"source": "../src/internal/index.ts",
"exports": {
".": {
"import": "../dist/urql-core-internal.mjs",
"require": "../dist/urql-core-internal.js",
"types": "../dist/types/internal/index.d.ts",
"source": "../src/internal/index.ts"
},
"./package.json": "./package.json"
},
"dependencies": {
"wonka": "^4.0.14"
}
}

View File

@@ -0,0 +1,71 @@
{
"name": "@urql/core",
"version": "2.3.6",
"description": "The shared core for the highly customizable and versatile GraphQL client",
"sideEffects": false,
"homepage": "https://formidable.com/open-source/urql/docs/",
"bugs": "https://github.com/FormidableLabs/urql/issues",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/FormidableLabs/urql.git",
"directory": "packages/core"
},
"keywords": [
"graphql client",
"state management",
"cache",
"formidablelabs",
"exchanges"
],
"main": "dist/urql-core",
"module": "dist/urql-core.mjs",
"types": "dist/types/index.d.ts",
"source": "src/index.ts",
"exports": {
".": {
"import": "./dist/urql-core.mjs",
"require": "./dist/urql-core.js",
"types": "./dist/types/index.d.ts",
"source": "./src/index.ts"
},
"./package.json": "./package.json",
"./internal": {
"import": "./dist/urql-core-internal.mjs",
"require": "./dist/urql-core-internal.js",
"types": "./dist/types/internal/index.d.ts",
"source": "./src/internal/index.ts"
}
},
"files": [
"LICENSE",
"README.md",
"dist/",
"internal/"
],
"scripts": {
"test": "jest",
"clean": "rimraf dist",
"check": "tsc --noEmit",
"lint": "eslint --ext=js,jsx,ts,tsx .",
"build": "rollup -c ../../scripts/rollup/config.js",
"prepare": "node ../../scripts/prepare/index.js",
"prepublishOnly": "run-s clean build"
},
"jest": {
"preset": "../../scripts/jest/preset"
},
"devDependencies": {
"graphql": "^16.0.0"
},
"peerDependencies": {
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
},
"dependencies": {
"@graphql-typed-document-node/core": "^3.1.0",
"wonka": "^4.0.14"
},
"publishConfig": {
"access": "public"
}
}

View File

@@ -0,0 +1,124 @@
# Changelog
## 0.3.0
### Minor Changes
- Add a new `retryWith` option which allows operations to be updated when a request is being retried, by [@kitten](https://github.com/kitten) (See [#1881](https://github.com/FormidableLabs/urql/pull/1881))
### Patch Changes
- Updated dependencies (See [#1870](https://github.com/FormidableLabs/urql/pull/1870) and [#1880](https://github.com/FormidableLabs/urql/pull/1880))
- @urql/core@2.3.1
## 0.2.1
### Patch Changes
- Remove closure-compiler from the build step (See [#1570](https://github.com/FormidableLabs/urql/pull/1570))
- Updated dependencies (See [#1570](https://github.com/FormidableLabs/urql/pull/1570), [#1509](https://github.com/FormidableLabs/urql/pull/1509), [#1600](https://github.com/FormidableLabs/urql/pull/1600), and [#1515](https://github.com/FormidableLabs/urql/pull/1515))
- @urql/core@2.1.0
## 0.2.0
### Minor Changes
- Add a second `Operation` input argument to the `retryIf` predicate, so that retrying can be actively avoided for specific types of operations, e.g. mutations or subscriptions, in certain user-defined cases, by [@kitten](https://github.com/kitten) (See [#1117](https://github.com/FormidableLabs/urql/pull/1117))
### Patch Changes
- Updated dependencies (See [#1119](https://github.com/FormidableLabs/urql/pull/1119), [#1113](https://github.com/FormidableLabs/urql/pull/1113), [#1104](https://github.com/FormidableLabs/urql/pull/1104), and [#1123](https://github.com/FormidableLabs/urql/pull/1123))
- @urql/core@1.15.0
## 0.1.10
### Patch Changes
- ⚠️ Fix the production build overwriting the development build. Specifically in the previous release we mistakenly replaced all development bundles with production bundles. This doesn't have any direct influence on how these packages work, but prevented development warnings from being logged or full errors from being thrown, by [@kitten](https://github.com/kitten) (See [#1097](https://github.com/FormidableLabs/urql/pull/1097))
- Updated dependencies (See [#1097](https://github.com/FormidableLabs/urql/pull/1097))
- @urql/core@1.14.1
## 0.1.9
### Patch Changes
- Deprecate the `Operation.operationName` property in favor of `Operation.kind`. This name was
previously confusing as `operationName` was effectively referring to two different things. You can
safely upgrade to this new version, however to mute all deprecation warnings you will have to
**upgrade** all `urql` packages you use. If you have custom exchanges that spread operations, please
use [the new `makeOperation` helper
function](https://formidable.com/open-source/urql/docs/api/core/#makeoperation) instead, by [@bkonkle](https://github.com/bkonkle) (See [#1045](https://github.com/FormidableLabs/urql/pull/1045))
- Updated dependencies (See [#1094](https://github.com/FormidableLabs/urql/pull/1094) and [#1045](https://github.com/FormidableLabs/urql/pull/1045))
- @urql/core@1.14.0
## 0.1.8
### Patch Changes
- Upgrade to a minimum version of wonka@^4.0.14 to work around issues with React Native's minification builds, which use uglify-es and could lead to broken bundles, by [@kitten](https://github.com/kitten) (See [#842](https://github.com/FormidableLabs/urql/pull/842))
- Updated dependencies (See [#838](https://github.com/FormidableLabs/urql/pull/838) and [#842](https://github.com/FormidableLabs/urql/pull/842))
- @urql/core@1.12.0
## 0.1.7
### Patch Changes
- Add `source` debug name to all `dispatchDebug` calls during build time to identify events by which exchange dispatched them, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#780](https://github.com/FormidableLabs/urql/pull/780))
- Updated dependencies (See [#780](https://github.com/FormidableLabs/urql/pull/780))
- @urql/core@1.11.7
## 0.1.6
### Patch Changes
- Add a `"./package.json"` entry to the `package.json`'s `"exports"` field for Node 14. This seems to be required by packages like `rollup-plugin-svelte` to function properly, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#771](https://github.com/FormidableLabs/urql/pull/771))
- Updated dependencies (See [#771](https://github.com/FormidableLabs/urql/pull/771))
- @urql/core@1.11.6
## 0.1.5
### Patch Changes
- Add debugging events to exchanges that add more detailed information on what is happening
internally, which will be displayed by devtools like the urql [Chrome / Firefox extension](https://github.com/FormidableLabs/urql-devtools), by [@andyrichardson](https://github.com/andyrichardson) (See [#608](https://github.com/FormidableLabs/urql/pull/608))
- Updated dependencies (See [#608](https://github.com/FormidableLabs/urql/pull/608), [#718](https://github.com/FormidableLabs/urql/pull/718), and [#722](https://github.com/FormidableLabs/urql/pull/722))
- @urql/core@1.11.0
## 0.1.4
### Patch Changes
- Add graphql@^15.0.0 to peer dependency range, by [@kitten](https://github.com/kitten) (See [#688](https://github.com/FormidableLabs/urql/pull/688))
- Updated dependencies (See [#688](https://github.com/FormidableLabs/urql/pull/688) and [#678](https://github.com/FormidableLabs/urql/pull/678))
- @urql/core@1.10.8
## 0.1.3
### Patch Changes
- ⚠️ Fix node resolution when using Webpack, which experiences a bug where it only resolves
`package.json:main` instead of `module` when an `.mjs` file imports a package, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#642](https://github.com/FormidableLabs/urql/pull/642))
- Updated dependencies (See [#642](https://github.com/FormidableLabs/urql/pull/642))
- @urql/core@1.10.4
## 0.1.2
### Patch Changes
- ⚠️ Fix Node.js Module support for v13 (experimental-modules) and v14. If your bundler doesn't support
`.mjs` files and fails to resolve the new version, please double check your configuration for
Webpack, or similar tools, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#637](https://github.com/FormidableLabs/urql/pull/637))
- Updated dependencies (See [#637](https://github.com/FormidableLabs/urql/pull/637))
- @urql/core@1.10.3
## 0.1.1
### Patch Changes
- ⚠️ Fix Rollup bundle output being written to .es.js instead of .esm.js, by [@kitten](https://github.com/kitten) (See [#609](https://github.com/FormidableLabs/urql/pull/609))
- Updated dependencies (See [#609](https://github.com/FormidableLabs/urql/pull/609))
- @urql/core@1.10.1
## v0.1.0
**Initial Release**

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 20182020 Formidable
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,15 @@
# @urql/exchange-retry (Exchange factory)
`@urql/exchange-retry` is an exchange for the [`urql`](../../README.md) GraphQL client that allows operations (queries, mutations, subscriptions) to be retried based on an `options` parameter.
## Quick Start Guide
First install `@urql/exchange-retry` alongside `urql`:
```sh
yarn add @urql/exchange-retry
# or
npm install --save @urql/exchange-retry
```
Read more about the [retry exchange](https://formidable.com/open-source/urql/docs/advanced/retry-operations).

View File

@@ -0,0 +1 @@
export { retryExchange } from './retryExchange';

View File

@@ -0,0 +1,12 @@
import { Exchange, Operation, CombinedError } from '@urql/core';
export interface RetryExchangeOptions {
initialDelayMs?: number;
maxDelayMs?: number;
randomDelay?: boolean;
maxNumberAttempts?: number;
/** Conditionally determine whether an error should be retried */
retryIf?: (error: CombinedError, operation: Operation) => boolean;
/** Conditionally update operations as they're retried (retryIf can be replaced with this) */
retryWith?: (error: CombinedError, operation: Operation) => Operation | null | undefined;
}
export declare const retryExchange: ({ initialDelayMs, maxDelayMs, randomDelay, maxNumberAttempts, retryIf, retryWith, }: RetryExchangeOptions) => Exchange;

View File

@@ -0,0 +1,83 @@
var r = require("wonka");
var e = require("@urql/core");
function _extends() {
return (_extends = Object.assign || function(r) {
for (var e = 1; e < arguments.length; e++) {
var t = arguments[e];
for (var a in t) {
if (Object.prototype.hasOwnProperty.call(t, a)) {
r[a] = t[a];
}
}
}
return r;
}).apply(this, arguments);
}
exports.retryExchange = function retryExchange(t) {
var a = t.retryIf;
var n = t.retryWith;
var o = t.initialDelayMs || 1e3;
var i = t.maxDelayMs || 15e3;
var u = t.maxNumberAttempts || 2;
var s = t.randomDelay || !0;
return function(t) {
var c = t.forward;
var y = t.dispatchDebug;
return function(t) {
var v = r.share(t);
var p = r.makeSubject();
var f = p.source;
var d = p.next;
var h = r.mergeMap((function(t) {
var a = t.key;
var n = t.context;
var c = (n.retryCount || 0) + 1;
var p = n.retryDelay || o;
var f = Math.random() + 1.5;
if (s && p * f < i) {
p *= f;
}
var d = r.filter((function(r) {
return ("query" === r.kind || "teardown" === r.kind) && r.key === a;
}))(v);
"production" !== process.env.NODE_ENV && y({
type: "retryAttempt",
message: "The operation has failed and a retry has been triggered (" + c + " / " + u + ")",
operation: t,
data: {
retryCount: c
},
source: "retryExchange"
});
return r.takeUntil(d)(r.delay(p)(r.fromValue(e.makeOperation(t.kind, t, _extends({}, t.context, {
retryDelay: p,
retryCount: c
})))));
}))(f);
return r.filter((function(r) {
if (!(r.error && (a ? a(r.error, r.operation) : n || r.error.networkError))) {
return !0;
}
if (!((r.operation.context.retryCount || 0) >= u - 1)) {
var e = n ? n(r.error, r.operation) : r.operation;
if (!e) {
return !0;
}
d(e);
return !1;
}
"production" !== process.env.NODE_ENV && y({
type: "retryExhausted",
message: "Maximum number of retries has been reached. No further retries will be performed.",
operation: r.operation,
source: "retryExchange"
});
return !0;
}))(r.share(c(r.merge([ v, h ]))));
};
};
};
//# sourceMappingURL=urql-exchange-retry.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
var r=require("wonka"),e=require("@urql/core");function t(){return(t=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}exports.retryExchange=function(n){var o=n.retryIf,a=n.retryWith,i=n.initialDelayMs||1e3,u=n.maxDelayMs||15e3,y=n.maxNumberAttempts||2,c=n.randomDelay||!0;return function(n){var f=n.forward;return function(n){var l=r.share(n),p=r.makeSubject(),m=p.source,s=p.next,k=r.mergeMap((function(n){var o=n.key,a=n.context,y=(a.retryCount||0)+1,f=a.retryDelay||i,p=Math.random()+1.5;c&&f*p<u&&(f*=p);var m=r.filter((function(r){return("query"===r.kind||"teardown"===r.kind)&&r.key===o}))(l);return r.takeUntil(m)(r.delay(f)(r.fromValue(e.makeOperation(n.kind,n,t({},n.context,{retryDelay:f,retryCount:y})))))}))(m);return r.filter((function(r){if(!r.error||!(o?o(r.error,r.operation):a||r.error.networkError))return!0;if(!((r.operation.context.retryCount||0)>=y-1)){var e=a?a(r.error,r.operation):r.operation;return!e||(s(e),!1)}return!0}))(r.share(f(r.merge([l,k]))))}}};
//# sourceMappingURL=urql-exchange-retry.min.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"urql-exchange-retry.min.js","sources":["../src/retryExchange.ts"],"sourcesContent":["import {\n makeSubject,\n share,\n pipe,\n merge,\n filter,\n fromValue,\n delay,\n mergeMap,\n takeUntil,\n} from 'wonka';\nimport {\n makeOperation,\n Exchange,\n Operation,\n CombinedError,\n OperationResult,\n} from '@urql/core';\nimport { sourceT } from 'wonka/dist/types/src/Wonka_types.gen';\n\nexport interface RetryExchangeOptions {\n initialDelayMs?: number;\n maxDelayMs?: number;\n randomDelay?: boolean;\n maxNumberAttempts?: number;\n /** Conditionally determine whether an error should be retried */\n retryIf?: (error: CombinedError, operation: Operation) => boolean;\n /** Conditionally update operations as they're retried (retryIf can be replaced with this) */\n retryWith?: (\n error: CombinedError,\n operation: Operation\n ) => Operation | null | undefined;\n}\n\nexport const retryExchange = ({\n initialDelayMs,\n maxDelayMs,\n randomDelay,\n maxNumberAttempts,\n retryIf,\n retryWith,\n}: RetryExchangeOptions): Exchange => {\n const MIN_DELAY = initialDelayMs || 1000;\n const MAX_DELAY = maxDelayMs || 15000;\n const MAX_ATTEMPTS = maxNumberAttempts || 2;\n const RANDOM_DELAY = randomDelay || true;\n\n return ({ forward, dispatchDebug }) => ops$ => {\n const sharedOps$ = pipe(ops$, share);\n const {\n source: retry$,\n next: nextRetryOperation,\n } = makeSubject<Operation>();\n\n const retryWithBackoff$ = pipe(\n retry$,\n mergeMap((op: Operation) => {\n const { key, context } = op;\n const retryCount = (context.retryCount || 0) + 1;\n let delayAmount = context.retryDelay || MIN_DELAY;\n\n const backoffFactor = Math.random() + 1.5;\n // if randomDelay is enabled and it won't exceed the max delay, apply a random\n // amount to the delay to avoid thundering herd problem\n if (RANDOM_DELAY && delayAmount * backoffFactor < MAX_DELAY) {\n delayAmount *= backoffFactor;\n }\n\n // We stop the retries if a teardown event for this operation comes in\n // But if this event comes through regularly we also stop the retries, since it's\n // basically the query retrying itself, no backoff should be added!\n const teardown$ = pipe(\n sharedOps$,\n filter(op => {\n return (\n (op.kind === 'query' || op.kind === 'teardown') && op.key === key\n );\n })\n );\n\n dispatchDebug({\n type: 'retryAttempt',\n message: `The operation has failed and a retry has been triggered (${retryCount} / ${MAX_ATTEMPTS})`,\n operation: op,\n data: {\n retryCount,\n },\n });\n\n // Add new retryDelay and retryCount to operation\n return pipe(\n fromValue(\n makeOperation(op.kind, op, {\n ...op.context,\n retryDelay: delayAmount,\n retryCount,\n })\n ),\n delay(delayAmount),\n // Stop retry if a teardown comes in\n takeUntil(teardown$)\n );\n })\n );\n\n const result$ = pipe(\n merge([sharedOps$, retryWithBackoff$]),\n forward,\n share,\n filter(res => {\n // Only retry if the error passes the conditional retryIf function (if passed)\n // or if the error contains a networkError\n if (\n !res.error ||\n (retryIf\n ? !retryIf(res.error, res.operation)\n : !retryWith && !res.error.networkError)\n ) {\n return true;\n }\n\n const maxNumberAttemptsExceeded =\n (res.operation.context.retryCount || 0) >= MAX_ATTEMPTS - 1;\n\n if (!maxNumberAttemptsExceeded) {\n const operation = retryWith\n ? retryWith(res.error, res.operation)\n : res.operation;\n if (!operation) return true;\n\n // Send failed responses to be retried by calling next on the retry$ subject\n // Exclude operations that have been retried more than the specified max\n nextRetryOperation(operation);\n return false;\n }\n\n dispatchDebug({\n type: 'retryExhausted',\n message:\n 'Maximum number of retries has been reached. No further retries will be performed.',\n operation: res.operation,\n });\n\n return true;\n })\n ) as sourceT<OperationResult>;\n\n return result$;\n };\n};\n"],"names":["MIN_DELAY","initialDelayMs","MAX_DELAY","MAX_ATTEMPTS","RANDOM_DELAY","retryWithBackoff$","retryCount","op","context","delayAmount","retryDelay","backoffFactor","filter","kind","error"],"mappings":"gTA0CQA,EAAYC,YACZC,wBACAC,qBACAC,iJASEC,+CAIIC,EAAUC,EAAGC,QACfC,GAAcD,EAAQE,YAAcV,KAElCW,+DAcaC,QAAZ,YAJQ,mBAAAC,6IAwBTP,EAHWA,4DA0BRQ,mLAbA"}

View File

@@ -0,0 +1,2 @@
import{share as r,makeSubject as t,mergeMap as e,filter as n,takeUntil as o,delay as a,fromValue as i,merge as u}from"wonka";import{makeOperation as y}from"@urql/core";function c(){return(c=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}function f(f){var p=f.retryIf,l=f.retryWith,m=f.initialDelayMs||1e3,v=f.maxDelayMs||15e3,s=f.maxNumberAttempts||2,d=f.randomDelay||!0;return function(f){var k=f.forward;return function(f){var x=r(f),h=t(),w=h.source,D=h.next,b=e((function(r){var t=r.key,e=r.context,u=(e.retryCount||0)+1,f=e.retryDelay||m,p=Math.random()+1.5;d&&f*p<v&&(f*=p);var l=n((function(r){return("query"===r.kind||"teardown"===r.kind)&&r.key===t}))(x);return o(l)(a(f)(i(y(r.kind,r,c({},r.context,{retryDelay:f,retryCount:u})))))}))(w);return n((function(r){if(!r.error||!(p?p(r.error,r.operation):l||r.error.networkError))return!0;if(!((r.operation.context.retryCount||0)>=s-1)){var t=l?l(r.error,r.operation):r.operation;return!t||(D(t),!1)}return!0}))(r(k(u([x,b]))))}}}export{f as retryExchange};
//# sourceMappingURL=urql-exchange-retry.min.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,85 @@
import { share as r, makeSubject as e, mergeMap as t, filter as n, takeUntil as a, delay as o, fromValue as i, merge as u } from "wonka";
import { makeOperation as c } from "@urql/core";
function _extends() {
return (_extends = Object.assign || function(r) {
for (var e = 1; e < arguments.length; e++) {
var t = arguments[e];
for (var n in t) {
if (Object.prototype.hasOwnProperty.call(t, n)) {
r[n] = t[n];
}
}
}
return r;
}).apply(this, arguments);
}
function retryExchange(s) {
var y = s.retryIf;
var p = s.retryWith;
var v = s.initialDelayMs || 1e3;
var f = s.maxDelayMs || 15e3;
var d = s.maxNumberAttempts || 2;
var h = s.randomDelay || !0;
return function(s) {
var m = s.forward;
var x = s.dispatchDebug;
return function(s) {
var l = r(s);
var g = e();
var E = g.source;
var b = g.next;
var D = t((function(r) {
var e = r.key;
var t = r.context;
var u = (t.retryCount || 0) + 1;
var s = t.retryDelay || v;
var y = Math.random() + 1.5;
if (h && s * y < f) {
s *= y;
}
var p = n((function(r) {
return ("query" === r.kind || "teardown" === r.kind) && r.key === e;
}))(l);
"production" !== process.env.NODE_ENV && x({
type: "retryAttempt",
message: "The operation has failed and a retry has been triggered (" + u + " / " + d + ")",
operation: r,
data: {
retryCount: u
},
source: "retryExchange"
});
return a(p)(o(s)(i(c(r.kind, r, _extends({}, r.context, {
retryDelay: s,
retryCount: u
})))));
}))(E);
return n((function(r) {
if (!(r.error && (y ? y(r.error, r.operation) : p || r.error.networkError))) {
return !0;
}
if (!((r.operation.context.retryCount || 0) >= d - 1)) {
var e = p ? p(r.error, r.operation) : r.operation;
if (!e) {
return !0;
}
b(e);
return !1;
}
"production" !== process.env.NODE_ENV && x({
type: "retryExhausted",
message: "Maximum number of retries has been reached. No further retries will be performed.",
operation: r.operation,
source: "retryExchange"
});
return !0;
}))(r(m(u([ l, D ]))));
};
};
}
export { retryExchange };
//# sourceMappingURL=urql-exchange-retry.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,65 @@
{
"name": "@urql/exchange-retry",
"version": "0.3.0",
"description": "An exchange for operation retry support in urql",
"sideEffects": false,
"homepage": "https://formidable.com/open-source/urql/docs/",
"bugs": "https://github.com/FormidableLabs/urql/issues",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/FormidableLabs/urql.git",
"directory": "exchanges/retry"
},
"keywords": [
"urql",
"graphql client",
"formidablelabs",
"exchanges",
"retry"
],
"main": "dist/urql-exchange-retry",
"module": "dist/urql-exchange-retry.mjs",
"types": "dist/types/index.d.ts",
"source": "src/index.ts",
"exports": {
".": {
"import": "./dist/urql-exchange-retry.mjs",
"require": "./dist/urql-exchange-retry.js",
"types": "./dist/types/index.d.ts",
"source": "./src/index.ts"
},
"./package.json": "./package.json"
},
"files": [
"LICENSE",
"CHANGELOG.md",
"README.md",
"dist/"
],
"scripts": {
"test": "jest",
"clean": "rimraf dist",
"check": "tsc --noEmit",
"lint": "eslint --ext=js,jsx,ts,tsx .",
"build": "rollup -c ../../scripts/rollup/config.js",
"prepare": "node ../../scripts/prepare/index.js",
"prepublishOnly": "run-s clean build"
},
"jest": {
"preset": "../../scripts/jest/preset"
},
"devDependencies": {
"graphql": "^15.4.0"
},
"peerDependencies": {
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
},
"dependencies": {
"@urql/core": ">=2.3.1",
"wonka": "^4.0.14"
},
"publishConfig": {
"access": "public"
}
}