urql-custom-scalars-exchange
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

urql-custom-scalars-exchange

urql exchange to allow mapping of custom scalar types

Example

yarn add urql-custom-scalars-exchange

or

npm install --save 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 '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

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.

Readme

Keywords

none

Package Sidebar

Install

npm i urql-custom-scalars-exchange

Weekly Downloads

1,096

Version

1.0.1

License

MIT

Unpacked Size

101 kB

Total Files

23

Last publish

Collaborators

  • clentfort