-
-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] Resolvers for interfaces #260
Comments
Or alternatively a way to compose resolvers @Resolver()
class TestResolver {
@FieldResolver()
fullName(@Root() test: Test) {
return test.firstName + test.lastName
}
}
@Resolver(of => Test2)
class Test2Resolver extends TestResolver {}
... |
I've always treated GraphQL interface like a normal TS interface, that is pure abstract and doesn't have an implementation. I thought that it's better to just use a base object type for fields with resolver and args and just extend them. @ObjectType()
class Person {
@Field()
age: number;
}
@ObjectType()
class Student extends Person {
@Field()
universityName: string;
} Also, mixing the extending class type is prohibited - your object type can't extend an interface type:
When Inheriting resolvers looks like a non standard solution that has to be handled specially: |
@19majkel94 How about allowing for composition of resolvers at the bare minimum? Doesn't go against the @InterfaceType()
class Test {
@Field() firstName: string
@Field() lastName: string
@Field() fullName: string
}
@ObjectType({ implements: Test })
class Test2 extends Test {}
@ObjectType({ implements: Test })
class Test3 extends Test {}
@Resolver()
class TestResolver {
@FieldResolver()
fullName(@Root() test: Test) {
return test.firstName + test.lastName
}
}
@Resolver(of => Test2)
class Test2Resolver extends TestResolver {}
@Resolver(of => Test3)
class Test3Resolver extends TestResolver {} |
Have you tried that?
It's perfectly legal to have a field resolver in base resolver class: |
ah didn't know that was possible thanks |
As Of course after the #261 arrives. |
@MichalLytek Not having this breaks paginating any field which is an interface type (w/ multiple implementations) in relay. Relay only allows paginating a single connection within a fragment. If you can't define the connection on the interface type then you can't paginate it. Side note; in the spirit of getting this rolled with some priority, would donating some money help? I don't have time to roll it myself right now and it seems like you're not satisfied with the implementation @kl4n4 did. |
@chrisdostert If you need this urgently, you can just use his branch of the fork he made. My priority is |
Closed by #579, released in @samdenty @chrisdostert @justinmchase @hyperloris @dmks |
@MichalLytek Ok cool, so you can define the resolver for the field either on the interface itself or on the resolver? So yeah that seems like it would work perfect because I would need access to services and the resolver will be able to have service dependencies resolved I believe. So that all looks great! |
Is your feature request related to a problem? Please describe.
Currently resolvers can only be applied to
ObjectTypes
Describe the solution you'd like
If an
InterfaceType
is specified in the params to a resolver, all@FieldResolvers
on the interface will apply to allObjectType
implementations.If a resolver for an
ObjectType
already has aFieldResolver
for a select field, it should use theObjectType
's definition (instead of theInterfaceType
)The text was updated successfully, but these errors were encountered: