UNPKG

graphql-yoga

Version:
34 lines (33 loc) • 1.31 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, }, code: 'BAD_REQUEST', }, }); } if (requestParserResult.length > limit) { throw new GraphQLError(`Batching is limited to ${limit} operations per request.`, { extensions: { http: { status: 413, }, code: 'BAD_REQUEST', }, }); } } }, }; }, }; }