comigor / artemis

Build dart types from GraphQL schemas and queries
MIT License
495 stars 119 forks source link

[Feature Request] Generate types from @gql annotations #104

Open yosef-abraham opened 4 years ago

yosef-abraham commented 4 years ago

In relay, one of the strength points is that queries and fragments can be written along side the widgets using them.

We had a discussion regarding this here.

For example:


@gql(r"""
  query MyHomePage_query {
    ...AllFilmsList_allFilms
  }
""")
class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return QueryBuilder(
      query: MyHomePage_query(),
      builder: (context, QueryResponse<$MyHomePage_query> response) { 
        // The QueryBuilder implicitly exposese through context the AllFilmsList_allFilms fragment
        return AllFilmsList();
      }
    );
  }
}

@gql(r"""
  fragment AllFilmsList_allFilms {
    allFilms {
      title
    }
  }
""")
class AllFilmsList extends StatelessWidget {
  const AllFilmsList({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return FragmentBuilder<$AllFilmsList_allFilms>(
      builder: (context, allFilms) {

      }
    );
  }
}

I also have been able to make vscode to auto-complete me inside the annotation's query.

What do you think?

comigor commented 4 years ago

Hello @iscriptology!

This seems a nice usage of GraphQL through a Flutter app! I like to use it on relay as well (though one downside is queries end up scattered across the repository and this makes me mad).

However, Artemis is a pure Dart library, and this wouldn't be its responsability to handle: it'd be nice to have a new GraphQL client library that leverages both Artemis type generation and this relay-style annotation-based usage.

If you'd like to start some implementation on this, please reach me and I can assist on the Artemis integration!

yosef-abraham commented 4 years ago

@comigor thanks for the reply.

Even though a specific graphql client adjusted for this use case would be nice, it still is fully backward compatible to just source the graphql queries from the gql annotations in addition to the .graphql files.

This can be done here at artemis regardless of any client being implemented.

What do you think?

comigor commented 4 years ago

Absolutely! We just need to keep configurations working and share fragments/enums/input types correctly.

But to be honest, this implementation is not a priority right now, but I'll gladly assist you if you want to start it!