Skip to content

Commit

Permalink
Injections are readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed May 2, 2024
1 parent 67ba1e8 commit f0b2ac0
Show file tree
Hide file tree
Showing 26 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .changeset/dirty-pigs-suffer.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"apollo-angular": patch
'apollo-angular': patch
---

ApolloClient does not delay the application becoming stable
2 changes: 1 addition & 1 deletion packages/apollo-angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const GET_DOGS = gql`
export class DogsComponent implements OnInit {
dogs: Observable<any>;

constructor(private apollo: Apollo) {}
constructor(private readonly apollo: Apollo) {}

ngOnInit() {
this.dogs = this.apollo
Expand Down
6 changes: 3 additions & 3 deletions packages/apollo-angular/http/src/http-batch-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions packages/apollo-angular/http/src/http-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-angular/http/tests/ssr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-angular/src/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class ApolloBase<TCacheShape = any> {
private useMutationLoading: boolean;

constructor(
protected ngZone: NgZone,
protected flags?: Flags,
protected readonly ngZone: NgZone,
protected readonly flags?: Flags,
protected _client?: ApolloClient<TCacheShape>,
) {
this.useInitialLoading = flags?.useInitialLoading ?? false;
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-angular/src/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export abstract class Mutation<T = {}, V extends OperationVariables = EmptyObjec
public abstract readonly document: DocumentNode | TypedDocumentNode<T, V>;
public client = 'default';

constructor(protected apollo: Apollo) {}
constructor(protected readonly apollo: Apollo) {}

public mutate(
variables?: V,
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-angular/src/query-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class QueryRef<T, V extends OperationVariables = EmptyObject> {
public queryId: ObservableQuery<T, V>['queryId'];

constructor(
private obsQuery: ObservableQuery<T, V>,
private readonly obsQuery: ObservableQuery<T, V>,
ngZone: NgZone,
options: WatchQueryOptions<V, T>,
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-angular/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export abstract class Query<T = {}, V extends OperationVariables = EmptyObject>
public abstract readonly document: DocumentNode | TypedDocumentNode<T, V>;
public client = 'default';

constructor(protected apollo: Apollo) {}
constructor(protected readonly apollo: Apollo) {}

public watch(variables?: V, options?: WatchQueryOptionsAlone<V, T>): QueryRef<T, V> {
return this.apollo.use(this.client).watchQuery<T, V>({
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-angular/src/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export abstract class Subscription<T = any, V extends OperationVariables = Empty
public abstract readonly document: DocumentNode | TypedDocumentNode<T, V>;
public client = 'default';

constructor(protected apollo: Apollo) {}
constructor(protected readonly apollo: Apollo) {}

public subscribe(
variables?: V,
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-angular/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function useMutationLoading<T>(source: Observable<FetchResult<T>>, enable
}

export class ZoneScheduler implements SchedulerLike {
constructor(private zone: NgZone) {}
constructor(private readonly zone: NgZone) {}

public now = Date.now ? Date.now : () => +new Date();

Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-angular/testing/src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export type Operation = LinkOperation & {

export class TestOperation<T = { [key: string]: any }> {
constructor(
public operation: Operation,
private observer: Observer<FetchResult<T>>,
public readonly operation: Operation,
private readonly observer: Observer<FetchResult<T>>,
) {}

public flush(result: ExecutionResult | ApolloError): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/demo/src/app/pages/author/author-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ interface Query {
export class AuthorPageComponent implements OnInit {
posts: Observable<Post[]>;
constructor(
private apollo: Apollo,
private route: ActivatedRoute,
private readonly apollo: Apollo,
private readonly route: ActivatedRoute,
) {}

ngOnInit() {
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/app/pages/posts/posts-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface Query {
})
export class PostsPageComponent implements OnInit {
posts: Observable<Post[]>;
constructor(private apollo: Apollo) {}
constructor(private readonly apollo: Apollo) {}

ngOnInit() {
this.posts = this.apollo
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/app/pages/posts/upvoter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;`;

Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/docs/caching/advanced-topics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/docs/data/error-handling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
12 changes: 6 additions & 6 deletions website/src/pages/docs/data/mutations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -99,7 +99,7 @@ const UPVOTE_POST = gql`
// ...
})
class UpvotePostComponent {
constructor(private apollo: Apollo) {}
constructor(private readonly apollo: Apollo) {}

upvote() {
this.apollo
Expand Down Expand Up @@ -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({
Expand All @@ -161,7 +161,7 @@ class UpvoteService {
// ...
})
class UpvoteComponent {
constructor(private upvoteService: UpvoteService) {}
constructor(private readonly upvoteService: UpvoteService) {}

newRepository() {
this.upvoteService.upvote(12).subscribe(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions website/src/pages/docs/data/queries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -203,7 +203,7 @@ const GET_FEED = gql`
class FeedComponent implements OnInit {
posts: Observable<any>;

constructor(private apollo: Apollo) {}
constructor(private readonly apollo: Apollo) {}

ngOnInit() {
this.posts = this.apollo
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<any>({
Expand Down
6 changes: 3 additions & 3 deletions website/src/pages/docs/data/services.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class ListComponent implements OnInit {
posts: Observable<Post[]>;

// inject it
constructor(private allPostsGQL: AllPostsGQL) {}
constructor(private readonly allPostsGQL: AllPostsGQL) {}

ngOnInit() {
// use it!
Expand Down Expand Up @@ -184,7 +184,7 @@ export class UpvoterComponent {
@Input()
postId: number;

constructor(private upvotePostGQL: UpvotePostGQL) {}
constructor(private readonly upvotePostGQL: UpvotePostGQL) {}

upvote() {
this.upvotePostGQL
Expand Down Expand Up @@ -293,7 +293,7 @@ export class ListComponent implements OnInit {
posts: Observable<Post[]>;

// inject it
constructor(private allPostsGQL: AllPostsGQL) {}
constructor(private readonly allPostsGQL: AllPostsGQL) {}

ngOnInit() {
// use it!
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/docs/development-and-testing/testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class DogComponent implements OnInit {
error$: Observable<any>;
dog$: Observable<any>;

constructor(private apollo: Apollo) {}
constructor(private readonly apollo: Apollo) {}

ngOnInit() {
const source$ = this.getDog();
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/docs/get-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const GET_CART_ITEMS = gql`
export class CartComponent {
data: Observable<any>;

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RepoInfoComponent {
repoName: string;
entry: any;

constructor(private apollo: Apollo) {}
constructor(private readonly apollo: Apollo) {}

prefetchComments(repoFullName: string) {
this.apollo
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/docs/recipes/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const PROFILE_QUERY = gql`

@Injectable()
class AuthService {
constructor(private apollo: Apollo) {}
constructor(private readonly apollo: Apollo) {}
logout() {
// some app logic

Expand Down

0 comments on commit f0b2ac0

Please sign in to comment.