Skip to content

Commit

Permalink
feat: update examples to gql instead of parse string
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Nov 11, 2019
1 parent 3879f18 commit 7b9ac57
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 36 deletions.
3 changes: 1 addition & 2 deletions examples/starwars/lib/episode/hero_query.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:gql/language.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

import './episode.dart';
Expand All @@ -13,7 +12,7 @@ class HeroForEpisode extends StatelessWidget {
Widget build(BuildContext context) {
return Query(
options: QueryOptions(
documentNode: parseString(r'''
documentNode: gql(r'''
query HeroForEpisode($ep: Episode!) {
hero(episode: $ep) {
__typename
Expand Down
5 changes: 3 additions & 2 deletions examples/starwars/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import './reviews/review_page.dart';
import './reviews/review_page_list.dart';

String get host {
if (Platform.isAndroid)
if (Platform.isAndroid) {
return '10.0.2.2';
else // for iOS simulator
} else {
return 'localhost';
}
}

final String GRAPHQL_ENDPOINT = 'http://$host:3000/graphql';
Expand Down
1 change: 0 additions & 1 deletion examples/starwars/lib/reviews/review.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:convert';
import 'package:meta/meta.dart';

import '../episode/episode.dart';
Expand Down
3 changes: 1 addition & 2 deletions examples/starwars/lib/reviews/review_page_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:starwars_app/reviews/review_subscription.dart'
show DisplayReviews;
import 'package:gql/language.dart';

class PagingReviews extends StatelessWidget {
static const BottomNavigationBarItem navItem = BottomNavigationBarItem(
Expand All @@ -14,7 +13,7 @@ class PagingReviews extends StatelessWidget {
Widget build(BuildContext context) {
return Query(
options: QueryOptions(
documentNode: parseString(r'''
documentNode: gql(r'''
query Reviews($page: Int!) {
reviews(page: $page) {
page
Expand Down
8 changes: 3 additions & 5 deletions packages/graphql/example/bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import 'package:graphql/client.dart';

import './graphql_operation/mutations/mutations.dart';
import './graphql_operation/queries/readRepositories.dart';
import 'package:gql/language.dart';

// to run the example, create a file ../local.dart with the content:
// const String YOUR_PERSONAL_ACCESS_TOKEN =
// '<YOUR_PERSONAL_ACCESS_TOKEN>';
Expand Down Expand Up @@ -41,7 +39,7 @@ void query() async {
const int nRepositories = 50;

final QueryOptions options = QueryOptions(
documentNode: parseString(readRepositories),
documentNode: gql(readRepositories),
variables: <String, dynamic>{
'nRepositories': nRepositories,
},
Expand Down Expand Up @@ -73,7 +71,7 @@ void starRepository(String repositoryID) async {
final GraphQLClient _client = client();

final MutationOptions options = MutationOptions(
documentNode: parseString(addStar),
documentNode: gql(addStar),
variables: <String, dynamic>{
'starrableId': repositoryID,
},
Expand Down Expand Up @@ -106,7 +104,7 @@ void removeStarFromRepository(String repositoryID) async {
final GraphQLClient _client = client();

final MutationOptions options = MutationOptions(
documentNode: parseString(removeStar),
documentNode: gql(removeStar),
variables: <String, dynamic>{
'starrableId': repositoryID,
},
Expand Down
22 changes: 9 additions & 13 deletions packages/graphql/lib/src/core/query_manager.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import 'dart:async';

import 'package:graphql/src/exceptions/exceptions.dart';
import 'package:meta/meta.dart';

import 'package:graphql/src/core/query_options.dart';
import 'package:graphql/src/core/query_result.dart';
import 'package:graphql/src/core/observable_query.dart';

import 'package:graphql/src/scheduler/scheduler.dart';

import 'package:graphql/src/link/link.dart';
import 'package:graphql/src/link/operation.dart';
import 'package:graphql/src/link/fetch_result.dart';

import 'package:graphql/src/cache/cache.dart';
import 'package:graphql/src/cache/normalized_in_memory.dart'
show NormalizedInMemoryCache;
import 'package:graphql/src/cache/optimistic.dart' show OptimisticCache;
import 'package:graphql/src/core/observable_query.dart';
import 'package:graphql/src/core/query_options.dart';
import 'package:graphql/src/core/query_result.dart';
import 'package:graphql/src/exceptions/exceptions.dart';
import 'package:graphql/src/link/fetch_result.dart';
import 'package:graphql/src/link/link.dart';
import 'package:graphql/src/link/operation.dart';
import 'package:graphql/src/scheduler/scheduler.dart';
import 'package:meta/meta.dart';

class QueryManager {
QueryManager({
Expand Down
5 changes: 2 additions & 3 deletions packages/graphql/lib/src/core/raw_operation_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import 'dart:convert' show json;

import 'package:gql/ast.dart';
import 'package:gql/language.dart';
import 'package:http/http.dart';

import 'package:graphql/src/utilities/get_from_ast.dart';
import 'package:graphql/src/link/http/link_http_helper_deprecated_stub.dart'
if (dart.library.io) 'package:graphql/src/link/http/link_http_helper_deprecated_io.dart';
import 'package:graphql/src/utilities/get_from_ast.dart';
import 'package:http/http.dart';

class RawOperationData {
RawOperationData({
Expand Down
3 changes: 1 addition & 2 deletions packages/graphql_flutter/example/lib/fetchmore/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:gql/language.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

import '../graphql_operation/queries/readRepositories.dart' as queries;
Expand Down Expand Up @@ -83,7 +82,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
Query(
options: QueryOptions(
documentNode: parseString(queries.searchRepositories),
documentNode: gql(queries.searchRepositories),
variables: <String, dynamic>{
'nRepositories': nRepositories,
'query': _searchQuery,
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql_flutter/example/lib/graphql_bloc/bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class Bloc {

Future<QueryResult> _mutateToggleStar(Repo repo) async {
final MutationOptions _options = MutationOptions(
documentNode: parseString(
repo.viewerHasStarred ? mutations.removeStar : mutations.addStar),
documentNode:
gql(repo.viewerHasStarred ? mutations.removeStar : mutations.addStar),
variables: <String, String>{
'starrableId': repo.id,
},
Expand Down
6 changes: 2 additions & 4 deletions packages/graphql_flutter/example/lib/graphql_widget/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:gql/language.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

import '../graphql_operation/mutations/mutations.dart' as mutations;
Expand Down Expand Up @@ -96,7 +95,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
Query(
options: QueryOptions(
documentNode: parseString(queries.readRepositories),
documentNode: gql(queries.readRepositories),
variables: <String, dynamic>{
'nRepositories': nRepositories,
},
Expand Down Expand Up @@ -175,8 +174,7 @@ class StarrableRepository extends StatelessWidget {
Widget build(BuildContext context) {
return Mutation(
options: MutationOptions(
documentNode:
parseString(starred ? mutations.removeStar : mutations.addStar),
documentNode: gql(starred ? mutations.removeStar : mutations.addStar),
update: (Cache cache, QueryResult result) {
if (result.hasException) {
print(result.exception);
Expand Down

0 comments on commit 7b9ac57

Please sign in to comment.