@atmina/urql-custom-scalars-exchange

中文文档
1.2.0发布于 2025/08/26MITTypeScriptESM + CJS零依赖近 30 天下载 9923

urql exchange to allow mapping of custom scalar types

原始使用文档
文档目录8 节
  1. Example
  2. FAQ
  3. Should this exchange be listed before or after the cache ex…
  4. Local Development
  5. npm start or yarn start
  6. npm run build or yarn build
  7. npm test or yarn test
  8. Acknowledgements

@atmina/urql-custom-scalars-exchange

urql exchange to allow mapping of custom scalar types

Example

yarn add @atmina/urql-custom-scalars-exchange

or

npm install --save @atmina/urql-custom-scalars-exchange

Define a custom scalar like Json in your schema via:

scalar Json

Download the introspection query from your endpoint. See the urql docs for a script to download the schema from your endpoint.

Configure the exchange like so

import customScalarsExchange from '@atmina/urql-custom-scalars-exchange';
import schema from '../schema.json';

const scalarsExchange = customScalarsExchange({
    schema: schema,
    scalars: {
        Json(value) {
            return JSON.parse(value);
        },
    },
});

Finally add the exchange to your urql client like so

const client = createClient({
    url: 'http://localhost:1234/graphql',
    exchanges: [dedupExchange, scalarsExchange, fetchExchange],
});

FAQ

Should this exchange be listed before or after the cache exchange?

This exchange should be listed before any cache exchange. Cache exchanges should represent the the data as returned by the endpoint.

Local Development

This project uses Corepack. Run corepack enable to enable it if you haven't already.

Below is a list of commands you will probably find useful.

npm start or yarn start

Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.

Your library will be rebuilt if you make edits.

npm run build or yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

npm test or yarn test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.

Acknowledgements

This project was bootstrapped with TSDX.

This project is a fork of Christian Lentfort's exchange.

版本与发布记录

@atmina/urql-custom-scalars-exchange 共发布 3 个版本,首次发布于 2024/09/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.0latest2025/08/261.2 年前
1.1.12024/11/222 年前
1.1.02024/09/182 年前

关于 @atmina/urql-custom-scalars-exchange 的常见问题

@atmina/urql-custom-scalars-exchange 是什么?

urql exchange to allow mapping of custom scalar types

如何安装 @atmina/urql-custom-scalars-exchange?

在项目目录运行 npm install @atmina/urql-custom-scalars-exchange,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@urql/core(^1.12.3 || ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0)、graphql(^15.3.0 || ^16.0.0)、wonka(^4.0.14 || ^6.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@atmina/urql-custom-scalars-exchange 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@atmina/urql-custom-scalars-exchange 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@atmina/urql-custom-scalars-exchange 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@atmina/urql-custom-scalars-exchange 可以商用吗?

@atmina/urql-custom-scalars-exchange 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@atmina/urql-custom-scalars-exchange 的下载量有多少?

根据 npm 官方下载统计,@atmina/urql-custom-scalars-exchange 在 2026/10/07 – 2026/11/05 这 30 天内被下载 9,923 次,日均约 331 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@atmina/urql-custom-scalars-exchange 还在维护吗?

最新版本 1.2.0 发布于 2025/08/26(1.2 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/09/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。