UNPKG

graphql-yoga

Version:
32 lines (31 loc) 1.19 kB
import { GraphQLError } from 'graphql'; export function useLimitBatching(limit) { return { onRequestParse() { return { onRequestParseDone({ requestParserResult }) { if (Array.isArray(requestParserResult)) { if (!limit) { throw new GraphQLError(`Batching is not supported.`, { extensions: { http: { status: 400, }, }, }); } if (requestParserResult.length > limit) { throw new GraphQLError(`Batching is limited to ${limit} operations per request.`, { extensions: { http: { status: 413, }, }, }); } } }, }; }, }; }