@graphql-mesh/plugin-operation-headers
Version:
20 lines (19 loc) • 616 B
JavaScript
import { getHeadersObj } from '@graphql-mesh/utils';
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
export function useOperationHeaders(factoryFn) {
return {
onFetch({ url, options, context, setOptions }) {
return handleMaybePromise(() => factoryFn({
url,
options,
context,
}), newHeaders => setOptions({
...options,
headers: {
...getHeadersObj(options.headers || {}),
...newHeaders,
},
}));
},
};
}