我使用apollo-graphql创建了一个使用graphql-iso-date的“帐户”类型和随附的解析器。配置导致以下错误,关于原因和解决方案的任何想法?
在下面的代码中,将typedef组合到特定typedef模块的集合中。
Type'{Date:GraphQLScalarType; DateTime:GraphQLScalarType;时间: GraphQLScalarType; } | {查询:AccountQueryResolver; }' 不是 可分配给类型'IResolvers | IResolvers [] | 未定义”。
类型'{日期:GraphQLScalarType;约会时间: GraphQLScalarType;时间:GraphQLScalarType; }'不可分配给 输入“ IResolvers | IResolvers [] |未定义”。
类型'{日期:GraphQLScalarType; DateTime:GraphQLScalarType;时间: GraphQLScalarType; }”不可分配给“ IResolvers”类型。属性“日期”与索引签名不兼容
类型'GraphQLScalarType'不能分配给类型'(()=> any)| GraphQLScalarType | IEnumResolver | IResolverObject | IResolverOptions”。
类型'GraphQLScalarType' 不能分配给'IResolverObject'类型。
“ GraphQLScalarType”类型缺少索引签名。
TypeDefs集合
import CustomScalarTypeDefs from "./custom";
import QueryTypeDefs from "./query";
import AccountTypeDefs from "./account";
const TypeDefs = [CustomScalarTypeDefs, QueryTypeDefs, AccountTypeDefs];
export default TypeDefs;
自定义标量TypeDefs
import { gql } from "apollo-server-express";
const customScalarTypeDefs = gql`
scalar Date
scalar DateTime
scalar Time
`;
export default customScalarTypeDefs;
查询TypeDefs
import { gql } from "apollo-server-express";
const QueryTypeDefs = gql`
type Query {
account(id: String!): Account
}
`;
export default QueryTypeDefs;
自定义标量解析器
import { GraphQLDate, GraphQLDateTime, GraphQLTime } from "graphql-iso-date";
const CustomScalarResolver = {
Date: GraphQLDate,
DateTime: GraphQLDateTime,
Time: GraphQLTime
};
export default CustomScalarResolver;
帐户解析器
import { QueryById } from "./signatures";
import Account, { AccountModel, AccountPayload } from "../../models/account";
interface AccountQueryResolver {
account: (_: never, req: QueryById) => Promise<AccountModel | null>;
createAccount: (
parent: Account | null,
{ entity, name }: AccountPayload
) => Promise<AccountModel | null>;
}
const accountResolver: AccountQueryResolver = {
account: (_, { id }): Promise<AccountModel | null> => {
return Account.findOne({ _id: id }).exec();
},
createAccount: (_, { entity, name }): Promise<AccountModel | null> => {
return Account.create({ entity, name });
}
};
export default accountResolver;