Fetch Plugin

The fetch plugin is both a very simple plugin and a critical one to villus inner workings. Because villus is built using a pipeline of plugins that perform some processing on a GraphQL operation.

The fetch plugin is the one that actually executes your queries and mutations against the GraphQL API which is why it is very important to either have a fetch or batch plugins or any similar plugins you may write on your own.


The fetch plugin is one of the default plugins that are pre-configured with any villus client unless specified otherwise


You can customize a few aspects of the fetch plugin:

import { useClient, fetch } from 'villus';

const fetchPlugin = fetch({
  // plugin options...

  use: [fetchPlugin],

The available options are:

fetchtypeof window.fetchPass this option if you plan to be specific about the fetch polyfill that will be used, by default it tries to find window.fetch on the browser or global.fetch on Node.js depending on the execution environment


You can check the source code for the fetch plugin and use it as a reference to build your own