Skip to content

Commit

Permalink
fix(ci): Sync master into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
micimize committed Jun 3, 2020
2 parents 65d6069 + 6c188cb commit 2a0507e
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 627 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ Here are some examples you can follow:
1. [Starwars Example](./examples/starwars)
2. [`flutter_bloc` example](./examples/flutter_bloc)

## Articles and Videos

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):
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

This is currently our roadmap, please feel free to request additions/changes.
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_bloc/lib/extended_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class _ExtendedBlocState extends State<ExtendedBloc> {
builder: (_, state) {
Widget child = Container();

if (state is GraphqlLoading) {
if (state is GraphqlLoadingState) {
child = Center(child: CircularProgressIndicator());
}

Expand Down
12 changes: 10 additions & 2 deletions examples/flutter_bloc/lib/extended_bloc/graphql/bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ abstract class GraphqlBloc<T> extends Bloc<GraphqlEvent<T>, GraphqlState<T>> {
ObservableQuery result;
WatchQueryOptions options;

GraphqlBloc({this.client, @required this.options}) {
GraphqlBloc({@required this.client, @required this.options}) {
result = client.watchQuery(options);

result.stream.listen((QueryResult result) {
if (result.loading && result.data == null) {
add(GraphqlLoadingEvent<T>(result: result));
}

if (!result.loading && result.data != null) {
add(
GraphqlLoadedEvent<T>(
Expand Down Expand Up @@ -51,10 +55,14 @@ abstract class GraphqlBloc<T> extends Bloc<GraphqlEvent<T>, GraphqlState<T>> {
void _refetch() => result.refetch();

@override
GraphqlState<T> get initialState => GraphqlLoading<T>();
GraphqlState<T> get initialState => GraphqlInitialState<T>();

@override
Stream<GraphqlState<T>> mapEventToState(GraphqlEvent<T> event) async* {
if (event is GraphqlLoadingEvent<T>) {
yield GraphqlLoadingState<T>(result: event.result);
}

if (event is GraphqlLoadedEvent<T>) {
yield GraphqlLoaded<T>(data: event.data, result: event.result);
}
Expand Down
6 changes: 6 additions & 0 deletions examples/flutter_bloc/lib/extended_bloc/graphql/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ class GraphqlErrorEvent<T> extends GraphqlEvent<T> {
GraphqlErrorEvent({@required this.error, @required this.result});
}

class GraphqlLoadingEvent<T> extends GraphqlEvent<T> {
final QueryResult result;

GraphqlLoadingEvent({@required this.result});
}

class GraphqlLoadedEvent<T> extends GraphqlEvent<T> {
final T data;
final QueryResult result;
Expand Down
8 changes: 7 additions & 1 deletion examples/flutter_bloc/lib/extended_bloc/graphql/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ abstract class GraphqlState<T> {
const GraphqlState({@required this.data});
}

class GraphqlLoading<T> extends GraphqlState<T> {}
class GraphqlInitialState<T> extends GraphqlState<T> {}

class GraphqlLoadingState<T> extends GraphqlState<T> {
final QueryResult result;

GraphqlLoadingState({@required this.result}) : super(data: null);
}

class GraphqlErrorState<T> extends GraphqlState<T> {
final OperationException error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class RepositoriesBloc extends GraphqlBloc<Map<String, dynamic>> {
documentNode: parseString(r'''
query ReadRepositories($nRepositories: Int!, $after: String) {
viewer {
id
__typename
repositories(first: $nRepositories, after: $after) {
pageInfo {
endCursor
Expand Down Expand Up @@ -53,11 +55,6 @@ class RepositoriesBloc extends GraphqlBloc<Map<String, dynamic>> {
void fetchMore({String after}) {
add(GraphqlFetchMoreEvent(
options: FetchMoreOptions(
// variables: ReportListArguments(
// pagination: PaginationInput(
// limit: limit,
// offset: offset,
// )).toJson(),
variables: <String, dynamic>{'nRepositories': 5, 'after': after},
updateQuery: (dynamic previousResultData, dynamic fetchMoreResultData) {
final List<dynamic> repos = <dynamic>[
Expand Down
8 changes: 5 additions & 3 deletions examples/flutter_bloc/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import 'local.dart';

void main() => runApp(MyApp());

final OptimisticCache cache = OptimisticCache(
dataIdFromObject: typenameDataIdFromObject,
);

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -55,9 +59,7 @@ class MyApp extends StatelessWidget {
final Link _link = _authLink.concat(_httpLink);

return GraphQLClient(
cache: OptimisticCache(
dataIdFromObject: typenameDataIdFromObject,
),
cache: cache,
link: _link,
);
}
Expand Down
14 changes: 14 additions & 0 deletions packages/graphql/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [3.0.2](https://github.com/zino-app/graphql-flutter/compare/v3.0.1...v3.0.2) (2020-05-18)


### Bug Fixes

* **client:** FetchMoreOptions bug with operator precedence ([f8e05af](https://github.com/zino-app/graphql-flutter/commit/f8e05af52f9720eed612f13b513d25f2456a8726))

# [3.1.0-beta.6](https://github.com/zino-app/graphql-flutter/compare/v3.1.0-beta.5...v3.1.0-beta.6) (2020-05-16)


Expand Down Expand Up @@ -34,6 +41,13 @@
* **style:** use curly braces ([42f4da4](https://github.com/zino-app/graphql-flutter/commit/42f4da4cb5ddb9f76c34a5946eb1bf662d138cbf))
* **tests:** don't factor tests into coverage scores ([4a9bcd4](https://github.com/zino-app/graphql-flutter/commit/4a9bcd4c708e955dbfcd432f0ce803541a343487))

## [3.0.1](https://github.com/zino-app/graphql-flutter/compare/v3.0.0...v3.0.1) (2020-04-20)


### Bug Fixes

* **style:** use curly braces ([42f4da4](https://github.com/zino-app/graphql-flutter/commit/42f4da4cb5ddb9f76c34a5946eb1bf662d138cbf))

# [3.1.0-beta.2](https://github.com/zino-app/graphql-flutter/compare/v3.1.0-beta.1...v3.1.0-beta.2) (2020-04-12)


Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/lib/src/core/query_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class FetchMoreOptions {
assert(updateQuery != null),
this.documentNode =
// ignore: deprecated_member_use_from_same_package
documentNode ?? document != null ? parseString(document) : null;
documentNode ?? (document != null ? parseString(document) : null);

DocumentNode documentNode;

Expand Down
5 changes: 0 additions & 5 deletions packages/graphql/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ name: graphql
description: A stand-alone GraphQL client for Dart, bringing all the features from
a modern GraphQL client to one easy to use package.
version: 3.1.0-beta.6
authors:
- Eus Dima <[email protected]>
- Zino Hofmann <[email protected]>
- Michael Joseph Rosenthal <[email protected]>
- TruongSinh Tran-Nguyen <[email protected]>
homepage: https://github.com/zino-app/graphql-flutter/tree/master/packages/graphql
dependencies:
meta: ^1.1.6
Expand Down
42 changes: 42 additions & 0 deletions packages/graphql/test/core/query_options_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:gql/language.dart';
import 'package:graphql/client.dart';
import 'package:test/test.dart';

void main() {
group('FetchMoreOptions', () {
group('constructs', () {
final dummyUpdateQuery = (previousResultData, fetchMoreResultData) {
return null;
};

final document = 'query { foo }';
final documentParsed = parseString(document);

final documentNode = parseString('query { bar }');

test('with documentNode', () {
final options = FetchMoreOptions(
documentNode: documentNode,
updateQuery: dummyUpdateQuery,
);
expect(options.documentNode, equals(documentNode));
});

test('with document', () {
final options = FetchMoreOptions(
// ignore: deprecated_member_use_from_same_package
document: document,
updateQuery: dummyUpdateQuery,
);
expect(options.documentNode, equals(documentParsed));
});

test('with neither', () {
final options = FetchMoreOptions(
updateQuery: dummyUpdateQuery,
);
expect(options.documentNode, isNull);
});
});
});
}
Loading

0 comments on commit 2a0507e

Please sign in to comment.