@envelop/core
Version: 
This is the core package for Envelop. You can find a complete documentation here: https://github.com/graphql-hive/envelop
18 lines (17 loc) • 560 B
JavaScript
import { handleStreamOrSingleExecutionResult } from '../utils.js';
const makeHandleResult = (formatter) => ({ args, result, setResult, }) => {
    const modified = formatter(result, args);
    if (modified !== false) {
        setResult(modified);
    }
};
export const usePayloadFormatter = (formatter) => ({
    onExecute() {
        const handleResult = makeHandleResult(formatter);
        return {
            onExecuteDone(payload) {
                return handleStreamOrSingleExecutionResult(payload, handleResult);
            },
        };
    },
});