import { createBatchResolver, ResolverFunction } from "graphql-resolve-batch"; interface SomeTestSource { someSourceProp: string; } interface SomeTestArgs { someArg: string; } interface SomeTestContext { someContextProp: string; } interface SomeTestResult { someTestResultProp: string; } const batchFunction = (sources: ReadonlyArray) => { const someTestResult: SomeTestResult = { someTestResultProp: "Hello" }; return sources.map(source => someTestResult); }; const asyncBatchFunction = async (sources: ReadonlyArray) => { return new Promise(resolve => { const res = [ { someTestResultProp: "" } ]; resolve(res); }); }; const asyncBatchFunctionWhenTReturnIsArray = async ( sources: ReadonlyArray ) => { const sourceBatches = sources.map(() => { return new Promise(resolve => { const res = [ { someTestResultProp: "" } ]; resolve(res); }); }); return Promise.all(sourceBatches); }; // $ExpectType ResolverFunction const withSourceAndResultTyped = createBatchResolver< SomeTestSource, SomeTestResult >((sources, _, __) => { // $ExpectType ReadonlyArray const verifySources = sources; return batchFunction(sources); }); // $ExpectType ResolverFunction const withSourceAndResultTypedAsPromise = createBatchResolver< SomeTestSource, SomeTestResult >(async (sources, _, __) => { // $ExpectType ReadonlyArray const verifySources = sources; const result = await asyncBatchFunction(sources); return result; }); // $ExpectType ResolverFunction const withSourceAndArgsAndResultTyped = createBatchResolver< SomeTestSource, SomeTestResult, SomeTestArgs >(async (sources, args, _) => { // $ExpectType ReadonlyArray const verifySources = sources; // $ExpectType string const verifyArgs = args.someArg; const result = await asyncBatchFunction(sources); return result; }); // $ExpectType ResolverFunction const withSourceAndArgsAndContextTyped = createBatchResolver< SomeTestSource, SomeTestResult, SomeTestArgs, SomeTestContext >(async (sources, args, context, info) => { // $ExpectType ReadonlyArray const verifySources = sources; // $ExpectType string const verifyArgs = args.someArg; // $ExpectType string const verifyContext = context.someContextProp; // $ExpectType GraphQLResolveInfo const verifyInfo = info; const result = await asyncBatchFunction(sources); return result; }); // $ExpectType ResolverFunction const withResultIsArray = createBatchResolver( (sources, _, __) => { // $ExpectType ReadonlyArray const verifySources = sources; return asyncBatchFunctionWhenTReturnIsArray(sources); } );