Git Product home page Git Product logo

Comments (4)

knaeckeKami avatar knaeckeKami commented on July 30, 2024 1

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.

Abhilash-Chandran avatar Abhilash-Chandran commented on July 30, 2024 1

I will give it a try then. 👍

from ferry.

knaeckeKami avatar knaeckeKami commented on July 30, 2024

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.

Abhilash-Chandran avatar Abhilash-Chandran commented on July 30, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.