Skip to content

Commit 37d99e6

Browse files
committed
Prettier
1 parent 638293b commit 37d99e6

4 files changed

Lines changed: 92 additions & 65 deletions

File tree

packages/apollo-angular/http/src/http-batch-link.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { print } from 'graphql';
22
import { Observable } from 'rxjs';
3-
import { HttpClient, HttpContext, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
3+
import { HttpClient, HttpContext, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
44
import { Injectable } from '@angular/core';
55
import { ApolloLink } from '@apollo/client';
6-
import { BatchLink } from '@apollo/client/link/batch';
76
import { ServerError } from '@apollo/client/errors';
7+
import { BatchLink } from '@apollo/client/link/batch';
88
import type { HttpLink } from './http-link';
99
import { Body, Context, OperationPrinter, Request } from './types';
1010
import {
@@ -36,16 +36,14 @@ function convertHttpErrorToApolloError(err: HttpErrorResponse): Error {
3636
});
3737

3838
// Get the body text
39-
const bodyText = typeof err.error === 'string'
40-
? err.error
41-
: JSON.stringify(err.error || {});
39+
const bodyText = typeof err.error === 'string' ? err.error : JSON.stringify(err.error || {});
4240

4341
// Return ServerError for non-2xx status codes (following Apollo Client's logic)
4442
if (err.status >= 300) {
45-
return new ServerError(
46-
`Response not successful: Received status code ${err.status}`,
47-
{ response: mockResponse, bodyText }
48-
);
43+
return new ServerError(`Response not successful: Received status code ${err.status}`, {
44+
response: mockResponse,
45+
bodyText,
46+
});
4947
}
5048

5149
// For other HttpErrorResponse cases, return a generic error
@@ -128,7 +126,8 @@ export class HttpBatchLinkHandler extends ApolloLink {
128126
}).subscribe({
129127
next: result => observer.next(result.body),
130128
error: err => {
131-
if (err instanceof HttpErrorResponse) observer.error(convertHttpErrorToApolloError(err));
129+
if (err instanceof HttpErrorResponse)
130+
observer.error(convertHttpErrorToApolloError(err));
132131
else observer.error(err);
133132
},
134133
complete: () => observer.complete(),

packages/apollo-angular/http/src/http-link.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ function convertHttpErrorToApolloError(err: HttpErrorResponse): Error {
3737
});
3838

3939
// Get the body text
40-
const bodyText = typeof err.error === 'string'
41-
? err.error
42-
: JSON.stringify(err.error || {});
40+
const bodyText = typeof err.error === 'string' ? err.error : JSON.stringify(err.error || {});
4341

4442
// Return ServerError for non-2xx status codes (following Apollo Client's logic)
4543
if (err.status >= 300) {
46-
return new ServerError(
47-
`Response not successful: Received status code ${err.status}`,
48-
{ response: mockResponse, bodyText }
49-
);
44+
return new ServerError(`Response not successful: Received status code ${err.status}`, {
45+
response: mockResponse,
46+
bodyText,
47+
});
5048
}
5149

5250
// For other HttpErrorResponse cases, return a generic error
@@ -133,7 +131,8 @@ export class HttpLinkHandler extends ApolloLink {
133131
observer.next(response.body);
134132
},
135133
error: err => {
136-
if (err instanceof HttpErrorResponse) observer.error(convertHttpErrorToApolloError(err));
134+
if (err instanceof HttpErrorResponse)
135+
observer.error(convertHttpErrorToApolloError(err));
137136
else observer.error(err);
138137
},
139138
complete: () => observer.complete(),

packages/apollo-angular/http/tests/http-batch-link.spec.ts

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,9 @@ describe('HttpBatchLink', () => {
834834
variables: {},
835835
};
836836
const errorBody = {
837-
errors: [{ message: 'Validation error', extensions: { code: 'GRAPHQL_VALIDATION_FAILED' } }],
837+
errors: [
838+
{ message: 'Validation error', extensions: { code: 'GRAPHQL_VALIDATION_FAILED' } },
839+
],
838840
};
839841

840842
execute(link, op).subscribe({
@@ -853,7 +855,9 @@ describe('HttpBatchLink', () => {
853855
});
854856

855857
setTimeout(() => {
856-
httpBackend.expectOne('graphql').flush([errorBody], { status: 400, statusText: 'Bad Request' });
858+
httpBackend
859+
.expectOne('graphql')
860+
.flush([errorBody], { status: 400, statusText: 'Bad Request' });
857861
}, 50);
858862
}));
859863

@@ -887,7 +891,9 @@ describe('HttpBatchLink', () => {
887891
});
888892

889893
setTimeout(() => {
890-
httpBackend.expectOne('graphql').flush(errorBody, { status: 500, statusText: 'Internal Server Error' });
894+
httpBackend
895+
.expectOne('graphql')
896+
.flush(errorBody, { status: 500, statusText: 'Internal Server Error' });
891897
}, 50);
892898
}));
893899

