Giter VIP home page Giter VIP logo

flutter_graphql_hooks's Introduction

Flutter GraphQL Hooks ๐Ÿช

LOOKING FOR MAINTAINERS

Watch on GitHub Star on GitHub Tweet!

Introduction

This package exposes an apollo-like set of hooks to be used with flutter, it's meant to be used together with the graphql_flutter package and it's based on it's latest implementation.

It can be used along with artemis to provide strongly typed hooks, example:

final query = GetRoomsQuery(variables: GetRoomsArguments(limit: 10, offset: 0));

final rooms = useQuery(QueryOptions(
  document: query.document,
  variables: query.getVariablesMap(),
));

final loading = rooms.result.loading;
final error = rooms.result.error;
final data = query.parse(rooms.result.data);
// Data will no longer be a [Map<String, dynamic>] and will have proper typings! 

Installing

dependencies:
  flutter_graphql_hooks:

Notes

In order to use the hooks, a GraphqlProvider must exist on the build context. Otherwise you'll need to manually pass the client in the hook as a parameter like:

final rooms = useQuery(QueryOptions(
  document: query.document,
  variables: query.getVariablesMap(),
), client: myGraphqlClient);

flutter_graphql_hooks's People

Contributors

kevinrodriguez-io avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flutter_graphql_hooks's Issues

Abuse of useState hook

Inside useQuery, useMutation and others, there are many useState for loading and error. These generates a double rebuild for each updating depleting performance.

The right way is to create a custom hook.

TypeError when setting data-attribute in useQuery

Hi there!

Thanks for creating this package, I'm hoping to get it working in our project :)

We're getting an error from use_query complaining about the type of the data-attribute.

As you can see in this screenshot, the incoming result.data is of type _InternalLinkedHashMap<String, dynamic>.

Screenshot 2021-02-05 at 13 56 44

But when setting data.value to result.value the following exception is thrown:
Screenshot 2021-02-05 at 14 59 59

It complains that the type of the data-attribute, which is Null coming from the type-assertion of useState(null), does not match the incoming data.

Is this possible to fix? One idea is trying data = useState<Map<String, dynamic>>(null)

Here is the code that is running the query:

class ShoppingCartScreen extends HookWidget {
  final int storeId;

  ShoppingCartScreen(this.storeId);

  @override
  Widget build(BuildContext context) {
    final trustMealArticlesQuery = TrustMealArticlesQuery(
        variables: TrustMealArticlesArguments(
            input: GetGroceryArticlesInput(storeId: storeId)));
    var queryResult = useQuery(QueryOptions(
            document: trustMealArticlesQuery.document,
            variables: trustMealArticlesQuery.getVariablesMap()))
        .result;

    var trustMealArticles = queryResult.data != null
        ? trustMealArticlesQuery.parse(queryResult.data).groceryArticles
        : <TrustMealArticles$Query$GroceryArticle>[];

    return ShoppingCartScreenContent(
      storeId: storeId,
      trustMealArticles: trustMealArticles,
      loading: queryResult.loading,
      exception: queryResult.error,
    );
  }
}

Adding the fetchMore function

Hello again

I see that useQuery returns a refetch-function, here called fetch, but I can't find any support for the fetchMore-function used for pagination.

Is it possible to add this?

Exception-throwing

Hi

In the query-hooks when result has an exception, why does it throw the exception? I thought the graphql-way is that the error silently arrives in the error-attribute and then it is handled from there. Now I have to wrap the query in an empty try-catch just to ignore the exception that is thrown.

Upgrade graphql_flutter

Hey

I would like to upgrade my graphql_flutter to 5.0.0, but this library currently keeps me from doing that.

Do you think you'd be able to upgrade easily?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.