-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Proposal] Interface implementation violate "Don't Repeat Yourself" #500
Comments
@IvanGoncharov #335 still need to COPY the |
@yaquawa There are many reasons why we need interfaces in GraphQL type system. Can you please rewrite your proposal so it doesn't introduce breaking changes to GraphQL? |
@IvanGoncharov |
I agree that the current way requires more writing (sometimes what appears as copy & paste), however this is an intentional tradeoff because the type system definition language favors reading over writing. I think we've discussed Also, types which implement interfaces may be subtypes in which case it certainly is not copy and paste. Consider this contrived but valid example: interface Animal {
parent: Animal
}
type Dog implements Animal {
parent: Dog
} |
@leebyron I know I'm very very late to the party, so forgive me for commenting here. I agree with optimizing for reading and not writing, but I disagree that the current state is doing this, so I'd like to understand the decision better. Even on the reading side, avoiding this repetition would be an improvement IMO:
While the schema can be read directly by some people as a text file, I imagine (from my limited experience) that consumers usually either have tooling to explore the graphql schema (like a playground) or are in an IDE where they can browse to find parent types. In both these cases, there is no need to have the inherited properties explicitly listed because the tooling can show them anyway. So as a reader you could have the "all fields visible in one place" experience without impacting the writers so much. On the writing side, we're talking about a major maintenance hassle. Having to repeat 30 properties in 10 different types is not ideal. The fields need to be kept in sync manually as the project is maintained, as well as their documentation. And there is no compile-time nor runtime check about the doc sync (because we also might want to "override" the doc of a particular field in a particular type, this shouldn't be considered an error). Being able to narrow the type down is a separate thing I believe (usually achieved via override, which is already allowed here), so if we need to narrow something down, we can always explicitly specify the overridden field, but it doesn't mean we should force people to redeclare all other inherited fields as well. The |
I don't understand why this is still not implemented |
Problem
I found it's very inefficient to implement interface in GraphQL.
In GraphQL, the word
implements
means "copy all the fields from interface to the target type".The more types you get, you have to repeat your self more and more... If you add or delete a field in the interface, then you have to delete all the types that implement the interface, which is repeat yourself again.
In GraphQL it's all about "copy and paste", no real implementation there. So why should we repeat ourself like this way?
Proposal
Introducing a simple
extends
operator just like most of the program languages would be an excellent solution.For consistency,
Interface
also can be extended using theextends
operator.This approach won't introduce any breaking changes, and it's natural to have such an operator because it's not something new concept and fit with GraphQL very well too.
The text was updated successfully, but these errors were encountered: