Jason Law

GraphQLResponse inherit Response info

@@ -319,7 +319,7 @@ class GetConnect extends GetConnectInterface { @@ -319,7 +319,7 @@ class GetConnect extends GetConnectInterface {
319 )) 319 ))
320 .toList()); 320 .toList());
321 } 321 }
322 - return GraphQLResponse<T>(body: res.body['data'] as T?); 322 + return GraphQLResponse<T>.fromResponse(res);
323 } on Exception catch (_) { 323 } on Exception catch (_) {
324 return GraphQLResponse<T>(graphQLErrors: [ 324 return GraphQLResponse<T>(graphQLErrors: [
325 GraphQLError( 325 GraphQLError(
@@ -355,7 +355,7 @@ class GetConnect extends GetConnectInterface { @@ -355,7 +355,7 @@ class GetConnect extends GetConnectInterface {
355 )) 355 ))
356 .toList()); 356 .toList());
357 } 357 }
358 - return GraphQLResponse<T>(body: res.body['data'] as T?); 358 + return GraphQLResponse<T>.fromResponse(res);
359 } on Exception catch (_) { 359 } on Exception catch (_) {
360 return GraphQLResponse<T>(graphQLErrors: [ 360 return GraphQLResponse<T>(graphQLErrors: [
361 GraphQLError( 361 GraphQLError(
@@ -7,6 +7,16 @@ import '../status/http_status.dart'; @@ -7,6 +7,16 @@ import '../status/http_status.dart';
7 class GraphQLResponse<T> extends Response<T> { 7 class GraphQLResponse<T> extends Response<T> {
8 final List<GraphQLError>? graphQLErrors; 8 final List<GraphQLError>? graphQLErrors;
9 GraphQLResponse({T? body, this.graphQLErrors}) : super(body: body); 9 GraphQLResponse({T? body, this.graphQLErrors}) : super(body: body);
  10 + GraphQLResponse.fromResponse(Response res)
  11 + : graphQLErrors = null,
  12 + super(
  13 + request: res.request,
  14 + statusCode: res.statusCode,
  15 + bodyBytes: res.bodyBytes,
  16 + bodyString: res.bodyString,
  17 + statusText: res.statusText,
  18 + headers: res.headers,
  19 + body: res.body['data'] as T?);
10 } 20 }
11 21
12 class Response<T> { 22 class Response<T> {
@@ -60,7 +70,8 @@ class Response<T> { @@ -60,7 +70,8 @@ class Response<T> {
60 final T? body; 70 final T? body;
61 } 71 }
62 72
63 -Future<String> bodyBytesToString(Stream<List<int>> bodyBytes, Map<String, String> headers) { 73 +Future<String> bodyBytesToString(
  74 + Stream<List<int>> bodyBytes, Map<String, String> headers) {
64 return bodyBytes.bytesToString(_encodingForHeaders(headers)); 75 return bodyBytes.bytesToString(_encodingForHeaders(headers));
65 } 76 }
66 77
@@ -101,7 +112,9 @@ class HeaderValue { @@ -101,7 +112,9 @@ class HeaderValue {
101 } 112 }
102 113
103 static HeaderValue parse(String value, 114 static HeaderValue parse(String value,
104 - {String parameterSeparator = ';', String? valueSeparator, bool preserveBackslash = false}) { 115 + {String parameterSeparator = ';',
  116 + String? valueSeparator,
  117 + bool preserveBackslash = false}) {
105 var result = HeaderValue(); 118 var result = HeaderValue();
106 result._parse(value, parameterSeparator, valueSeparator, preserveBackslash); 119 result._parse(value, parameterSeparator, valueSeparator, preserveBackslash);
107 return result; 120 return result;
@@ -131,7 +144,8 @@ class HeaderValue { @@ -131,7 +144,8 @@ class HeaderValue {
131 return stringBuffer.toString(); 144 return stringBuffer.toString();
132 } 145 }
133 146
134 - void _parse(String value, String parameterSeparator, String? valueSeparator, bool preserveBackslash) { 147 + void _parse(String value, String parameterSeparator, String? valueSeparator,
  148 + bool preserveBackslash) {
135 var index = 0; 149 var index = 0;
136 150
137 bool done() => index == value.length; 151 bool done() => index == value.length;