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

Types generation #26

Closed
lucasavila00 opened this issue Jun 29, 2018 · 26 comments
Closed

Types generation #26

lucasavila00 opened this issue Jun 29, 2018 · 26 comments
Assignees
Labels
enhancement New feature or request
Projects

Comments

@lucasavila00
Copy link
Contributor

lucasavila00 commented Jun 29, 2018

I can make a generator for the types, but it would be nice to pass the parameters to the runtime.
I think Dart doesn't allow it, but how could we go towards that full typed approach?
I haven't written a single line of Dart but I liked Flutter a lot, but I'd need to use it with GraphQL. I can help with the GraphQL part but I would need help with Dart.

@HofmannZ
Copy link
Member

HofmannZ commented Jul 16, 2018

@degroote22 Yes we are planning to create a fully typed library. Right now we mainly need it to handle caching more effectively, by actually passing response date into the appropriate GraphQL types. Feel free to try implementing a generator, we will jump in to help with Dart to make something great together.

@HofmannZ HofmannZ added the enhancement New feature or request label Jul 16, 2018
@HofmannZ HofmannZ self-assigned this Jul 16, 2018
@lucasavila00
Copy link
Contributor Author

lucasavila00 commented Jul 16, 2018

I've just finished my college's semeter and I did not have the time to look at it before.
I hope to be able to look into it soon.
As soon as I have news I'll give a shout here.

@lucasavila00
Copy link
Contributor Author

lucasavila00 commented Aug 25, 2018

I got a prototype working.
It's very rough (I'm updating it though) but it works with the example from this project.
I'm using a fork of the generator for now (pending issue) and a custom template.

See how it would be added to the example folder of this repository.

I'm currently using dartz's Option abstrasct data type to model fields that are optional.
The template is written in 185 lines of Typescript but we could implement it in Dart and compile using dart2js.

It uses this function know which string is a GraphQL operation.

