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 executes your queries and mutations against the GraphQL API which is why it is very important to either have a fetch
or batch
plugin, or any similar plugins you may write on your own.
tip
The fetch plugin is one of the default plugins that are pre-configured with any villus client unless specified otherwise
Options
You can customize a few aspects of the fetch
plugin:
vue<script setup>
import { useClient, fetch } from 'villus';
const fetchPlugin = fetch({
// plugin options...
});
useClient({
use: [fetchPlugin],
});
</script>
The available options are:
Option | Type | Description |
---|---|---|
fetch | typeof window.fetch | Pass 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 |
Code
You can check the source code for the fetch
plugin and use it as a reference to build your own