zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.25k stars 619 forks source link

Separate generic GraphQL client code from flutter implementation #72

Closed adelcasse closed 5 years ago

adelcasse commented 6 years ago

Is your feature request related to a problem? Please describe. When trying to use Graphql-flutter in a framework-agnostic way, it is today possible to target directly non-Flutter specific parts (Client, ...) of this library, which is probably the best in Dart as of today.

For example, following the BLoC pattern, we use graphql-flutter inside our business logic components that (even if used today with Flutter) are intended to be framework-agnostic (and could be used with AngularDart for example ?).

The problem is that, making a separate Dart package for this business logic components, a dependency on graphql-flutter would bring a dependency on Flutter itself, even if we're not using Flutter-specific parts of the package.

Describe the solution you'd like Separate this wonderfull lib in 2 packages : 1 framework-agnostic with generic GraphQL, and another one with Flutter implementation targetting the first one

Describe alternatives you've considered If this is not intended, we would probably create a new library based on the "generic" GraphQL implementation from this library. This would probably bring some overhead in maintaining synchronization between the 2 projects contributions.

adelcasse commented 6 years ago

I've just come across the README and just saw this statement "With that being said, the project lives currently still inside one package. We plan to spilt up the project into multiple smaler packages in the near future, to follow Apollo's modules design"

So that's great, sorry I didn't read this before ;).

And, for your information, we're really interested in my company in helping/contributing to this as it matches our development needs ;)

HofmannZ commented 6 years ago

@adelcasse Yes will be adding that to version 1.0.0

jeprojects commented 6 years ago

@HofmannZ Is it possible to access the GraphQL client now for testing with 1.0.0-alpha.4?

I tried, but getting an error:

RangeError (index): Invalid value: Valid value range is empty: 0

Here is a sample of the code, perhaps I am doing something wrong?

      HttpLink httpLink = HttpLink(
        uri: graphQlEndpoint + '/graphql',
      );

      GraphQLClient graphql = GraphQLClient(
        link: httpLink,
        cache: _cache,
      );

      QueryOptions q = QueryOptions()
       ..document = signedRequest.body
       ..context = <String, dynamic>{
        "headers": signedRequest.headers,
      };

      var result = await graphql.query(q);
HofmannZ commented 6 years ago

@jeprojects see issue #86 for the implementation.

This line causes a bug in 1.0.0-alpha.4 that avoids you from using headers in the context. It is already fixed in PR #88. Just waiting for a peer review ✌🏻

jeprojects commented 6 years ago

@HofmannZ Thanks! Keep up the awesome work.

dustin-graham commented 6 years ago

@HofmannZ I'm assuming this is related, but I'm interested in building an AngularDart project and I'd like to use this library. Splitting off a base library that is outside of any Flutter considerations seems to be what I would need to accomplish this. I'm interested in helping with this effort if it's a direction you'd like to go. Perhaps there is already progress for this already?

dustin-graham commented 6 years ago

Perhaps what I'll experiment with first is to use my fork to trim out Flutter pieces and make it compatible with AngularDart and see what it looks like at that point. And then try to see if I can refactor this library to depend on the trimmed-down base GraphQL library.

HofmannZ commented 6 years ago

@dustin-graham It's on the top of the todo list now, just having the rolling impediments:

After those to impediments the refactoring should be minimal because I kept code splitting in mind when I did the initial refactoring.

It also is nice to have the two separate codebases so I can setup env independent testing.

shafqatevo commented 5 years ago

@HofmannZ zillion thanks for this project - we're just getting started with a Flutter-AngularDart codesharing project. Is the modularization almost ready or will it take some more time?

truongsinh commented 5 years ago

Separation MR at #203

micimize commented 5 years ago

graphql/client.dart is now in beta, though reeeeeaaaaally lacking in docs

will leave this open until it is better documented and out of beta

jaumard commented 5 years ago

graphql is not yet in pub right ? Does it change a lot from the one currently bundled into this one ?

mainawycliffe commented 5 years ago

@jaumard It doesn't change much at all. You can find the beta on pub here. There are some examples too, though more docs and examples are required.

jaumard commented 5 years ago

Ho ok didn't pop on search ^^ thanks @mainawycliffe ! I'll try it, as I don't need the flutter part I prefer not having it in my deps :)

klavs commented 5 years ago

Why is it dependent on dart:io? As far as I know, it makes it incompatible with web platform

HofmannZ commented 5 years ago

:tada: This issue has been resolved in version 1.0.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

kei42 commented 5 years ago

Hello, I've been trying to use the package on web platform with graphql: ^1.0.1 for websockets and it seems that the file socket_client.dart depends on dart:io is it normal ? I've been trying to implement it based on this thread : https://github.com/zino-app/graphql-flutter/issues/231

Thanks.

micimize commented 5 years ago

@kei42 @klavs just made #295 to track the dart:io issue