mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 21:31:12 +08:00
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
This commit is contained in:
@@ -1,129 +1,93 @@
|
||||
import { createBatchResolver, ResolverFunction } from "graphql-resolve-batch";
|
||||
|
||||
// Test cases split up in namespaces to test different type inference scenarios.
|
||||
|
||||
namespace WithSourceAndResult {
|
||||
interface SomeTestSource {
|
||||
someSourceProp: string;
|
||||
}
|
||||
|
||||
interface SomeTestResult {
|
||||
someTestResultProp: string;
|
||||
}
|
||||
|
||||
const verify = createBatchResolver<SomeTestSource, SomeTestResult>(
|
||||
(sources, _, __) => {
|
||||
return sources.map(source => {
|
||||
const res: SomeTestResult = {
|
||||
someTestResultProp: ""
|
||||
};
|
||||
|
||||
return res;
|
||||
});
|
||||
}
|
||||
);
|
||||
interface SomeTestSource {
|
||||
someSourceProp: string;
|
||||
}
|
||||
|
||||
namespace WithSourceAndResultAsPromise {
|
||||
interface SomeTestSource {
|
||||
someSourceProp: string;
|
||||
}
|
||||
|
||||
interface SomeTestResult {
|
||||
someTestResultProp: string;
|
||||
}
|
||||
|
||||
const verify = 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);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
interface SomeTestArgs {
|
||||
someArg: string;
|
||||
}
|
||||
|
||||
namespace WithSourceAndArgsAndResult {
|
||||
interface SomeTestSource {
|
||||
someSourceProp: string;
|
||||
}
|
||||
interface SomeTestContext {
|
||||
someContextProp: string;
|
||||
}
|
||||
|
||||
interface SomeTestArgs {
|
||||
someArg: string;
|
||||
}
|
||||
interface SomeTestResult {
|
||||
someTestResultProp: string;
|
||||
}
|
||||
|
||||
interface SomeTestResult {
|
||||
someTestResultProp: string;
|
||||
}
|
||||
const withSourceAndResultTyped = createBatchResolver<
|
||||
SomeTestSource,
|
||||
SomeTestResult
|
||||
>((sources, _, __) => {
|
||||
return sources.map(source => {
|
||||
const res: SomeTestResult = {
|
||||
someTestResultProp: ""
|
||||
};
|
||||
|
||||
const verify = createBatchResolver<
|
||||
SomeTestSource,
|
||||
SomeTestResult,
|
||||
SomeTestArgs
|
||||
>((sources, args, _) => {
|
||||
// $ExpectType ReadonlyArray<SomeTestSource>
|
||||
const verifySources = sources;
|
||||
// $ExpectType string
|
||||
const verifyArgs = args.someArg;
|
||||
return res;
|
||||
});
|
||||
});
|
||||
|
||||
return sources.map(source => {
|
||||
return new Promise<SomeTestResult>(resolve => {
|
||||
const res: SomeTestResult = {
|
||||
someTestResultProp: ""
|
||||
};
|
||||
const withSourceAndResultTypedAsPromise = createBatchResolver<
|
||||
SomeTestSource,
|
||||
SomeTestResult
|
||||
>((sources, _, __) => {
|
||||
// $ExpectType ReadonlyArray<SomeTestSource>
|
||||
const verifySources = sources;
|
||||
|
||||
resolve(res);
|
||||
});
|
||||
return sources.map(source => {
|
||||
return new Promise<SomeTestResult>(resolve => {
|
||||
const res: SomeTestResult = {
|
||||
someTestResultProp: ""
|
||||
};
|
||||
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
namespace WithSourceAndArgsAndContextAndResult {
|
||||
interface SomeTestSource {
|
||||
someSourceProp: string;
|
||||
}
|
||||
const withSourceAndArgsAndResultTyped = createBatchResolver<
|
||||
SomeTestSource,
|
||||
SomeTestResult,
|
||||
SomeTestArgs
|
||||
>((sources, args, _) => {
|
||||
// $ExpectType ReadonlyArray<SomeTestSource>
|
||||
const verifySources = sources;
|
||||
// $ExpectType string
|
||||
const verifyArgs = args.someArg;
|
||||
|
||||
interface SomeTestArgs {
|
||||
someArg: string;
|
||||
}
|
||||
return sources.map(source => {
|
||||
return new Promise<SomeTestResult>(resolve => {
|
||||
const res: SomeTestResult = {
|
||||
someTestResultProp: ""
|
||||
};
|
||||
|
||||
interface SomeTestContext {
|
||||
someContextProp: string;
|
||||
}
|
||||
|
||||
interface SomeTestResult {
|
||||
someTestResultProp: string;
|
||||
}
|
||||
|
||||
const verify = 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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
2
types/graphql-resolve-batch/index.d.ts
vendored
2
types/graphql-resolve-batch/index.d.ts
vendored
@@ -23,4 +23,4 @@ export type BatchResolveFunction<TSource, TArgs, TContext, TReturn> = (
|
||||
sources: ReadonlyArray<TSource>,
|
||||
args: TArgs,
|
||||
context: TContext
|
||||
) => TReturn[] | Promise<TReturn>[];
|
||||
) => TReturn[] | Array<Promise<TReturn>>;
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-namespace": false,
|
||||
"array-type": [true, "array"]
|
||||
}
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user