String gql(String input) => input;
String readRepositories = gql("""
...

I'd appreciate feedback 👍

@HofmannZ
Copy link
Member

HofmannZ commented Sep 3, 2018

Great work!

I really like how you generate the comments for the classes, so that you have some documentation while coding.

On the other side it feels a bit weird to have javascript running inside a dart project.

It would be possible to use graphql_parser to process the query strings.

@ghost
Copy link

ghost commented Sep 3, 2018 via email

@lucasavila00
Copy link
Contributor Author

lucasavila00 commented Sep 3, 2018

The way types are being generated is with 2 things, the generator and the template.
The generator does more than just parsing the operations, it checks for errors in the operations agains the schema and pass to the template a flattened structure that's easier to use.
It also does some other stuff, like supporting graphql-import syntax. We would have a lot of work to support the same features they already do.
I'd rather work on a good template than reimplementing graphql-code-generator, at least for now.
The current generator has watch mode and the performance is okay, when used like this you don't even remember the fact that it is JS.

@lucasavila00 lucasavila00 changed the title Accept type as parameters Types generation Sep 3, 2018
@ghost
Copy link

ghost commented Sep 3, 2018

There are many graphql parsers and generators in golang. Because it's golang which has built in code gen at its core it already supports many frontend languages. It can also do graphql to grpc and db gen. All from the graphql schema.

https://github.com/graphql-go/graphql

https://github.com/99designs/gqlgen

  • the most feature complete.

The dart type generator then runs from the golang types using standard AST. I need to find the repo...

@lucasavila00
Copy link
Contributor Author

@gedw99 Go is faster than JS but the friction would be there anyways.
IDK if it would be worth the trouble.

@micimize
Copy link
Collaborator

micimize commented Sep 28, 2018

I've got serviceable type/json_serializable generation with graphql-to-dart working, although it still has some limitations. For instance, it doesn't extract graphql strings from dart code, and I still feel like I might be generating non-idiomatic code.

Eventually doing code generation with dart faculties would be more convenient, build process wise, but I don't think it's a priority for anyone anytime soon.

@micimize
Copy link
Collaborator

I'm not sure if graphql-flutter itself should attempt to generate types, at least at first.
Rather, I think we should provide an api for a user to integrate their own generated types, and possibly a seperate type generation project.

@amadeu01
Copy link

amadeu01 commented Sep 2, 2019

@lucasavila00 that generator https://github.com/comigor/artemis seems really cool
it might help as a base to create a generator for graphql-flutter

@HofmannZ
Copy link
Member

HofmannZ commented Sep 2, 2019

@amadeu01 Nice suggestion!

@comigor Would you be interested in moving your type generator under the graphql-flutter project? I think it would be awesome for new developers to get type generation out of the box. What do you think?

@comigor
Copy link
Contributor

comigor commented Sep 2, 2019

Hey guys!

Yeah, I also think this project would benefit from types generation, and that's why I've started Artemis, actually. The goal of it is to have GraphQL type generation for any Dart project, not just Flutter-based projects (I'm already using it with Flutter for desktop and some CLI's).

It was on my roadmap to make a Flutter widget layer to it and, for this, graphql_flutter would be an awesome vessel; but I think the graphql package has some conflicts of how I'd like Artemis to work (be pure Dart, use Dart's http.Client instead of a custom non-plugabble approach, for instance, or having cache and auth layer decoupled).

Would it be possible to just reference Artemis as a dependency of graphql_flutter for now? This way I could keep focusing on it, and it would even help guiding me to write more documentation and tests. I'll kindly accept changes and pull requests to it, so we can grow it together.

@micimize
Copy link
Collaborator

micimize commented Sep 2, 2019

@comigor I don't see any issue with that - if I can manage to replace graphql-to-dart with artemis I might start incorporating some typed widgets / helpers here.

There are some features we have implemented that I'd like to publish as standalone modules eventually, namely caching. So, if you go to add caching support, I'd rather put in the time to break that out, and work with you to get an appealing API design and the features you need.

graphql is pure Dart, btw

@comigor
Copy link
Contributor

comigor commented Sep 2, 2019

Yeah, I'd like to have cache (and even HTTP) decoupled from the code generation, but I had to create ArtemisClient abstraction to automatically get typed input/response from a query.

And what I meant of "pure Dart" is just using some default abstractions (like http.Client instead of HttpLink and things like that).

I didn't know about graphql-to-dart, but what I like most about Artemis is having it integrated with Flutter/Dart builder while generating code.

Ping me if you want some help on the migration! I'm actively working on Artemis right now (and adding documentation as we speak).

@smkhalsa
Copy link
Contributor

smkhalsa commented Nov 4, 2019

Now that #429 has been merged, is there a plan to integrate https://github.com/comigor/artemis?

@micimize
Copy link
Collaborator

micimize commented Nov 5, 2019

@smkhalsa in a sense - at the least, I'm probably going to start implementing a 3rd party code that does so, and if it gets to a mature state I'll PR it as another package.

@comigor
Copy link
Contributor

comigor commented Nov 5, 2019

Hey guys, how are you doing?

With the introduction of Queries (see this example), the code generated from Artemis could already be used in conjunction with graphql-flutter: one could link this with a custom QueryOptions, for example, and that's it.

Are guys thinking in another kind of integration? I hope we can think in a first-class integration, but without losing the customization possibilities of Artemis.

@oexza
Copy link

oexza commented Nov 7, 2019

Hey guys, how are you doing?

With the introduction of Queries (see this example), the code generated from Artemis could already be used in conjunction with graphql-flutter: one could link this with a custom QueryOptions, for example, and that's it.

Are guys thinking in another kind of integration? I hope we can think in a first-class integration, but without losing the customization possibilities of Artemis.

Can you make an example of this? I'm curious to see how this would work.

@vasilich6107
Copy link
Contributor

vasilich6107 commented Jan 10, 2020

@oexza

Here is a fresh example from my today experiments. Works pretty fine.
I'm using v3.0.0-beta[latest] version of flutter_graphql

              Query(
                options: QueryOptions(
                  documentNode: EmployeeQueryQuery(
                          variables: EmployeeQueryArguments(id: '123'))
                      .document,
                  variables: EmployeeQueryArguments(id: '123').toJson(),
                ),
                builder: (
                  QueryResult result, {
                  Future<QueryResult> Function() refetch,
                  FetchMore fetchMore,
                }) {
                  if (result.hasException) {
                    return Text(result.exception.toString());
                  }

                  if (result.loading) {
                    return const Center(
                      child: CircularProgressIndicator(),
                    );
                  }

                  final test = EmployeeQuery.fromJson(result.data);

                  debugPrint(test.employee.firstName);

                  return Container();
                },
              )

@michaellee8
Copy link

What is the status of this one? Are there any documentations yet?

@vasilich6107
Copy link
Contributor

@michaellee8
Copy link

https://medium.com/@v.ditsyak/ultimate-toolchain-to-work-with-graphql-in-flutter-13aef79c6484

Thank you, this one look nice. It will be great if this can be added to the README so that more people will be able to see that.

@vasilich6107
Copy link
Contributor

vasilich6107 commented Apr 24, 2020

@michaellee8 there is a PR for that #540

@mainawycliffe @micimize please...

@vasilich6107
Copy link
Contributor

@budde377
Copy link
Collaborator

Both artemis and graphql_codegen provides code generation for graphql_flutter and graphql. I think relying on external libraries is a decent approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Open Scrum
  
Future
Development

No branches or pull requests

10 participants