Files
DefinitelyTyped/types/graphql-resolve-batch/graphql-resolve-batch-tests.ts
nayni de71e26019 graphql-resolve-batch: remove namespace and array-type tslint rule
- Restructured the tests to not use namespaces as a result
- Promise return becomes an Array because its a complex type
2018-02-17 00:16:30 +01:00

94 lines
2.1 KiB
TypeScript

import { createBatchResolver, ResolverFunction } from "graphql-resolve-batch";
interface SomeTestSource {
someSourceProp: string;
}
interface SomeTestArgs {
someArg: string;
}
interface SomeTestContext {
someContextProp: string;
}
interface SomeTestResult {
someTestResultProp: string;
}
const withSourceAndResultTyped = createBatchResolver<
SomeTestSource,
SomeTestResult
>((sources, _, __) => {
return sources.map(source => {
const res: SomeTestResult = {
someTestResultProp: ""
};
return res;
});
});
const withSourceAndResultTypedAsPromise = createBatchResolver<
SomeTestSource,
SomeTestResult
>((sources, _, __) => {
// $ExpectType ReadonlyArray<SomeTestSource>
const verifySources = sources;
return sources.map(source => {
return new Promise<SomeTestResult>(resolve => {
const res: SomeTestResult = {
someTestResultProp: ""
};
resolve(res);
});
});
});
const withSourceAndArgsAndResultTyped = createBatchResolver<
SomeTestSource,
SomeTestResult,
SomeTestArgs
>((sources, args, _) => {
// $ExpectType ReadonlyArray<SomeTestSource>
const verifySources = sources;
// $ExpectType string
const verifyArgs = args.someArg;
return sources.map(source => {
return new Promise<SomeTestResult>(resolve => {
const res: SomeTestResult = {
someTestResultProp: ""
};
resolve(res);
});
});
});
const withSourceAndArgsAndContextTyped = createBatchResolver<
SomeTestSource,
SomeTestResult,
SomeTestArgs,
SomeTestContext
>((sources, args, context) => {
// $ExpectType ReadonlyArray<SomeTestSource>
const verifySources = sources;
// $ExpectType string
const verifyArgs = args.someArg;
// $ExpectType string
const verifyContext = context.someContextProp;
return sources.map(source => {
return new Promise<SomeTestResult>(resolve => {
const res: SomeTestResult = {
someTestResultProp: ""
};
resolve(res);
});
});
});