Skip to content
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

Closed
2 tasks done
MichalLytek opened this issue Jan 27, 2018 · 3 comments
Closed
2 tasks done

GraphQL interface type and class extending support #6

MichalLytek opened this issue Jan 27, 2018 · 3 comments
Labels
Enhancement 🆕 New feature or request
Milestone

Comments

@MichalLytek
Copy link
Owner

MichalLytek commented Jan 27, 2018

  • support for GraphQLInterface
  • support for extending classes with definitions
@MichalLytek
Copy link
Owner Author

Does this mean that this issue #6 is obsolete? What is planed to support there?

@4F2E4A2E
No, this task is about support interfaces in GraphQL schema:
http://graphql.org/learn/schema/#interfaces

I've only created the task issue but I haven't thought about the API design and use cases yet.
However I think it will look like this:

@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.
What do you think?

@MichalLytek MichalLytek modified the milestones: 1.0.0 release, Beta release Feb 7, 2018
@4F2E4A2E
Copy link
Contributor

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! 👍

@MichalLytek MichalLytek changed the title Union and interfaces support GraphQL interface type and class extending support Feb 15, 2018
@4F2E4A2E
Copy link
Contributor

This is maybe worth noticing: graphql/graphql-js#1235

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement 🆕 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants