graphql_client icon indicating copy to clipboard operation
graphql_client copied to clipboard

Use generator instead of transformer

Open Aetet opened this issue 7 years ago • 7 comments

As I know dart team will deprecate transformer API favor to builder api. Like https://github.com/google/built_value.dart I think it would be great if it ll be builder from the beginning

Aetet avatar Aug 25 '17 18:08 Aetet

Thanks for your comment. I have never wrote a transformer but I am eager to learn.

Do you mean that this is the Builder API: https://github.com/dart-lang/build ?

hourliert avatar Aug 26 '17 13:08 hourliert

Yep. This is it. Example of the generator: https://github.com/google/built_value.dart/tree/master/built_value_generator

Generator must be separate package. This prevent problems from analyzer, source_gen deps. Because they always must be sync with upstream.

Aetet avatar Aug 26 '17 18:08 Aetet

Thanks a lot for your issue. I will have a look at this during the week 👍 .

hourliert avatar Aug 28 '17 19:08 hourliert

Hi @Aetet,

I am looking at Generators right now and I have some questions.

  • AngularDart seems to use (not everywhere) "old transformers", do you think they will migrate to generators?
  • Why should I create a separate package for the generator? The angular codegen transformer seems to be included into the main repo : https://github.com/dart-lang/angular/blob/master/angular/lib/transform/codegen.dart
  • Is there any best practice to name a generator repository that is related to a library?
  • I have seen that graphql_client users will have to launch a "watcher" (as detailed here). Is there a way to launch this command in parallel of launching pub serve?

Thanks in advance!

EDIT: Ready almost ready! https://github.com/hourliert/graphql_client/tree/master/graphql_client_generator 😂

hourliert avatar Aug 31 '17 15:08 hourliert

Hi, @hourliert

  1. AFAIK they want to migrate to new compiler https://github.com/dart-lang/angular/issues/363 but also supports transformers for backward compatibility

  2. The main issue - all modules even for dev dependency must satisfy by version. For example you have following deps:

dep:
  built_value: 
  angular: 4.0.0
dev_dep:
   # for coverage
  dart_dev: 1.0.0

And if your package for coverage dart_dev wants analyzer 0.28.0 and angular 0.30.0 - because of semver we cannot resolve this deps.

So you need downgrade angular, or patch dart_dev by yourself, or separate dart_dev as external package. And run it like cli.

Occasionally will run into this problem. For built_value_generator, dartfmt, less_transformer, etc. That's why you need to reduce it with separate package. To solve this problem by infrastructure we need separate section at pubspec for this deps. But AFAIK it won't be shipped at Dart 2.0.

  1. Usually generator named like library but with suffix 'generator' like: built_value - built_value_generator
  2. As I can see at the issues https://github.com/dart-lang/angular/issues/420 they want to deprecate pub serve too. I think dart developers at https://gitter.im/dart-lang/angular2 can answer your questions more precisely.

I think good practice to use single repo for generator and library, but have separate package for them at pub.

Thanks to you!

Aetet avatar Sep 01 '17 09:09 Aetet

Awesome, thanks a lot for your answer. I'll keep this issue updated.

hourliert avatar Sep 01 '17 11:09 hourliert

@hourliert Has there been any progress on this front? This would indeed be a handy feature! I'd love to help out where I can.

g33kidd avatar Mar 22 '18 04:03 g33kidd