UNPKG

@omnigraph/odata

Version:
24 lines (23 loc) 935 B
import urljoin from 'url-join'; import { mapMaybePromise } from '@graphql-tools/utils'; import { Request } from '@whatwg-node/fetch'; 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 mapMaybePromise(dataloaderFactory(context).load(request), response => response.text()); }; }