@omnigraph/odata
Version:
24 lines (23 loc) • 955 B
JavaScript
import urljoin from 'url-join';
import { Request } from '@whatwg-node/fetch';
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
import { getUrlString } from '../utils/getUrlString.js';
export function createEntitySetCountResolver({ endpoint, entitySetName, dataloaderFactory, headersFactory, }) {
return function entitySetCountResolver(root, args, context, info) {
const url = new URL(endpoint);
url.href = urljoin(url.href, `/${entitySetName}/$count`);
const urlString = getUrlString(url);
const method = 'GET';
const request = new Request(urlString, {
method,
headers: headersFactory({
root,
args,
context,
info,
env: process.env,
}, method),
});
return handleMaybePromise(() => dataloaderFactory(context).load(request), response => response.text());
};
}