mirror of
https://github.com/foss42/apidash.git
synced 2025-12-04 20:13:56 +08:00
streamHttpRequest: Added GraphQL Ability
This commit is contained in:
@@ -232,7 +232,7 @@ streamHttpRequest(
|
|||||||
http.StreamedResponse streamedResponse;
|
http.StreamedResponse streamedResponse;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//HANDLE MULTI-PART
|
//Handling HTTP Multipart Requests
|
||||||
if (apiType == APIType.rest && isMultipart && hasBody) {
|
if (apiType == APIType.rest && isMultipart && hasBody) {
|
||||||
final multipart = http.MultipartRequest(
|
final multipart = http.MultipartRequest(
|
||||||
requestModel.method.name.toUpperCase(),
|
requestModel.method.name.toUpperCase(),
|
||||||
@@ -248,6 +248,24 @@ streamHttpRequest(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
streamedResponse = await client.send(multipart);
|
streamedResponse = await client.send(multipart);
|
||||||
|
} else if (apiType == APIType.graphql) {
|
||||||
|
// Handling GraphQL Requests
|
||||||
|
var requestBody = getGraphQLBody(requestModel);
|
||||||
|
String? body;
|
||||||
|
if (requestBody != null) {
|
||||||
|
var contentLength = utf8.encode(requestBody).length;
|
||||||
|
if (contentLength > 0) {
|
||||||
|
body = requestBody;
|
||||||
|
headers[HttpHeaders.contentLengthHeader] = contentLength.toString();
|
||||||
|
if (!requestModel.hasContentTypeHeader) {
|
||||||
|
headers[HttpHeaders.contentTypeHeader] = ContentType.json.header;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final request = http.Request('POST', uri)
|
||||||
|
..headers.addAll(headers)
|
||||||
|
..body = body ?? '';
|
||||||
|
streamedResponse = await client.send(request);
|
||||||
} else {
|
} else {
|
||||||
String? body;
|
String? body;
|
||||||
bool overrideContentType = false;
|
bool overrideContentType = false;
|
||||||
@@ -274,7 +292,6 @@ streamHttpRequest(
|
|||||||
|
|
||||||
subscription = outputStream.listen(
|
subscription = outputStream.listen(
|
||||||
(data) {
|
(data) {
|
||||||
if (!controller.isClosed) {
|
|
||||||
HttpResponse? resp;
|
HttpResponse? resp;
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
resp = HttpResponse.bytes(
|
resp = HttpResponse.bytes(
|
||||||
@@ -286,8 +303,8 @@ streamHttpRequest(
|
|||||||
persistentConnection: streamedResponse.persistentConnection,
|
persistentConnection: streamedResponse.persistentConnection,
|
||||||
reasonPhrase: streamedResponse.reasonPhrase,
|
reasonPhrase: streamedResponse.reasonPhrase,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
if (!controller.isClosed) {
|
if (!controller.isClosed) {
|
||||||
|
//if it is partial response chunk, complete it here only and then send
|
||||||
controller.add((resp, stopwatch.elapsed, null));
|
controller.add((resp, stopwatch.elapsed, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user