mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
- Restructured the tests to not use namespaces as a result - Promise return becomes an Array because its a complex type
94 lines
2.1 KiB
TypeScript
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);
|
|
});
|
|
});
|
|
});
|