shawon1fb

response.copyWith method added

1 import 'dart:collection'; 1 import 'dart:collection';
2 import 'dart:convert'; 2 import 'dart:convert';
  3 +
3 import '../exceptions/exceptions.dart'; 4 import '../exceptions/exceptions.dart';
4 import '../request/request.dart'; 5 import '../request/request.dart';
5 import '../status/http_status.dart'; 6 import '../status/http_status.dart';
6 7
7 class GraphQLResponse<T> extends Response<T> { 8 class GraphQLResponse<T> extends Response<T> {
8 final List<GraphQLError>? graphQLErrors; 9 final List<GraphQLError>? graphQLErrors;
  10 +
9 GraphQLResponse({T? body, this.graphQLErrors}) : super(body: body); 11 GraphQLResponse({T? body, this.graphQLErrors}) : super(body: body);
  12 +
10 GraphQLResponse.fromResponse(Response res) 13 GraphQLResponse.fromResponse(Response res)
11 : graphQLErrors = null, 14 : graphQLErrors = null,
12 super( 15 super(
@@ -30,6 +33,26 @@ class Response<T> { @@ -30,6 +33,26 @@ class Response<T> {
30 this.body, 33 this.body,
31 }); 34 });
32 35
  36 + Response<T> copyWith({
  37 + Request? request,
  38 + int? statusCode,
  39 + Stream<List<int>>? bodyBytes,
  40 + String? bodyString,
  41 + String? statusText,
  42 + Map<String, String>? headers,
  43 + T? body,
  44 + }) {
  45 + return Response<T>(
  46 + request: request ?? this.request,
  47 + statusCode: statusCode ?? this.statusCode,
  48 + bodyBytes: bodyBytes ?? this.bodyBytes,
  49 + bodyString: bodyString ?? this.bodyString,
  50 + statusText: statusText ?? this.statusText,
  51 + headers: headers ?? this.headers,
  52 + body: body ?? this.body,
  53 + );
  54 + }
  55 +
33 /// The Http [Request] linked with this [Response]. 56 /// The Http [Request] linked with this [Response].
34 final Request? request; 57 final Request? request;
35 58