GraphQL med Typescript: Resolver-typfel


Med hjälp av apollo-graphql har jag skapat en "account"-typ och tillhörande resolver som använder graphql-iso-date. Konfigurationen resulterar i följande fel, några idéer på orsaken och lösningen?

I koden som inkluderas nedan kombineras typedefs till en samling från specifika typedef-moduler.

Typen '{ Date: GraphQLScalarType; DateTime: GraphQLScalarType; Time: GraphQLScalarType; } | { Query: AccountQueryResolver; }' går inte att tilldela typen 'IResolvers | IResolvers[] | undefined'.

Typen ''{ Date: GraphQLScalarType; DateTime: GraphQLScalarType; Time: GraphQLScalarType; }'' kan inte tilldelas till typen ''IResolvers | IResolvers[] | undefined''.

Typen ''{ Date: GraphQLScalarType; DateTime: GraphQLScalarType; Time: GraphQLScalarType; }'' kan inte tilldelas typen ''IResolvers''. Egenskapen ''Date'' är inkompatibel med indexsignaturen

Typen 'GraphQLScalarType' kan inte tilldelas typen '(() => any) | GraphQLScalarType | IEnumResolver | IResolverObject | IResolverOptions'.

Typen 'GraphQLScalarType' kan inte tilldelas typen 'IResolverObject'.
Indexsignaturen saknas i typen 'GraphQLScalarType'.

TypeDefs-samling

import CustomScalarTypeDefs from "./custom";
import QueryTypeDefs from "./query";
import AccountTypeDefs from "./account";

const TypeDefs = [CustomScalarTypeDefs, QueryTypeDefs, AccountTypeDefs];

export default TypeDefs;

Egna skalartyper TypeDefs

import { gql } from "apollo-server-express";

const customScalarTypeDefs = gql`
  scalar Date
  scalar DateTime
  scalar Time
`;

export default customScalarTypeDefs;

Frågetypdefinitioner

import { gql } from "apollo-server-express";

const QueryTypeDefs = gql`
  type Query {
    account(id: String!): Account
  }
`;

export default QueryTypeDefs;

Anpassad Skalärupplösare

import { GraphQLDate, GraphQLDateTime, GraphQLTime } from "graphql-iso-date";

const CustomScalarResolver = {
  Date: GraphQLDate,
  DateTime: GraphQLDateTime,
  Time: GraphQLTime
};

export default CustomScalarResolver;

Kontoupplösare

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;