> Plugin for extend Graph. May use like computed.
npm install @graph-state/plugin-extend> Plugin for extend Graph. May use like computed.
``sh`
npm i @graph-state/core @graph-state/plugin-extend
or
`sh`
yarn add @graph-state/core @graph-state/plugin-extend
`jsx
import { createState } from '@graph-state/core';
import extendPlugin from '@graph-state/plugin-extend';
export const graphState = createState({
plugins: [
extendPlugin({
User: (cache, graph) => {
return {
...graph,
someProp: 'test'
}
}
}),
],
});
graphState.mutate({
_type: 'User',
_id: 'id'
})
graphState.resolve('User:id')
/**
* _type: 'User',
* _id: 'id'
* someProp: 'test'
*/
`
`jsx
export const graphState = createState({
plugins: [extendPlugin()],
});
graphState.extendGraph('User:test', (cache, graph) => graph)
`
`jsx
export const graphState = createState({
plugins: [extendPlugin()],
});
setTimeout(() => {
// Extend all User graphs and add extender for next updates.
graphState.declareExtendGraph('User', (cache, graph) => graph)
}, 1000)
``