Skip to content

Commit

Permalink
Merge pull request #648 from zino-app/modularization
Browse files Browse the repository at this point in the history
  • Loading branch information
micimize authored Oct 6, 2020
2 parents fb33aad + 79a8143 commit 8691287
Show file tree
Hide file tree
Showing 148 changed files with 5,773 additions and 7,733 deletions.
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ jobs:
command: |
cd packages/graphql
dartfmt **/*.dart -n --set-exit-if-changed
flutter analyze
pub get
dartanalyzer lib test
cd example && pub get && dartanalyzer .
- run:
name: Code formating and analyzing (graphql_flutter)
command: |
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ unlinked_spec.ds
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/.last_build_id
**/ios/Flutter/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
Expand All @@ -127,3 +129,7 @@ unlinked_spec.ds
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

**/test/.test_coverage.dart


7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

## :mega: [`v4` is now in open alpha](https://github.com/zino-app/graphql-flutter/pull/648) :mega:


## About this project

GraphQL brings many benefits, both to the client: devices will need fewer requests, and therefore reduce data usage. And to the programmer: requests are arguable, they have the same structure as the request.
Expand Down Expand Up @@ -40,9 +39,9 @@ Here are some examples you can follow:

## Articles and Videos

External guides, tutorials, and other resources from the GraphQL Flutter community
External guides, tutorials, and other resources from the GraphQL Flutter community

* [Ultimate toolchain to work with GraphQL in Flutter](https://medium.com/@v.ditsyak/ultimate-toolchain-to-work-with-graphql-in-flutter-13aef79c6484):
- [Ultimate toolchain to work with GraphQL in Flutter](https://medium.com/@v.ditsyak/ultimate-toolchain-to-work-with-graphql-in-flutter-13aef79c6484):
An intro to using `graphql_flutter` with [`artemis`](https://pub.dev/packages/artemis) for code generation and [`graphql-faker`](https://github.com/APIs-guru/graphql-faker) for API prototyping

## Roadmap
Expand All @@ -61,7 +60,7 @@ This is currently our roadmap, please feel free to request additions/changes.
| Optimistic results ||
| Modularity ||
| Automatic Persisted Queries ||
| Client state management | 🔜 |
| Client state management | |

## Contributing

Expand Down
129 changes: 0 additions & 129 deletions changelog-v2-v3.md

This file was deleted.

150 changes: 150 additions & 0 deletions changelog-v3-v4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Migrating from v3 – v4

v4 aims to solve a number of sore spots, particularly with caching, largely by leveraging libraries from the https://github.com/gql-dart ecosystem. There has also been a concerted effort to add more API docstrings to the codebase.

## Cache overhaul

- There is now only a single `GraphQLCache`, which leverages [normalize](https://pub.dev/packages/normalize),
Giving us a much more `apollo`ish API.
- [`typePolicies`]
- [direct cache access] via `readQuery`, `writeQuery`, `readFragment`, and `writeFragment`
All of which can which can be used for [local state management]
- `LazyCacheMap` has been deleted
- `GraphQLCache` marks itself for rebroadcasting (should fix some related issues)
- **`Store`** is now a seperate concern:

```dart
/// Only necessary on flutter
void main() async {
await initHiveForFlutter();
runApp(MyApp());
}
GraphQLCache(
// The default store is the InMemoryStore, which does NOT persist to disk
store: GraphQLCache(store: HiveStore()),
)
```

## We now use the [gql_link system](https://github.com/gql-dart/gql/tree/master/links/gql_link)

- Most links are re-exported from `graphql/client.dart`
- `QueryOptions`, `MutationOptions`, etc are turned into
[gql_exec](https://github.com/gql-dart/gql/tree/master/links/gql_exec) `Request`s
before being sent down the link chain.
- `documentNode` is deprecated in favor of `DocumentNode document` for consistency with `gql` libraries
- We won't leave alpha until we have [full backwards compatability](https://github.com/gql-dart/gql/issues/57)

```diff
final httpLink = HttpLink(
- uri: 'https://api.github.com/graphql',
+ 'https://api.github.com/graphql',
);

final authLink = AuthLink(
getToken: () async => 'Bearer $YOUR_PERSONAL_ACCESS_TOKEN',
);

var link = authLink.concat(httpLink);

if (ENABLE_WEBSOCKETS) {
final websocketLink = WebSocketLink(
- uri: 'ws://localhost:8080/ws/graphql'
+ 'ws://localhost:8080/ws/graphql'
);

- link = link.concat(websocketLink);
+ // split request based on type
+ link = Link.split(
+ (request) => request.isSubscription,
+ websocketLink,
+ link,
+ );
}
```

This makes all link development coordinated across the ecosystem, so that we can leverage existing links like [gql_dio_link](https://pub.dev/packages/gql_dio_link), and all link-based clients benefit from new link development

## `subscription` API overhaul

`Subscription`/`client.subscribe` API is in line with the rest of the API

```dart
final subscriptionDocument = gql(
r'''
subscription reviewAdded {
reviewAdded {
stars, commentary, episode
}
}
''',
);
// graphql/client.dart usage
subscription = client.subscribe(
SubscriptionOptions(
document: subscriptionDocument
),
);
// graphql_flutter/graphql_flutter.dart usage
Subscription(
options: SubscriptionOptions(
document: subscriptionDocument,
),
builder: (result) { /*...*/ },
);
```

## Minor changes

- `pollInterval`, which used to be an `int` of `seconds`, is now a `Duration`
- As mentioned before, `documentNode: gql(...)` is now `document: gql(...)`.
- The exported `gql` utility adds `__typename` automatically.
\*\*If you define your own, make sure to include `AddTypenameVisitor`,
or else that your cache `dataIdFromObject` works without it

### Enums are normalized and idiomatic

```diff
- QueryResultSource.OptimisticResult
+ QueryResultSource.optimisticResult
- QueryResultSource.Cache
+ QueryResultSource.cache
// etc

- QueryLifecycle.UNEXECUTED
+ QueryLifecycle.unexecuted
- QueryLifecycle.SIDE_EFFECTS_PENDING
+ QueryLifecycle.sideEffectsPending
```

### `client.fetchMore` (experimental)

The `fetchMore` logic is now available for when one isn't using `watchQuery`:

```dart
/// Untested example code
class MyQuery {
QueryResult latestResult;
QueryOptions initialOptions;
FetchMoreOptions get _fetchMoreOptions {
// resolve the fetchMore params based on some data in lastestResult,
// like last item id or page number, and provide custom updateQuery logic
}
Future<QueryResult> fetchMore() async {
final result = await client.fetchMore(
_fetchMoreOptions,
options: options,
previousResult: latestResult,
);
_latestResult = result;
return result;
}
}
```

[local state management]: https://www.apollographql.com/docs/tutorial/local-state/#update-local-data
[`typepolicies`]: https://www.apollographql.com/docs/react/caching/cache-configuration/#the-typepolicy-type
[direct cache access]: https://www.apollographql.com/docs/react/caching/cache-interaction/
Loading

0 comments on commit 8691287

Please sign in to comment.