-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
GraphQL interface type and class extending support #6
Comments
@4F2E4A2E I've only created the task issue but I haven't thought about the API design and use cases yet. @GraphQLInterfaceType()
export abstract class Character {
@Field(type => ID)
id: string;
@Field()
name: string;
@Field(type => Character)
friends: Character[];
@Field(type => Episode)
appearsIn: Episode[];
}
@GraphQLObjectType()
export class Human implements Character {
@Field(type => ID)
id: string;
@Field()
name: string;
@Field(type => Character)
friends: Character[];
@Field(type => Episode)
appearsIn: Episode[];
@Field(type => Starship)
starships: Starship[];
@Field(type => Int)
totalCredits: number;
}
@GraphQLObjectType()
class Droid implements Character {
@Field(type => ID)
id: string;
@Field()
name: string;
@Field(type => Character)
friends: Character[];
@Field(type => Episode)
appearsIn: Episode[];
@Field({ nullable: true })
primaryFunction: string;
} It is possible to do this without repeating the decorators: @GraphQLObjectType({ implements: Character })
export class Human implements Character {
id: string;
name: string;
friends: Character[];
appearsIn: Episode[];
@Field(type => Starship)
starships: Starship[];
@Field(type => Int)
totalCredits: number;
} However I'm not convinced it's a good choose. I prefer explicitness but decorator duplication means N times doing the same changes in every implementation so it's easy to make a mistake, but the correctness of interface implementation might be checked on schema-build time of course. |
I prefer explicitness too and the fact that you can duplicate decorators, but don't have too is just great and very useful in many cases, so thanks for that! 👍 |
This is maybe worth noticing: graphql/graphql-js#1235 |
GraphQLInterface
The text was updated successfully, but these errors were encountered: