Support for property resolvers for interface types
See original GitHub issueI’m submitting a…
[x] Feature request
Current behavior
I would like to create a resolver for an interface type which has a property resolver
Expected behavior
I should be able to define a resolver for an interface type and add property resolvers for virtual fields on that resolver. It should have access to services via constructor injection, etc.
Minimal reproduction of the problem with instructions
@InterfaceType()
export class IExample {
}
@Resolver(of => IExample)
export class ExampleResolver {
constructor(
private readonly example: ExampleService
) { }
@ResolveProperty(type => Boolean)
public async foo(@Root() item: IExample) {
// this.example is available for this function
return false
}
}
What is the motivation / use case for changing the behavior?
If you have an interface type with multiple concrete types you want to be able to access it in gql like:
examples {
foo
}
Not
examples {
... on ConcreteType {
foo
}
}
Which it seems like right now the only way to do it is to promote the field to resolvers for each concrete type.
Environment
Nest version: ^6.7.2
For Tooling issues:
- Node version:
v12.8.0
- Platform:
linux
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Resolvers - Apollo GraphQL Docs
This object is called the resolver map. The resolver map has top-level fields that correspond to your schema's types (such as Query above)....
Read more >graphql - combining resolvers for interface and concrete types
For some reason I'm having a hard time figuring out how to combine resolvers for a GraphQL interface and a type that implements...
Read more >Resolvers – GraphQL Tools
Writing resolvers with graphql-tools. ... Unions and interfaces are great when you have fields that are in common between two types.
Read more >Resolvers | NestJS - A progressive Node.js framework
Recommended: define an interface instead of using any . Type is imported from the @nestjs/common package; The isAbstract: true property indicates that SDL...
Read more >Interfaces and inheritance - TypeGraphQL
The main idea of TypeGraphQL is to create GraphQL types based on TypeScript classes. In object-oriented programming it is common to create interfaces...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looking at this more, adding the field to the interface doesn’t help. I am getting a crash in
type-graphql
which I’m filing a bug over there for but I do think that this is a legitimate issue in this library and think this ticket should be re-opened.I think its legitimate because I am able to do this with graphql without using this library and it is documented in their documentation and it is a limitation of this library that this isn’t supported.
I think the example from the gql documentation for characters that @marcus-sa linked to is a good one, so this feature request / bug becomes how can I implement
Character.name
as a property resolver?You can’t query interfaces, you can only implement them.
EDIT: It seems like I’ve misunderstood your question. This is out of the scope (as it’s not supported in the GraphQL spec)