🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@urql/exchange-context

Package Overview
Dependencies
Maintainers
6
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@urql/exchange-context

An exchange for setting (a)synchronous operation-context in urql

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
12K
93.71%
Maintainers
6
Weekly downloads
 
Created
Source

@urql/exchange-context

An exchange for setting operation context in urql

@urql/exchange-context is an exchange for the urql GraphQL client which can set the operation context both synchronously as well as asynchronously

Quick Start Guide

First install @urql/exchange-context alongside urql:

yarn add @urql/exchange-context
# or
npm install --save @urql/exchange-context

You'll then need to add the contextExchange, that this package exposes, to your urql Client, the positioning of this exchange depends on whether you set an async setter or not. If you set an async context-setter it's best placed after all the synchronous exchanges (in front of the fetchExchange).

import { createClient, cacheExchange, fetchExchange } from 'urql';
import { contextExchange } from '@urql/exchange-context';

const client = createClient({
  url: 'http://localhost:1234/graphql',
  exchanges: [
    cacheExchange,
    contextExchange({
      getContext: async operation => {
        const token = await getToken();
        return { ...operation.context, headers: { authorization: token } };
      },
    }),
    fetchExchange,
  ],
});

Keywords

urql

FAQs

Package last updated on 09 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts