-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de26fa4
commit 77788ce
Showing
4 changed files
with
142 additions
and
96 deletions.
There are no files selected for viewing
82 changes: 62 additions & 20 deletions
82
lib/app/modules/Graphql/controllers/graphql_controller.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,36 @@ | ||
import 'package:get/get.dart'; | ||
import 'package:getx_standard/app/service/graphQL/graphql_config.dart'; | ||
import 'package:graphql_flutter/graphql_flutter.dart'; | ||
|
||
import 'graphql_config.dart'; | ||
|
||
class GraphQLService extends GetxService { | ||
GraphQLConfig graphQLConfig = GraphQLConfig(); | ||
|
||
Future<GraphQLResult> performQuery(String query) async { | ||
final options = QueryOptions(document: gql(query)); | ||
final result = await graphQLConfig.graphqlClient().query(options); | ||
return _handleResult(result); | ||
} | ||
Future<dynamic> performMutation(String mutation) async { | ||
final mutationOptions = MutationOptions( | ||
document: gql(mutation), | ||
); | ||
|
||
Future<GraphQLResult> performMutation(String mutation) async { | ||
final options = MutationOptions(document: gql(mutation)); | ||
final result = await graphQLConfig.graphqlClient().mutate(options); | ||
return _handleResult(result); | ||
} | ||
final result = await graphQLConfig.graphqlClient().mutate(mutationOptions); | ||
|
||
GraphQLResult _handleResult(QueryResult result) { | ||
if (result.hasException) { | ||
final graphqlError = result.exception?.graphqlErrors.first; | ||
throw GraphQLError(graphqlError!.message); | ||
} else { | ||
return GraphQLResult(result.data); | ||
throw result.exception!; | ||
} | ||
} | ||
} | ||
|
||
class GraphQLError implements Exception { | ||
final String message; | ||
return result.data; | ||
} | ||
|
||
GraphQLError(this.message); | ||
Future<dynamic> performQuery(String query) async { | ||
final queryOptions = QueryOptions( | ||
document: gql(query), | ||
); | ||
|
||
@override | ||
String toString() => 'GraphQLError: $message'; | ||
} | ||
final result = await graphQLConfig.graphqlClient().query(queryOptions); | ||
|
||
class GraphQLResult { | ||
final dynamic data; | ||
if (result.hasException) { | ||
throw result.exception!; | ||
} | ||
|
||
GraphQLResult(this.data); | ||
return result.data; | ||
} | ||
} |