Skip to content

Question: Splitting resolvers fails type check #305

@bglgwyng

Description

@bglgwyng

The following code passed type check. The definition of IResolvers is generated by mercurius-codegen.

const resolvers: IResolvers = {
  User: {
     // resolver code
  },
  Query,
  Mutation
}

I wanted to seperate the User resolver because it's quite large.

const User: UserResolvers = {
  // resolver code
}

const resolvers: IResolvers = {
  User,
  Query,
  Mutation
}

But then, the type check failed with this message.

Type '{ User: UserResolvers<MercuriusContext, User>; Query: QueryResolvers<MercuriusContext, {}>; Mutation: MutationResolvers<...>; }' is not assignable to type 'IResolvers<any, MercuriusContext>'.
  Property 'User' is incompatible with index signature.
    Type 'UserResolvers<MercuriusContext, User>' is not assignable to type 'GraphQLScalarType<unknown, unknown> | IEnumResolver | (() => any) | IResolverObject<any, MercuriusContext, any> | IResolverOptions<...> | undefined'.
      Type 'UserResolvers<MercuriusContext, User>' is not assignable to type 'IResolverObject<any, MercuriusContext, any>'.
        Property 'isTypeOf' is incompatible with index signature.
          Type 'IsTypeOfResolverFn<User, MercuriusContext>' is not assignable to type 'IResolverObject<any, MercuriusContext, any> | IResolverOptions<any, MercuriusContext, any> | IFieldResolver<...> | undefined'.
            Type 'IsTypeOfResolverFn<User, MercuriusContext>' is not assignable to type 'IFieldResolver<any, MercuriusContext, any>'.
              Types of parameters 'info' and 'context' are incompatible.
                Type 'MercuriusContext' is missing the following properties from type 'GraphQLResolveInfo': fieldName, fieldNodes, returnType, parentType, and 6 more.ts(2322)

When I switched UserResolvers to IResolvers["User"], the same message appeared.
How can I fix this problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions