Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@urql/exchange-populate

Package Overview
Dependencies
Maintainers
19
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@urql/exchange-populate

An exchange that automaticcally populates the mutation selection body

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
19
Created
Source

@urql/exchange-populate

populate is an exchange for auto-populating fields in your mutations.

Read more about the populateExchange on our docs!

Quick Start Guide

First install @urql/exchange-populate alongside urql:

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

You'll then need to add the populateExchange, that this package exposes.

import { createClient, cacheExchange, fetchExchange } from 'urql';
import { populateExchange } from '@urql/exchange-populate';

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

The schema option is the introspection result for your backend graphql schema, more information about how to get your schema can be found in the "Schema Awareness" Page of the Graphcache documentation..

Example usage

Consider the following queries which have been requested in other parts of your application:

# Query 1
{
  todos {
    id
    name
  }
}

# Query 2
{
  todos {
    id
    createdAt
  }
}

Without the populateExchange you may write a mutation like the following which returns a newly created todo item:

# Without populate
mutation addTodo(id: ID!) {
  addTodo(id: $id) {
    id        # To update Query 1 & 2
    name      # To update Query 1
    createdAt # To update Query 2
  }
}

By using populateExchange, you no longer need to manually specify the selection set required to update your other queries. Instead you can just add the @populate directive.

# With populate
mutation addTodo(id: ID!) {
  addTodo(id: $id) @populate
}

Note: The above two mutations produce an identical GraphQL request.

Keywords

FAQs

Package last updated on 10 May 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc