-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Implement new naming schemes #96
Conversation
void main() { | ||
group('On complex input objects', () { | ||
test( | ||
'Unused input objects will be filtered out', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember correct in previous versions there was no need to filter unused input
and enum
why are we going implement approach that requires filtering?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I've created a new canonical visitor (responsible for retrieving all canonical classes: enums, input objects and fragments). However, not every of those canonical objects are used on each one of the queries, so I'm filtering out the unused values while we don't implement a single place to output canonical objects.
The overall solution seems to work fine. On monday we are starting the flutter project from scratch. I'll try to use this branch to generate sources. |
What do you think about omitting the Let me explain in details. I'm thinking about usage of the generated types in project. On the screenshot that I posted above you can see that we have three classes generated with the same The long named classes is a must to avoid the conflicts as we agreed. But mixins could be useful for referring to the specific types. For example I can define a widget that accepts As far as I see there is no any convention that recommends to use https://dart.dev/guides/language/language-tour#adding-features-to-a-class-mixins Also we did not postfix the classes with Here is an example in code usage
and
|
Sure, there's not needed to call it mixin, I'll update with those changes as well |
Actually, it seems the following is possible: type Person {
id: ID!
firstName: String!
lastName: String!
} fragment Person on Person {
firstName
lastName
}
query {
personById(id: "abc") {
...Person
}
} And I couldn't find anything on spec on validation of name uniqueness between fragments definitions and other objects, only the fragment declaration itself: https://spec.graphql.org/June2018/#sec-Fragment-Name-Uniqueness. So, if we don't append something to the fragment definition, it's possible for it to collide with some other declaration name. As this is the beta branch, I'm gonna merge it and we can still think about this and open another PR later. This one is too huge already! |
56027f4
to
818334e
Compare
51e040f
to
23c4594
Compare
From comments on #90 and #93:
The current pathed naming approach (let's call it pathedWithTypes) has some corner cases despicted on #93 #63 #91. If the path to the same object forks, but use the same classes on both forks, it'll be unable to generate two (or more) classes with the same name. So, in this case, you'd have to use aliases.
This PR adds a new option to choose which kind of class names will be generated: pathed with field names, pathed with type (GraphQL classes) names and "simple" (do not use pathes).
QueryName$QueryRoot$Pokemon$Pokemon
QueryName$QueryRoot$Charmander$Evolutions
Pokemon
For compatibility reasons, pathedWithTypes is still the default. But, theoretically, pathedWithFields is the one that would not generate conflicts. We can change the default (or even kill pathedWithTypes in the future). I'd still give the option to generate simple given some users like to use import aliases to prefix their generated code (and it gives the flexibility to not generate those huge names).
In the future, I'd like to generate the canonical (scalars, input objects and enums) objects into a different file.