Snapshot Plugin
💡
This page is currently under construction and expected to change. Please feel free to reach out to us directly in case you are having any troubles.
The snapshot
plugin allows applying snapshot for development usage.
The snapshot plugin writes the responses of your remote data source to your file system and then uses it instead of re-fetching it every time. It’s also helpful because you can easily manipulate your data manually and see how your API mesh responds.
To get started with this plugin, install it:
npm i @graphql-mesh/plugin-snapshot
Then, add it to your plugins:
mesh.config.ts
import useSnapshot from '@graphql-mesh/plugin-snapshot'
import { defineConfig } from '@graphql-mesh/serve-cli'
export const serveConfig = defineConfig({
plugins: pluginCtx => [
useSnapshot({
...pluginCtx,
// You can provide a custom condition to enable/disable the plugin
if: () => process.env.NODE_ENV === 'development',
// The directory where the snapshots will be stored
outputDir: '__snapshots__',
// The origins to apply the snapshot
apply: ['https://my-remote-api.com/*']
})
]
})
The following snapshot will work if you are in a development environment (see the if
command).
To modify your snapshots and change the responses, go to __snapshots__
and modify the responses
under those files.