@@ -904,7 +910,10 @@ describe('HttpBatchLink', () => {
904910
variables: {},
905911
};
906912
const errorBody = [{ errors: [{ message: 'Not found' }] }];
907-
const customHeaders = new HttpHeaders({ 'X-Custom-Header': 'test-value', 'X-Request-ID': '12345' });
913+
const customHeaders = new HttpHeaders({
914+
'X-Custom-Header': 'test-value',
915+
'X-Request-ID': '12345',
916+
});
908917

909918
execute(link, op).subscribe({
910919
next: () => {
@@ -932,7 +941,7 @@ describe('HttpBatchLink', () => {
932941
httpBackend.expectOne('graphql').flush(errorBody, {
933942
status: 404,
934943
statusText: 'Not Found',
935-
headers: customHeaders
944+
headers: customHeaders,
936945
});
937946
}, 50);
938947
}));
@@ -972,14 +981,15 @@ describe('HttpBatchLink', () => {
972981
});
973982

974983
setTimeout(() => {
975-
httpBackend.expectOne('graphql').flush(
976-
[{ errors: [{ message: 'Bad request' }] }],
977-
{ status: 400, statusText: 'Bad Request' }
978-
);
984+
httpBackend
985+
.expectOne('graphql')
986+
.flush([{ errors: [{ message: 'Bad request' }] }], {
987+
status: 400,
988+
statusText: 'Bad Request',
989+
});
979990
}, 50);
980991
}));
981992

982-
983993
test('should extract body text from string error', () =>
984994
new Promise<void>(done => {
985995
const link = httpLink.create({ uri: 'graphql' });
@@ -1006,7 +1016,9 @@ describe('HttpBatchLink', () => {
10061016
});
10071017

10081018
setTimeout(() => {
1009-
httpBackend.expectOne('graphql').flush(errorBody, { status: 500, statusText: 'Server Error' });
1019+
httpBackend
1020+
.expectOne('graphql')
1021+
.flush(errorBody, { status: 500, statusText: 'Server Error' });
10101022
}, 50);
10111023
}));
10121024

@@ -1036,7 +1048,9 @@ describe('HttpBatchLink', () => {
10361048
});
10371049

10381050
setTimeout(() => {
1039-
httpBackend.expectOne('graphql').flush(errorBody, { status: 400, statusText: 'Bad Request' });
1051+
httpBackend
1052+
.expectOne('graphql')
1053+
.flush(errorBody, { status: 400, statusText: 'Bad Request' });
10401054
}, 50);
10411055
}));
10421056

@@ -1094,7 +1108,9 @@ describe('HttpBatchLink', () => {
10941108
});
10951109

10961110
setTimeout(() => {
1097-
httpBackend.expectOne('graphql').flush([{ data }], { status: 299, statusText: 'Custom Success' });
1111+
httpBackend
1112+
.expectOne('graphql')
1113+
.flush([{ data }], { status: 299, statusText: 'Custom Success' });
10981114
}, 50);
10991115
}));
11001116

@@ -1124,10 +1140,9 @@ describe('HttpBatchLink', () => {
11241140
});
11251141

11261142
setTimeout(() => {
1127-
httpBackend.expectOne('graphql').flush(
1128-
[{ errors: [{ message: 'Error' }] }],
1129-
{ status: 300, statusText: 'Error' }
1130-
);
1143+
httpBackend
1144+
.expectOne('graphql')
1145+
.flush([{ errors: [{ message: 'Error' }] }], { status: 300, statusText: 'Error' });
11311146
}, 50);
11321147
}));
11331148

@@ -1157,10 +1172,9 @@ describe('HttpBatchLink', () => {
11571172
});
11581173

11591174
setTimeout(() => {
1160-
httpBackend.expectOne('graphql').flush(
1161-
[{ errors: [{ message: 'Error' }] }],
1162-
{ status: 404, statusText: 'Not Found' }
1163-
);
1175+
httpBackend
1176+
.expectOne('graphql')
1177+
.flush([{ errors: [{ message: 'Error' }] }], { status: 404, statusText: 'Not Found' });
11641178
}, 50);
11651179
}));
11661180

@@ -1190,10 +1204,12 @@ describe('HttpBatchLink', () => {
11901204
});
11911205

11921206
setTimeout(() => {
1193-
httpBackend.expectOne('graphql').flush(
1194-
[{ errors: [{ message: 'Error' }] }],
1195-
{ status: 503, statusText: 'Service Unavailable' }
1196-
);
1207+
httpBackend
1208+
.expectOne('graphql')
1209+
.flush([{ errors: [{ message: 'Error' }] }], {
1210+
status: 503,
1211+
statusText: 'Service Unavailable',
1212+
});
11971213
}, 50);
11981214
}));
11991215
});

