Comments (4)
most of the actual codegen logic is in gql_code_builder, ferry_generator is mostly just a wrapper that uses gql_code_builder to generate the OperationRequest classes that ferry expects (gql_code_builder is also used by other graphql code builders like graphql_codegen or the now deprecated artemis).
I think another package is warranted though, as users of built_value probably don't like and additional dependency to freezed which they don't need and visa-versa.
Dependencies that use analyzer
are notoriously annoying due to the frequent breaking changes, so they should not be added unless necessary.
from ferry.
I will give it a try then. 👍
from ferry.
I am not the original author of ferry but took over maintenance, but I am one of the first users of ferry.
But I can give my thoughts on the possible rationale of the original author:
query HeroQuery {
hero {
...HeroFragment
height
weight
}
}
fragment HeroFragment on Hero {
id
name
}
This will generate a HeroFragment abstract class, and a HeroQuery_hero class that implements the HeroFragment class, so you can write code that accepts fragment types which are shared across many queries.
Similarly, when using inline fragments with type conditions, like
fragment DroidFragment on Droid {
primaryFunction
}
query HeroForEpisode($ep: Episode!) {
hero(episode: $ep) {
name
friends {
name
}
... on Droid {
...DroidFragment
}
}
}
We generate a base class GHeroForEpisodeReq_heroBase
, which has the common fields,
and specialized classes for the type conditions, in this case GHeroForEpisodeReq_heroOnDroid
, which has the common fields plus the fields that are specific to this typecondition.
These are the two features of ferry_gererator that go a bit beyond basic data classes.
The first versions of ferry were published in 2019.
built_value was already out and stable at that point and supported all of these features.
It supported union types (even though in a bit crude way) for fragment spreads with type conditions and subtypes (for inline fragment spreads).
I don't know if freezed even existed at that point, but if it did, it was probably a very new and unstable package and did not yet have support for this kind of subtyping.
I think built_value was the reasonable choice in 2019. Nowadays, with Dart having native support for sealed classes, null safety (yes, built_value supported null safety using runtime checks before Dart had null safety), etc. it might look differently.
Of course, the syntax of built_value is cumbersome, and also the single serializers.dart file which lists all the serializers for all the generated types prooves to be problematic for bigger projects.
Another thing is that since early 2021, the Dart team announced that it explored static metaprogramming.
While still unclear on if this will ever be released and how exactly it would look like, for people working on code generators that brings uncertainty, because of the risk of spending many hours on a project that could be outdated soon because of language level support for macros.
ferry does not directly depend on ferry_generator, as long as any generator uses the OperationRequest
interface, it will work fine, so in principle, one could implement another code generator that uses freezed or implements serialization manually (I also like what graphql_codegen does for example).
from ferry.
@knaeckeKami Thanks for the detailed answer. Now that static metaprogramming is already out in dart master branch, i think the development is going good on its way. So i dont see any reason why we shouldn't approach freeazed serializers as well. I will walk through the code and see how much effort it would require. I am not sure if ferry_generator is confirgurable by design. If not, then this would need a separate package say ferry_freezed_generator.
from ferry.
Related Issues (20)
- Cannot use `tristate_optionals: true` in mutations having lists in their parameters HOT 5
- Custom ISO serializer for DateTime HOT 5
- How to remove the `__typename` in the `toJson` of a fragment HOT 2
- Change in cache doesn't propagate HOT 28
- [Feature Request] Add `ContextEntries` to requests that can be retrieved in custom `gql` `Link` HOT 9
- [Feature Request] Access properties using Maps (ferry_generator) HOT 3
- [Feature Request] a CLI that output unused field/argument in the schema HOT 1
- Generating tristate_optionals generates invalid code with mixed up imports HOT 10
- Unable to Upload Multipart File with dio link HOT 2
- ferry_flutter: endless loading state after the cache has been cleared HOT 1
- Null check operator used on a null value and "Bad Element" HOT 1
- schema.schema.gql.dart not generated - "possibleTypesMap" missing HOT 3
- Ferry cannot decompose fragment on TypeCondition HOT 1
- Manually update the ferry data HOT 1
- TypePolicy is broken Or there is no clear documentation about it. HOT 12
- The relevant error-causing widget was:
- [Feature Request] Export request query to graphql HOT 1
- Non-dev dependency in ferry_generator package HOT 2
- Simple example calling a mutation on click and handling the response HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ferry.