urql6-custom-scalars-exchange
v1.0.0
Published
urql exchange to allow mapping of custom scalar types
Downloads
2
Readme
urql6-custom-scalars-exchange
urql exchange to allow mapping of custom scalar types
Example
bun add urql6-custom-scalars-exchangeor
npm install --save urql6-custom-scalars-exchangeDefine a custom scalar like Json in your schema via:
scalar JsonDownload 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 'urql6-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.
bun 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.
bun 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).
bun 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 is a fork of Christian Lentfort's exchange.
