gql-dart / ferry

Stream-based strongly typed GraphQL client for Dart
https://ferrygraphql.com/
MIT License
604 stars 116 forks source link

Generated Client SDK #226

Open smkhalsa opened 3 years ago

smkhalsa commented 3 years ago

We should explore creating a client generator that simply wraps a TypedLink and provides typed access to all operations.

Rather than instantiating an operation request and manually executing it on a TypedLink, we could generate the client (based on operations in .graphql files) then execute the operations as method calls directly on the client. For example:

import 'path/to/generated/client';

final client = Client(typedLink: someLink);

Then we could execute operations:

final todos = await client.query.getTodos((b) => b..vars.offset = 10).first;

Or access the cache:

final myTodo = await client.readFragment.Todo((b) => b.id = "123");
smkhalsa commented 3 years ago

Upon further thought, I think the sdks should be broken out:

  1. ClientSDK: allows for executing graphql operations
  2. CacheSDK: allows for reading and writing to / from the cache