Skip to content

[TypeScript Resolvers] feat: Generate Interface types without field resolvers #2194

Open
@rynobax

Description

@rynobax

Is your feature request related to a problem? Please describe.
When attempting to generate types for an existing graphql server, I am having trouble getting the generated types for interfaces to match my implementation.

On my server I only specify a __resolveType resolver for my interface type, and let the implementing types provide the revolvers for the shared fields. However, when I generate types, the interface type requires that a resolver for all fields be provided.

Example
interface Animal {
  color: String!
}

type Dog implements Animal {
  color: String!
  bark: String!
}

type Cat implements Animal {
  color: String!
  meow: String!
}
const resolvers: Resolvers = {
  Cat: {
    color: e => e.color,
    meow: e => e.noise,
  },
  Dog: {
    color: e => e.color,
    bark: e => e.noise,
  },
  Animal: {
    __resolveType: e => (e.dog ? "Dog" : "Cat")
    // Property 'color' is missing in type '{ __resolveType: () => "Cat"; }' but required in type 'AnimalResolvers<any, Animal>'
  },

Describe the solution you'd like

I would like to specify in my configuration that I would like interface resolver types to only require a __resolveType field.

I would be happy to work on adding the functionality if I could get some confirmation this is a feature worth adding, and not just me doing something wrong 😄 .

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions