Skip to content
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

[gql_build] generate aliases for the generated data, reqs and vars #290

Open
osaxma opened this issue Dec 17, 2021 · 0 comments
Open

[gql_build] generate aliases for the generated data, reqs and vars #290

osaxma opened this issue Dec 17, 2021 · 0 comments

Comments

@osaxma
Copy link
Contributor

osaxma commented Dec 17, 2021

Since not too long ago, dart introduced Typedefs for non-function types*. It'd be nice if gql_build can generate an optional aliases file such as:

  • generated file: ./all_pokemon.aliases.dart;
import './all_pokemon.req.gql.dart';
import './all_pokemon.var.gql.dart';
import './all_pokemon.data.gql.dart';

typedef AllPokemon = GAllPokemon;
typedef AllPokemonData = GAllPokemonData;
typedef AllPokemonVar = GAllPokemonVars;
typedef AllPokemonVarsBuilder = GAllPokemonVarsBuilder;
  • In some other file:
import './all_pokemon.aliases.dart';

final pokemonQuery = AllPokemon((b) {
  b.vars = AllPokemonVarsBuilder()..first = 100;
});

final allPokemonsData = AllPokemonData.fromJson({/* json */});

The main advantage will be:

  • IDE can support Autocomplete since all_pokemon.aliases.dart can be included in the analyzer.
  • The G prefix can be removed by the alias.
  • The alias file is browsable for available data, reqs, and vars.

* Typedefs for non-function types this is only supported if the min sdk constraint is set to 2.15.0 or higher in pubspec.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant