Skip to content

Commit cafb23a

Browse files
committed
Move away from deprecated things
1 parent a564953 commit cafb23a

File tree

8 files changed

+29
-35
lines changed

8 files changed

+29
-35
lines changed

.changeset/long-apes-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'apollo-angular': patch
3+
---
4+
5+
Move away from deprecated things

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class HttpBatchLinkHandler extends ApolloLink {
160160
const context: Context & { skipBatching?: boolean } = operation.getContext();
161161

162162
if (context.skipBatching) {
163-
return Math.random().toString(36).substr(2, 9);
163+
return Math.random().toString(36).substring(2, 11);
164164
}
165165

166166
const headers =

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { HttpClientModule, HttpHeaders } from '@angular/common/http';
2-
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
1+
import { HttpHeaders, provideHttpClient } from '@angular/common/http';
2+
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
33
import { TestBed } from '@angular/core/testing';
44
import { ApolloLink, execute, gql, Operation } from '@apollo/client/core';
55
import { HttpBatchLink } from '../src/http-batch-link';
@@ -14,8 +14,7 @@ describe('HttpBatchLink', () => {
1414

1515
beforeEach(() => {
1616
TestBed.configureTestingModule({
17-
imports: [HttpClientModule, HttpClientTestingModule],
18-
providers: [HttpBatchLink],
17+
providers: [provideHttpClient(), provideHttpClientTesting(), HttpBatchLink],
1918
});
2019
httpLink = TestBed.inject(HttpBatchLink);
2120
httpBackend = TestBed.inject(HttpTestingController);

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { print, stripIgnoredCharacters } from 'graphql';
22
import { mergeMap } from 'rxjs/operators';
3-
import { HttpClientModule, HttpHeaders } from '@angular/common/http';
4-
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
3+
import { HttpHeaders, provideHttpClient } from '@angular/common/http';
4+
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
55
import { TestBed } from '@angular/core/testing';
66
import { ApolloLink, execute, gql, InMemoryCache } from '@apollo/client/core';
77
import { Apollo } from '../../src';
@@ -17,8 +17,7 @@ describe('HttpLink', () => {
1717

1818
beforeEach(() => {
1919
TestBed.configureTestingModule({
20-
imports: [HttpClientModule, HttpClientTestingModule],
21-
providers: [HttpLink, Apollo],
20+
providers: [provideHttpClient(), provideHttpClientTesting(), HttpLink, Apollo],
2221
});
2322
httpLink = TestBed.inject(HttpLink);
2423
httpBackend = TestBed.inject(HttpTestingController);
@@ -544,7 +543,7 @@ describe('HttpLink', () => {
544543
});
545544

546545
test('should work with mergeMap', done => {
547-
const apollo: Apollo = TestBed.get(Apollo);
546+
const apollo = TestBed.inject(Apollo);
548547

549548
const op1 = {
550549
query: gql`

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { filter, first } from 'rxjs/operators';
2-
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
1+
import { firstValueFrom } from 'rxjs';
2+
import { filter } from 'rxjs/operators';
3+
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
34
import { ApplicationRef, Component, destroyPlatform, getPlatform, NgModule } from '@angular/core';
4-
import { BrowserModule } from '@angular/platform-browser';
55
import {
66
INITIAL_CONFIG,
77
platformServer,
@@ -66,12 +66,8 @@ describe.skip('integration', () => {
6666

6767
@NgModule({
6868
declarations: [AsyncServerApp],
69-
imports: [
70-
BrowserModule.withServerTransition({ appId: 'async-server' }),
71-
ServerModule,
72-
HttpClientTestingModule,
73-
],
74-
providers: [HttpLink],
69+
imports: [ServerModule],
70+
providers: [provideHttpClientTesting(), HttpLink],
7571
bootstrap: [AsyncServerApp],
7672
})
7773
class AsyncServerModule {}
@@ -87,12 +83,7 @@ describe.skip('integration', () => {
8783
]);
8884
const moduleRef = await platform.bootstrapModule(AsyncServerModule);
8985
const applicationRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
90-
await applicationRef.isStable
91-
.pipe(
92-
filter((isStable: boolean) => isStable),
93-
first(),
94-
)
95-
.toPromise();
86+
await firstValueFrom(applicationRef.isStable.pipe(filter(isStable => isStable)));
9687
const str = platform.injector.get(PlatformState).renderToString();
9788

9889
expect(clearNgVersion(str)).toMatchSnapshot();

packages/apollo-angular/testing/tests/integration.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ describe('Integration', () => {
176176
],
177177
});
178178

179-
const apollo: Apollo = TestBed.get(Apollo);
180-
const backend: ApolloTestingController = TestBed.get(ApolloTestingController);
179+
const apollo = TestBed.inject(Apollo);
180+
const backend = TestBed.inject(ApolloTestingController);
181181

182182
const query = gql`
183183
{

packages/apollo-angular/tests/Apollo.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe('Apollo', () => {
217217
obs.subscribe({
218218
error,
219219
complete: () => {
220-
expect(error).not.toBeCalled();
220+
expect(error).not.toHaveBeenCalled();
221221
done();
222222
},
223223
});
@@ -240,11 +240,11 @@ describe('Apollo', () => {
240240

241241
const obs = apollo.query({} as any);
242242

243-
expect(client.query).not.toBeCalled();
243+
expect(client.query).not.toHaveBeenCalled();
244244

245245
obs.subscribe({
246246
complete: () => {
247-
expect(client.query).toBeCalled();
247+
expect(client.query).toHaveBeenCalled();
248248
done();
249249
},
250250
});
@@ -371,7 +371,7 @@ describe('Apollo', () => {
371371
obs.subscribe({
372372
error,
373373
complete: () => {
374-
expect(error).not.toBeCalled();
374+
expect(error).not.toHaveBeenCalled();
375375
done();
376376
},
377377
});
@@ -394,11 +394,11 @@ describe('Apollo', () => {
394394

395395
const obs = apollo.mutate({} as any);
396396

397-
expect(client.mutate).not.toBeCalled();
397+
expect(client.mutate).not.toHaveBeenCalled();
398398

399399
obs.subscribe({
400400
complete: () => {
401-
expect(client.mutate).toBeCalled();
401+
expect(client.mutate).toHaveBeenCalled();
402402
done();
403403
},
404404
});

packages/apollo-angular/tests/integration.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HttpClientModule } from '@angular/common/http';
1+
import { provideHttpClient } from '@angular/common/http';
22
import { TestBed } from '@angular/core/testing';
33
import { InMemoryCache } from '@apollo/client/core';
44
import { mockSingleLink } from '@apollo/client/testing';
@@ -8,8 +8,8 @@ describe('Integration', () => {
88
describe('default', () => {
99
beforeEach(() => {
1010
TestBed.configureTestingModule({
11-
imports: [HttpClientModule],
1211
providers: [
12+
provideHttpClient(),
1313
provideApollo(() => {
1414
return {
1515
link: mockSingleLink(),

0 commit comments

Comments
 (0)