Skip to content

Instantly share code, notes, and snippets.

Avatar

Velotio Technologies velotiotech

View GitHub Profile
View .json
{
"data": [
{
"title": "The Godfather",
"genre": "Drama"
}
]
}
View .json
[
{
"title": "The Godfather",
"genre": "Drama",
"rating": 9.2,
"year": 1972
}
]
View .json
[
{
title: "The Godfather",
genre: "Drama",
rating: 9.2,
year: 1972
}
]
View .txt
/GET localhost:8080/movies
View .dart
Subscription(   options: SubscriptionOptions(     document: gql(counterSubscription),   ),   builder: (result) {     if (result.hasException) {       return Text("Error occurred: " + result.exception.toString());     }‍     if (result.isLoading) {       return Center(         child: const CircularProgressIndicator(),       );     }‍     return ResultAccumulator.appendUniqueEntries(         latest: result.data,         builder: (context, {results}) => ...     );   }),
View .dart
final counterSubscription = '''subscription counterAdded {   counterAdded {       name       id   }}''';
View .dart
Mutation( options: MutationOptions(   document: gql(addCounter),   update: (GraphQLDataProxy cache, QueryResult result) {     return cache;   },   onCompleted: (dynamic resultData) {     print(resultData);   }, ), builder: (   RunMutation runMutation,   QueryResult result, ) {   return FlatButton(       onPressed: () => runMutation({             'counterId': 21,           }),       child: Text('Add Counter')); },);
View .dart
final String readCounters = """query readCounters(\$counterId: Int!) {   counter {       name       id   }}""";
View .dart
options: QueryOptions( document: gql(readCounters), variables: {   'conuterId': 23, }, pollInterval: Duration(seconds: 10),),
View .dart
class MyHomePage extends StatelessWidget@override Widget build(BuildContext) {   return Query(     options: QueryOptions(       document: gql(readCounters),       variables: {         'counterId': 23,       },       pollInterval: Duration(seconds: 10),     ),     builder: (QueryResult result,         { VoidCallback refetch, FetchMore fetchMore }) {       if (result.hasException) {         return Text(result.exception.toString());       }‍       if (result.isLoading) {         return Text('Loading');       }‍       // it can be either Map or List       List counters = result.data['counter'];‍       return ListView.builder(           itemCount: repositories.length,           itemBuilder: (context, index) {             return Text(counters\[index\]['name']);           });     },) }}