尝试将 typescript 与 graphql-resolvers 一起使用
使用 graphql-resolvers 第一个 getSample 输入正确并且可以工作,但第二个不喜欢 combineResolvers 的返回值并引发类型错误:(我一次尝试一个)
const resolver: Resolvers = {
Query: {
getSample:async (_parent, _args, {},) => {
return sampleData
}
},
};
const resolver2: Resolvers = {
Query: {
getSample: combineResolvers(
isAdmin,
async (_parent, _args, {},) => {
return sampleData
}
),
},
};
export default resolver2
错误:
Type 'IFieldResolver<{}, any, {}, any>' is not assignable to type 'Resolver<any, {}, any, {}> | undefined'.
Type 'IFieldResolver<{}, any, {}, any>' is not assignable to type 'ResolverFn<any, {}, any, {}>'.
Types of parameters 'info' and 'info' are incompatible.
Type 'GraphQLResolveInfo' is not assignable to type 'GraphQLResolveInfo & { mergeInfo?: MergeInfo | undefined; }'.
Type 'import("/Users/dandodd/Dev/codegen-test/node_modules/graphql/type/definition").GraphQLResolveInfo' is not assignable to type 'import("/Users/dandodd/Dev/codegen-test/node_modules/@types/graphql-resolvers/node_modules/graphql/type/definition").GraphQLResolveInfo'.
Types of property 'returnType' are incompatible.
Type 'import("/Users/dandodd/Dev/codegen-test/node_modules/graphql/type/definition").GraphQLOutputType' is not assignable to type 'import("/Users/dandodd/Dev/codegen-test/node_modules/@types/graphql-resolvers/node_modules/graphql/type/definition").GraphQLOutputType'.
Type 'GraphQLScalarType' is not assignable to type 'GraphQLOutputType'.
Type 'GraphQLScalarType' is missing the following properties from type 'GraphQLEnumType': getValues, getValue
28 getSample: combineResolvers(
~~~~~~~~~
src/gen-types.ts:190:3
190 getSample?: Resolver<Maybe<ResolversTypes['Sample']>, ParentType, ContextType>;
我可以转换 combineResolvers 的返回值吗