packages/apollo-angular/http/tests/http-link.spec.ts

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,9 @@ describe('HttpLink', () => {
806806
variables: {},
807807
};
808808
const errorBody = {
809-
errors: [{ message: 'Validation error', extensions: { code: 'GRAPHQL_VALIDATION_FAILED' } }],
809+
errors: [
810+
{ message: 'Validation error', extensions: { code: 'GRAPHQL_VALIDATION_FAILED' } },
811+
],
810812
};
811813

812814
execute(link, op).subscribe({
@@ -853,7 +855,9 @@ describe('HttpLink', () => {
853855
},
854856
});
855857

856-
httpBackend.expectOne('graphql').flush(errorBody, { status: 500, statusText: 'Internal Server Error' });
858+
httpBackend
859+
.expectOne('graphql')
860+
.flush(errorBody, { status: 500, statusText: 'Internal Server Error' });
857861
});
858862

859863
test('should include all response properties in ServerError', () => {
@@ -868,7 +872,10 @@ describe('HttpLink', () => {
868872
variables: {},
869873
};
870874
const errorBody = { errors: [{ message: 'Not found' }] };
871-
const customHeaders = new HttpHeaders({ 'X-Custom-Header': 'test-value', 'X-Request-ID': '12345' });
875+
const customHeaders = new HttpHeaders({
876+
'X-Custom-Header': 'test-value',
877+
'X-Request-ID': '12345',
878+
});
872879

873880
execute(link, op).subscribe({
874881
next: () => {
@@ -894,7 +901,7 @@ describe('HttpLink', () => {
894901
httpBackend.expectOne('graphql').flush(errorBody, {
895902
status: 404,
896903
statusText: 'Not Found',
897-
headers: customHeaders
904+
headers: customHeaders,
898905
});
899906
});
900907

@@ -930,10 +937,12 @@ describe('HttpLink', () => {
930937
},
931938
});
932939

933-
httpBackend.expectOne('graphql').flush(
934-
{ errors: [{ message: 'Bad request' }] },
935-
{ status: 400, statusText: 'Bad Request' }
936-
);
940+
httpBackend
941+
.expectOne('graphql')
942+
.flush(
943+
{ errors: [{ message: 'Bad request' }] },
944+
{ status: 400, statusText: 'Bad Request' },
945+
);
937946
});
938947

939948
test('should extract body text from string error', () => {
@@ -959,7 +968,9 @@ describe('HttpLink', () => {
959968
},
960969
});
961970

962-
httpBackend.expectOne('graphql').flush(errorBody, { status: 500, statusText: 'Server Error' });
971+
httpBackend
972+
.expectOne('graphql')
973+
.flush(errorBody, { status: 500, statusText: 'Server Error' });
963974
});
964975

965976
test('should extract body text from object error', () => {
@@ -1035,7 +1046,9 @@ describe('HttpLink', () => {
10351046
},
10361047
});
10371048

1038-
httpBackend.expectOne('graphql').flush({ data }, { status: 299, statusText: 'Custom Success' });
1049+
httpBackend
1050+
.expectOne('graphql')
1051+
.flush({ data }, { status: 299, statusText: 'Custom Success' });
10391052
});
10401053

10411054
test('should create ServerError for status 300', () => {
@@ -1061,10 +1074,9 @@ describe('HttpLink', () => {
10611074
},
10621075
});
10631076

1064-
httpBackend.expectOne('graphql').flush(
1065-
{ errors: [{ message: 'Error' }] },
1066-
{ status: 300, statusText: 'Error' }
1067-
);
1077+
httpBackend
1078+
.expectOne('graphql')
1079+
.flush({ errors: [{ message: 'Error' }] }, { status: 300, statusText: 'Error' });
10681080
});
10691081

10701082
test('should create ServerError for status 404', () => {
@@ -1090,10 +1102,9 @@ describe('HttpLink', () => {
10901102
},
10911103
});
10921104

1093-
httpBackend.expectOne('graphql').flush(
1094-
{ errors: [{ message: 'Error' }] },
1095-
{ status: 404, statusText: 'Not Found' }
1096-
);
1105+
httpBackend
1106+
.expectOne('graphql')
1107+
.flush({ errors: [{ message: 'Error' }] }, { status: 404, statusText: 'Not Found' });
10971108
});
10981109

10991110
test('should create ServerError for status 503', () => {
@@ -1119,10 +1130,12 @@ describe('HttpLink', () => {
11191130
},
11201131
});
11211132

1122-
httpBackend.expectOne('graphql').flush(
1123-
{ errors: [{ message: 'Error' }] },
1124-
{ status: 503, statusText: 'Service Unavailable' }
1125-
);
1133+
httpBackend
1134+
.expectOne('graphql')
1135+
.flush(
1136+
{ errors: [{ message: 'Error' }] },
1137+
{ status: 503, statusText: 'Service Unavailable' },
1138+
);
11261139
});
11271140
});
11281141
});

0 commit comments

Comments
 (0)