From f0b2ac0c90624b3d006a7c72b9046bc81a9f9c05 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Thu, 2 May 2024 16:45:59 +0700 Subject: [PATCH] Injections are readonly --- .changeset/dirty-pigs-suffer.md | 2 +- packages/apollo-angular/README.md | 2 +- packages/apollo-angular/http/src/http-batch-link.ts | 6 +++--- packages/apollo-angular/http/src/http-link.ts | 6 +++--- packages/apollo-angular/http/tests/ssr.spec.ts | 4 ++-- packages/apollo-angular/src/apollo.ts | 4 ++-- packages/apollo-angular/src/mutation.ts | 2 +- packages/apollo-angular/src/query-ref.ts | 2 +- packages/apollo-angular/src/query.ts | 2 +- packages/apollo-angular/src/subscription.ts | 2 +- packages/apollo-angular/src/utils.ts | 2 +- packages/apollo-angular/testing/src/operation.ts | 4 ++-- .../src/app/pages/author/author-page.component.ts | 4 ++-- .../demo/src/app/pages/posts/posts-page.component.ts | 2 +- .../demo/src/app/pages/posts/upvoter.component.ts | 2 +- scripts/prepare-e2e.js | 2 +- website/src/pages/docs/caching/advanced-topics.mdx | 2 +- website/src/pages/docs/data/error-handling.mdx | 2 +- website/src/pages/docs/data/mutations.mdx | 12 ++++++------ website/src/pages/docs/data/queries.mdx | 8 ++++---- website/src/pages/docs/data/services.mdx | 6 +++--- .../pages/docs/development-and-testing/testing.mdx | 2 +- website/src/pages/docs/get-started.mdx | 2 +- .../managing-state-with-field-policies.mdx | 2 +- .../pages/docs/performance/improving-performance.mdx | 2 +- website/src/pages/docs/recipes/authentication.mdx | 2 +- 26 files changed, 44 insertions(+), 44 deletions(-) diff --git a/.changeset/dirty-pigs-suffer.md b/.changeset/dirty-pigs-suffer.md index 7e174186c..587c5126f 100644 --- a/.changeset/dirty-pigs-suffer.md +++ b/.changeset/dirty-pigs-suffer.md @@ -1,5 +1,5 @@ --- -"apollo-angular": patch +'apollo-angular': patch --- ApolloClient does not delay the application becoming stable diff --git a/packages/apollo-angular/README.md b/packages/apollo-angular/README.md index b9dee571b..dcae72d72 100644 --- a/packages/apollo-angular/README.md +++ b/packages/apollo-angular/README.md @@ -84,7 +84,7 @@ const GET_DOGS = gql` export class DogsComponent implements OnInit { dogs: Observable; - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} ngOnInit() { this.dogs = this.apollo diff --git a/packages/apollo-angular/http/src/http-batch-link.ts b/packages/apollo-angular/http/src/http-batch-link.ts index dc8560c5d..b18aca58c 100644 --- a/packages/apollo-angular/http/src/http-batch-link.ts +++ b/packages/apollo-angular/http/src/http-batch-link.ts @@ -40,8 +40,8 @@ export class HttpBatchLinkHandler extends ApolloLink { private print: OperationPrinter = print; constructor( - private httpClient: HttpClient, - private options: BatchOptions, + private readonly httpClient: HttpClient, + private readonly options: BatchOptions, ) { super(); @@ -184,7 +184,7 @@ export class HttpBatchLinkHandler extends ApolloLink { providedIn: 'root', }) export class HttpBatchLink { - constructor(private httpClient: HttpClient) {} + constructor(private readonly httpClient: HttpClient) {} public create(options: BatchOptions): HttpBatchLinkHandler { return new HttpBatchLinkHandler(this.httpClient, options); diff --git a/packages/apollo-angular/http/src/http-link.ts b/packages/apollo-angular/http/src/http-link.ts index 35b1c0530..7d40d281f 100644 --- a/packages/apollo-angular/http/src/http-link.ts +++ b/packages/apollo-angular/http/src/http-link.ts @@ -17,8 +17,8 @@ export class HttpLinkHandler extends ApolloLink { private print: OperationPrinter = print; constructor( - private httpClient: HttpClient, - private options: Options, + private readonly httpClient: HttpClient, + private readonly options: Options, ) { super(); @@ -98,7 +98,7 @@ export class HttpLinkHandler extends ApolloLink { providedIn: 'root', }) export class HttpLink { - constructor(private httpClient: HttpClient) {} + constructor(private readonly httpClient: HttpClient) {} public create(options: Options): HttpLinkHandler { return new HttpLinkHandler(this.httpClient, options); diff --git a/packages/apollo-angular/http/tests/ssr.spec.ts b/packages/apollo-angular/http/tests/ssr.spec.ts index 584a77128..3264bbdea 100644 --- a/packages/apollo-angular/http/tests/ssr.spec.ts +++ b/packages/apollo-angular/http/tests/ssr.spec.ts @@ -45,8 +45,8 @@ describe.skip('integration', () => { public text = 'online'; constructor( - private httpLink: HttpLink, - private httpBackend: HttpTestingController, + private readonly httpLink: HttpLink, + private readonly httpBackend: HttpTestingController, ) {} public ngOnInit() { diff --git a/packages/apollo-angular/src/apollo.ts b/packages/apollo-angular/src/apollo.ts index b2c4353c9..10ffdfaec 100644 --- a/packages/apollo-angular/src/apollo.ts +++ b/packages/apollo-angular/src/apollo.ts @@ -28,8 +28,8 @@ export class ApolloBase { private useMutationLoading: boolean; constructor( - protected ngZone: NgZone, - protected flags?: Flags, + protected readonly ngZone: NgZone, + protected readonly flags?: Flags, protected _client?: ApolloClient, ) { this.useInitialLoading = flags?.useInitialLoading ?? false; diff --git a/packages/apollo-angular/src/mutation.ts b/packages/apollo-angular/src/mutation.ts index 5e70c7b58..7d706ece6 100644 --- a/packages/apollo-angular/src/mutation.ts +++ b/packages/apollo-angular/src/mutation.ts @@ -10,7 +10,7 @@ export abstract class Mutation; public client = 'default'; - constructor(protected apollo: Apollo) {} + constructor(protected readonly apollo: Apollo) {} public mutate( variables?: V, diff --git a/packages/apollo-angular/src/query-ref.ts b/packages/apollo-angular/src/query-ref.ts index 0cd07f371..4dce2a3de 100644 --- a/packages/apollo-angular/src/query-ref.ts +++ b/packages/apollo-angular/src/query-ref.ts @@ -51,7 +51,7 @@ export class QueryRef { public queryId: ObservableQuery['queryId']; constructor( - private obsQuery: ObservableQuery, + private readonly obsQuery: ObservableQuery, ngZone: NgZone, options: WatchQueryOptions, ) { diff --git a/packages/apollo-angular/src/query.ts b/packages/apollo-angular/src/query.ts index a6b377116..00b2a5d82 100644 --- a/packages/apollo-angular/src/query.ts +++ b/packages/apollo-angular/src/query.ts @@ -11,7 +11,7 @@ export abstract class Query public abstract readonly document: DocumentNode | TypedDocumentNode; public client = 'default'; - constructor(protected apollo: Apollo) {} + constructor(protected readonly apollo: Apollo) {} public watch(variables?: V, options?: WatchQueryOptionsAlone): QueryRef { return this.apollo.use(this.client).watchQuery({ diff --git a/packages/apollo-angular/src/subscription.ts b/packages/apollo-angular/src/subscription.ts index 71ae26921..290fd29ca 100644 --- a/packages/apollo-angular/src/subscription.ts +++ b/packages/apollo-angular/src/subscription.ts @@ -15,7 +15,7 @@ export abstract class Subscription; public client = 'default'; - constructor(protected apollo: Apollo) {} + constructor(protected readonly apollo: Apollo) {} public subscribe( variables?: V, diff --git a/packages/apollo-angular/src/utils.ts b/packages/apollo-angular/src/utils.ts index 90d1e6fc8..02f21136e 100644 --- a/packages/apollo-angular/src/utils.ts +++ b/packages/apollo-angular/src/utils.ts @@ -52,7 +52,7 @@ export function useMutationLoading(source: Observable>, enable } export class ZoneScheduler implements SchedulerLike { - constructor(private zone: NgZone) {} + constructor(private readonly zone: NgZone) {} public now = Date.now ? Date.now : () => +new Date(); diff --git a/packages/apollo-angular/testing/src/operation.ts b/packages/apollo-angular/testing/src/operation.ts index 1e646d6b9..b64dca764 100644 --- a/packages/apollo-angular/testing/src/operation.ts +++ b/packages/apollo-angular/testing/src/operation.ts @@ -10,8 +10,8 @@ export type Operation = LinkOperation & { export class TestOperation { constructor( - public operation: Operation, - private observer: Observer>, + public readonly operation: Operation, + private readonly observer: Observer>, ) {} public flush(result: ExecutionResult | ApolloError): void { diff --git a/packages/demo/src/app/pages/author/author-page.component.ts b/packages/demo/src/app/pages/author/author-page.component.ts index d48becba0..a77cff5b2 100644 --- a/packages/demo/src/app/pages/author/author-page.component.ts +++ b/packages/demo/src/app/pages/author/author-page.component.ts @@ -27,8 +27,8 @@ interface Query { export class AuthorPageComponent implements OnInit { posts: Observable; constructor( - private apollo: Apollo, - private route: ActivatedRoute, + private readonly apollo: Apollo, + private readonly route: ActivatedRoute, ) {} ngOnInit() { diff --git a/packages/demo/src/app/pages/posts/posts-page.component.ts b/packages/demo/src/app/pages/posts/posts-page.component.ts index 936a8f0bb..044ccabc8 100644 --- a/packages/demo/src/app/pages/posts/posts-page.component.ts +++ b/packages/demo/src/app/pages/posts/posts-page.component.ts @@ -35,7 +35,7 @@ interface Query { }) export class PostsPageComponent implements OnInit { posts: Observable; - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} ngOnInit() { this.posts = this.apollo diff --git a/packages/demo/src/app/pages/posts/upvoter.component.ts b/packages/demo/src/app/pages/posts/upvoter.component.ts index e3e5b08b5..35b27520c 100644 --- a/packages/demo/src/app/pages/posts/upvoter.component.ts +++ b/packages/demo/src/app/pages/posts/upvoter.component.ts @@ -8,7 +8,7 @@ import { Component, Input } from '@angular/core'; export class UpvoterComponent { @Input() postId: number; - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} upvote() { this.apollo diff --git a/scripts/prepare-e2e.js b/scripts/prepare-e2e.js index d138e2f96..f0a3f82a6 100755 --- a/scripts/prepare-e2e.js +++ b/scripts/prepare-e2e.js @@ -13,7 +13,7 @@ function updateComponent() { `import { versionInfo } from 'graphql';\n` + fs .readFileSync(filepath, 'utf8') - .replace('AppComponent {', 'AppComponent { constructor(private apollo: Apollo) {}') + .replace('AppComponent {', 'AppComponent { constructor(private readonly apollo: Apollo) {}') .replace('imports: [', 'imports: [ApolloModule, ') + `\n (window as any).GRAPHQL_VERSION = versionInfo.major;`; diff --git a/website/src/pages/docs/caching/advanced-topics.mdx b/website/src/pages/docs/caching/advanced-topics.mdx index 83993349d..41dc021e5 100644 --- a/website/src/pages/docs/caching/advanced-topics.mdx +++ b/website/src/pages/docs/caching/advanced-topics.mdx @@ -104,7 +104,7 @@ const SUBMIT_COMMENT_MUTATION = gql` // ... }) class CommentsPageComponent { - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} submit({repoFullName, commentContent}) { this.apollo.mutate({ diff --git a/website/src/pages/docs/data/error-handling.mdx b/website/src/pages/docs/data/error-handling.mdx index 0e41aafae..1ad9928c6 100644 --- a/website/src/pages/docs/data/error-handling.mdx +++ b/website/src/pages/docs/data/error-handling.mdx @@ -50,7 +50,7 @@ const MY_QUERY = gql` // ... }) class ShowingSomeErrorsComponent { - constructor(private apollo: Apollo) { + constructor(private readonly apollo: Apollo) { this.myQuery = this.apollo.watchQuery({ query: MY_QUERY, errorPolicy: 'all', diff --git a/website/src/pages/docs/data/mutations.mdx b/website/src/pages/docs/data/mutations.mdx index f477edc5d..02ff78295 100644 --- a/website/src/pages/docs/data/mutations.mdx +++ b/website/src/pages/docs/data/mutations.mdx @@ -67,7 +67,7 @@ const UPVOTE_POST = gql` // ... }) class UpvotePostComponent { - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} newRepository() { this.apollo.mutate({ mutation: UPVOTE_POST }).subscribe(); @@ -99,7 +99,7 @@ const UPVOTE_POST = gql` // ... }) class UpvotePostComponent { - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} upvote() { this.apollo @@ -145,7 +145,7 @@ const UPVOTE_POST = gql` providedIn: 'root', }) class UpvoteService { - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} upvote(postId: string) { return this.apollo.mutate({ @@ -161,7 +161,7 @@ class UpvoteService { // ... }) class UpvoteComponent { - constructor(private upvoteService: UpvoteService) {} + constructor(private readonly upvoteService: UpvoteService) {} newRepository() { this.upvoteService.upvote(12).subscribe( @@ -216,7 +216,7 @@ const CHANGE_POST_TITLE = gql` class PostComponent { currentUser: User; - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} upvote({ postId, title }) { this.apollo @@ -308,7 +308,7 @@ const UPVOTE_POST = gql` providedIn: 'root', }) class UpvoteService { - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} upvote(postId: string) { return this.apollo diff --git a/website/src/pages/docs/data/queries.mdx b/website/src/pages/docs/data/queries.mdx index 6a388a2b0..6f377510e 100644 --- a/website/src/pages/docs/data/queries.mdx +++ b/website/src/pages/docs/data/queries.mdx @@ -50,7 +50,7 @@ class PostsComponent implements OnInit, OnDestroy { private querySubscription: Subscription; - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} ngOnInit() { this.querySubscription = this.apollo @@ -203,7 +203,7 @@ const GET_FEED = gql` class FeedComponent implements OnInit { posts: Observable; - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} ngOnInit() { this.posts = this.apollo @@ -262,7 +262,7 @@ class PostsComponent implements OnInit, OnDestroy { private querySubscription: Subscription; - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} ngOnInit() { this.querySubscription = this.apollo @@ -327,7 +327,7 @@ class PostsComponent implements OnInit, OnDestroy { private querySubscription: Subscription; - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} ngOnInit() { this.postsQuery = this.apollo.watchQuery({ diff --git a/website/src/pages/docs/data/services.mdx b/website/src/pages/docs/data/services.mdx index 30a13b4c7..6dd4f950a 100644 --- a/website/src/pages/docs/data/services.mdx +++ b/website/src/pages/docs/data/services.mdx @@ -99,7 +99,7 @@ export class ListComponent implements OnInit { posts: Observable; // inject it - constructor(private allPostsGQL: AllPostsGQL) {} + constructor(private readonly allPostsGQL: AllPostsGQL) {} ngOnInit() { // use it! @@ -184,7 +184,7 @@ export class UpvoterComponent { @Input() postId: number; - constructor(private upvotePostGQL: UpvotePostGQL) {} + constructor(private readonly upvotePostGQL: UpvotePostGQL) {} upvote() { this.upvotePostGQL @@ -293,7 +293,7 @@ export class ListComponent implements OnInit { posts: Observable; // inject it - constructor(private allPostsGQL: AllPostsGQL) {} + constructor(private readonly allPostsGQL: AllPostsGQL) {} ngOnInit() { // use it! diff --git a/website/src/pages/docs/development-and-testing/testing.mdx b/website/src/pages/docs/development-and-testing/testing.mdx index 3dbf80fc8..eb138cd3e 100644 --- a/website/src/pages/docs/development-and-testing/testing.mdx +++ b/website/src/pages/docs/development-and-testing/testing.mdx @@ -57,7 +57,7 @@ export class DogComponent implements OnInit { error$: Observable; dog$: Observable; - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} ngOnInit() { const source$ = this.getDog(); diff --git a/website/src/pages/docs/get-started.mdx b/website/src/pages/docs/get-started.mdx index 772c7d69c..3d622d988 100644 --- a/website/src/pages/docs/get-started.mdx +++ b/website/src/pages/docs/get-started.mdx @@ -163,7 +163,7 @@ export class ExchangeRates implements OnInit { loading = true; error: any; - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} ngOnInit() { this.apollo diff --git a/website/src/pages/docs/local-state/managing-state-with-field-policies.mdx b/website/src/pages/docs/local-state/managing-state-with-field-policies.mdx index f23682d13..c48cd2bc0 100644 --- a/website/src/pages/docs/local-state/managing-state-with-field-policies.mdx +++ b/website/src/pages/docs/local-state/managing-state-with-field-policies.mdx @@ -199,7 +199,7 @@ export const GET_CART_ITEMS = gql` export class CartComponent { data: Observable; - constructor(private apollo: Apollo) { + constructor(private readonly apollo: Apollo) { // Emits a new result when cartItemsVar changes its value this.data = this.apollo.watchQuery({ query: GET_CART_ITEMS, diff --git a/website/src/pages/docs/performance/improving-performance.mdx b/website/src/pages/docs/performance/improving-performance.mdx index c56b5790b..5928474fc 100644 --- a/website/src/pages/docs/performance/improving-performance.mdx +++ b/website/src/pages/docs/performance/improving-performance.mdx @@ -44,7 +44,7 @@ class RepoInfoComponent { repoName: string; entry: any; - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} prefetchComments(repoFullName: string) { this.apollo diff --git a/website/src/pages/docs/recipes/authentication.mdx b/website/src/pages/docs/recipes/authentication.mdx index e7b9e6878..76287bc58 100644 --- a/website/src/pages/docs/recipes/authentication.mdx +++ b/website/src/pages/docs/recipes/authentication.mdx @@ -170,7 +170,7 @@ const PROFILE_QUERY = gql` @Injectable() class AuthService { - constructor(private apollo: Apollo) {} + constructor(private readonly apollo: Apollo) {} logout() { // some app logic