Support Generated Responses
This commit is contained in:
parent
f0aee561ad
commit
5291d6bfe2
@ -10,7 +10,7 @@ targets:
|
|||||||
schema_mapping:
|
schema_mapping:
|
||||||
- schema: schema.graphqls
|
- schema: schema.graphqls
|
||||||
queries_glob: graphql/*.graphql
|
queries_glob: graphql/*.graphql
|
||||||
output: lib/graphql/imgagini_graphql.dart
|
output: lib/graphql/imagini_graphql.dart
|
||||||
scalar_mapping:
|
scalar_mapping:
|
||||||
- graphql_type: Upload
|
- graphql_type: Upload
|
||||||
custom_parser_import: 'package:imagini/helpers/upload_serializer.dart'
|
custom_parser_import: 'package:imagini/helpers/upload_serializer.dart'
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
// ignore: uri_does_not_exist
|
// ignore: uri_does_not_exist
|
||||||
import 'cookie_client_stub.dart'
|
import 'cookie_client_stub.dart'
|
||||||
@ -11,7 +10,7 @@ import 'cookie_client_stub.dart'
|
|||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:graphql_flutter/graphql_flutter.dart';
|
import 'package:graphql_flutter/graphql_flutter.dart';
|
||||||
|
|
||||||
import 'package:imagini/models/api/response/login_response.dart';
|
import 'package:imagini/graphql/imagini_graphql.dart';
|
||||||
|
|
||||||
class APIProvider{
|
class APIProvider{
|
||||||
String _server, _accessToken, _refreshToken;
|
String _server, _accessToken, _refreshToken;
|
||||||
@ -50,7 +49,7 @@ class APIProvider{
|
|||||||
// this._refreshToken = _refreshToken;
|
// this._refreshToken = _refreshToken;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Future<LoginResponse> login([
|
Future<Login$Query$AuthResponse> login([
|
||||||
String username,
|
String username,
|
||||||
String password,
|
String password,
|
||||||
]) async {
|
]) async {
|
||||||
@ -58,20 +57,10 @@ class APIProvider{
|
|||||||
(username != null && password != null) ||
|
(username != null && password != null) ||
|
||||||
(_accessToken != null && _refreshToken != null)
|
(_accessToken != null && _refreshToken != null)
|
||||||
);
|
);
|
||||||
String loginQuery = """
|
|
||||||
query login(\$user: String!, \$password: String!, \$deviceID: ID) {
|
|
||||||
login(user: \$user, password: \$password, deviceID: \$deviceID) {
|
|
||||||
result,
|
|
||||||
device {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}""";
|
|
||||||
|
|
||||||
|
|
||||||
QueryResult response = await _client.query(
|
QueryResult response = await _client.query(
|
||||||
QueryOptions(
|
QueryOptions(
|
||||||
document: gql(loginQuery),
|
document: LoginQuery().document,
|
||||||
variables: {
|
variables: {
|
||||||
"user": "admin",
|
"user": "admin",
|
||||||
"password": "admin"
|
"password": "admin"
|
||||||
@ -79,7 +68,10 @@ class APIProvider{
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return LoginResponse.fromJson(jsonDecode("{}"));
|
final loginResponse = Login$Query.fromJson(response.data);
|
||||||
|
print(loginResponse);
|
||||||
|
|
||||||
|
return loginResponse.login;
|
||||||
}
|
}
|
||||||
|
|
||||||
void logout() {
|
void logout() {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import 'package:imagini/api/api_provider.dart';
|
import 'package:imagini/api/api_provider.dart';
|
||||||
import 'package:imagini/models/api/response/login_response.dart';
|
import 'package:imagini/graphql/imagini_graphql.dart';
|
||||||
|
|
||||||
class ImaginiAPIRepository {
|
class ImaginiAPIRepository {
|
||||||
APIProvider _apiProvider;
|
APIProvider _apiProvider;
|
||||||
|
|
||||||
ImaginiAPIRepository(this._apiProvider);
|
ImaginiAPIRepository(this._apiProvider);
|
||||||
|
|
||||||
Stream<LoginResponse> login(String user, password) {
|
Stream<Login$Query$AuthResponse> login(String user, password) {
|
||||||
return Stream.fromFuture(_apiProvider.login(user, password));
|
return Stream.fromFuture(_apiProvider.login(user, password));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,14 @@ import 'dart:async';
|
|||||||
import 'package:imagini/core/imagini_application.dart';
|
import 'package:imagini/core/imagini_application.dart';
|
||||||
import 'package:imagini/api/imagini_api_repository.dart';
|
import 'package:imagini/api/imagini_api_repository.dart';
|
||||||
|
|
||||||
import 'package:imagini/models/api/response/login_response.dart';
|
import 'package:imagini/graphql/imagini_graphql.dart';
|
||||||
|
|
||||||
class SplashBloc{
|
class SplashBloc{
|
||||||
|
|
||||||
final ImaginiApplication _application;
|
final ImaginiApplication _application;
|
||||||
|
|
||||||
final _loginController = StreamController<LoginResponse>();
|
final _loginController = StreamController<Login$Query$AuthResponse>();
|
||||||
Stream<LoginResponse> get loginResult => _loginController.stream;
|
Stream<Login$Query$AuthResponse> get loginResult => _loginController.stream;
|
||||||
|
|
||||||
SplashBloc(this._application){
|
SplashBloc(this._application){
|
||||||
_init();
|
_init();
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
export 'imgagini_graphql.graphql.dart';
|
export 'imagini_graphql.graphql.dart';
|
@ -7,7 +7,7 @@ import 'package:equatable/equatable.dart';
|
|||||||
import 'package:gql/ast.dart';
|
import 'package:gql/ast.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
import 'package:imagini/helpers/upload_serializer.dart';
|
import 'package:imagini/helpers/upload_serializer.dart';
|
||||||
part 'imgagini_graphql.graphql.g.dart';
|
part 'imagini_graphql.graphql.g.dart';
|
||||||
|
|
||||||
@JsonSerializable(explicitToJson: true)
|
@JsonSerializable(explicitToJson: true)
|
||||||
class Login$Query$AuthResponse$Device with EquatableMixin {
|
class Login$Query$AuthResponse$Device with EquatableMixin {
|
@ -1,6 +1,6 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
part of 'imgagini_graphql.graphql.dart';
|
part of 'imagini_graphql.graphql.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
// JsonSerializableGenerator
|
// JsonSerializableGenerator
|
@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:fluro/fluro.dart';
|
import 'package:fluro/fluro.dart';
|
||||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||||
|
|
||||||
import 'package:imagini/core/AppProvider.dart';
|
import 'package:imagini/core/app_provider.dart';
|
||||||
|
|
||||||
class LoginScreen extends StatefulWidget {
|
class LoginScreen extends StatefulWidget {
|
||||||
static const String PATH = '/Login';
|
static const String PATH = '/Login';
|
||||||
|
@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||||
import 'package:fluro/fluro.dart';
|
import 'package:fluro/fluro.dart';
|
||||||
|
|
||||||
import 'package:imagini/models/api/response/LoginResponse.dart';
|
import 'package:imagini/core/app_provider.dart';
|
||||||
import 'package:imagini/core/AppProvider.dart';
|
import 'package:imagini/blocs/splash_bloc.dart';
|
||||||
import 'package:imagini/blocs/SplashBloc.dart';
|
import 'package:imagini/graphql/imagini_graphql.dart';
|
||||||
|
|
||||||
class SplashScreen extends StatefulWidget {
|
class SplashScreen extends StatefulWidget {
|
||||||
static const String PATH = '/';
|
static const String PATH = '/';
|
||||||
@ -58,11 +58,11 @@ class _SplashScreenState extends State<SplashScreen> {
|
|||||||
void _init(){
|
void _init(){
|
||||||
if(null == bloc){
|
if(null == bloc){
|
||||||
bloc = SplashBloc(AppProvider.getApplication(context));
|
bloc = SplashBloc(AppProvider.getApplication(context));
|
||||||
bloc.loginResult.listen((LoginResponse lr) {
|
bloc.loginResult.listen((Login$Query$AuthResponse lr) {
|
||||||
if (lr.error != null) {
|
if (lr.result != AuthResult.success) {
|
||||||
AppProvider.getRouter(context).navigateTo(context, "/Login", transition: TransitionType.fadeIn);
|
|
||||||
} else {
|
|
||||||
AppProvider.getRouter(context).navigateTo(context, "/Home", transition: TransitionType.fadeIn);
|
AppProvider.getRouter(context).navigateTo(context, "/Home", transition: TransitionType.fadeIn);
|
||||||
|
} else {
|
||||||
|
AppProvider.getRouter(context).navigateTo(context, "/Login", transition: TransitionType.fadeIn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user