TypeScriptでのGraphQL: リゾルバーの型エラー
apollo-graphqlを使用して、「account」タイプとgraphql-iso-dateを使用する関連するリゾルバーを作成しました。この構成により以下のエラーが発生します。原因と解決方法について何かアイデアはありますか?
以下に含まれるコードでは、typedef は特定の typedef モジュールからのコレクションにまとめられています。
タイプ '{ Date: GraphQLScalarType; DateTime: GraphQLScalarType; Time: GraphQLScalarType; } | { Query: AccountQueryResolver; }' はタイプ 'IResolvers | IResolvers[] | undefined' に割り当てることができません。
タイプ '{ Date: GraphQLScalarType; DateTime: GraphQLScalarType; Time: GraphQLScalarType; }' はタイプ 'IResolvers | IResolvers[] | undefined' に割り当てることができません。
タイプ '{ Date: GraphQLScalarType; DateTime: GraphQLScalarType; Time: GraphQLScalarType; }' はタイプ 'IResolvers' に割り当て可能ではありません。プロパティ 'Date' はインデックスシグネチャと互換性がありません
型 '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;
カスタムスカラ型定義
import { gql } from "apollo-server-express";
const customScalarTypeDefs = gql`
scalar Date
scalar DateTime
scalar Time
`;
export default customScalarTypeDefs;
クエリ型定義
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;