-
Notifications
You must be signed in to change notification settings - Fork 3
chore: upgrade Angular and related dependencies to version 15 #1159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
df223e7
1dc972b
9ff5a2f
8cedfef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import { Injectable } from '@angular/core' | ||
| import {BehaviorSubject, Observable, Subject} from 'rxjs' | ||
| import { BehaviorSubject, Observable, Subject } from 'rxjs' | ||
| import { Post } from '../../../models/Post' | ||
| import {Apollo, gql, QueryRef} from "apollo-angular"; | ||
| import {map, take} from "rxjs/operators"; | ||
| import { Apollo, gql, QueryRef } from 'apollo-angular' | ||
| import { map, take } from 'rxjs/operators' | ||
|
|
||
| const QUERY = gql` | ||
| query Posts($featured: Boolean, $after: String, $before: String, $first: Int, $last: Int) { | ||
|
|
@@ -57,7 +57,12 @@ export class RequestService { | |
| listQuery: QueryRef<Result> | ||
| posts?: Post[] | ||
| pageInfo?: PageInfo | ||
| pageInfo$: Subject<PageInfo> = new BehaviorSubject<PageInfo>({hasPreviousPage: true, hasNextPage: false, startCursor: "", endCursor: ""}) | ||
| pageInfo$: Subject<PageInfo> = new BehaviorSubject<PageInfo>({ | ||
| hasPreviousPage: true, | ||
| hasNextPage: false, | ||
| startCursor: '', | ||
| endCursor: '', | ||
| }) | ||
|
|
||
| constructor(private gql: Apollo) { | ||
| this.listQuery = this.gql.watchQuery<Result>({ | ||
|
|
@@ -66,58 +71,79 @@ export class RequestService { | |
| featured: false, | ||
| last: 20, | ||
| }, | ||
| fetchPolicy: 'network-only' | ||
| fetchPolicy: 'network-only', | ||
| }) | ||
|
|
||
| const s = this.listQuery.valueChanges.subscribe(res => { | ||
| const s = this.listQuery.valueChanges.subscribe((res) => { | ||
| this.pageInfo = res.data.posts.pageInfo | ||
| this.pageInfo$.next(this.pageInfo) | ||
| s.unsubscribe() | ||
| }) | ||
| } | ||
|
|
||
| async fetchMore() { | ||
| await this.listQuery.fetchMore({ | ||
| if (!this.pageInfo) { | ||
| return | ||
| } | ||
|
|
||
| const result = await this.listQuery.fetchMore({ | ||
| variables: { | ||
| last: 20, | ||
| before: this.pageInfo.endCursor | ||
| before: this.pageInfo.endCursor, | ||
| }, | ||
| updateQuery: (prev, { fetchMoreResult }) => { | ||
| this.pageInfo = fetchMoreResult.posts.pageInfo | ||
| this.pageInfo$.next(this.pageInfo) | ||
| }) | ||
|
|
||
| return { | ||
| posts: { | ||
| edges: [...prev.posts.edges, ...fetchMoreResult.posts.edges], | ||
| pageInfo: fetchMoreResult.posts.pageInfo | ||
| } | ||
| } | ||
| if (result.data) { | ||
| this.pageInfo = result.data.posts.pageInfo | ||
| this.pageInfo$.next(this.pageInfo) | ||
|
|
||
| // Update cache with merged results | ||
| const prev = this.listQuery.getCurrentResult().data | ||
| if (prev) { | ||
| this.gql.client.cache.writeQuery({ | ||
| query: QUERY, | ||
| variables: { | ||
| featured: false, | ||
| last: 20, | ||
| }, | ||
| data: { | ||
| posts: { | ||
| __typename: 'PostConnection', | ||
| edges: [...prev.posts.edges, ...result.data.posts.edges], | ||
| pageInfo: result.data.posts.pageInfo, | ||
| }, | ||
| }, | ||
| }) | ||
|
Comment on lines
+103
to
+116
|
||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| hasPreviousPage(): Observable<boolean> { | ||
| return this.pageInfo$.pipe(map(e => e.hasPreviousPage)) | ||
| return this.pageInfo$.pipe(map((e) => e.hasPreviousPage)) | ||
| } | ||
|
|
||
| listPosts(): Observable<Post[]> { | ||
| return this.listQuery.valueChanges.pipe(map(res => { | ||
| return res.data.posts.edges.map(edge => edge.node) | ||
| })) | ||
| return this.listQuery.valueChanges.pipe( | ||
| map((res) => { | ||
| return res.data.posts.edges.map((edge) => edge.node) | ||
| }) | ||
| ) | ||
| } | ||
|
|
||
| listFeaturedPosts(): Observable<Post[]> { | ||
| return this.gql.query<Result>({ | ||
| query: QUERY, | ||
| variables: { | ||
| featured: true, | ||
| last: 20 | ||
| } | ||
| }).pipe( | ||
| map(res => { | ||
| return res.data.posts.edges.map(edge => edge.node) | ||
| }), | ||
| take(1) | ||
| ) | ||
| return this.gql | ||
| .query<Result>({ | ||
| query: QUERY, | ||
| variables: { | ||
| featured: true, | ||
| last: 20, | ||
| }, | ||
| }) | ||
| .pipe( | ||
| map((res) => { | ||
| return res.data.posts.edges.map((edge) => edge.node) | ||
| }), | ||
| take(1) | ||
| ) | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,11 @@ | ||
| // This file is required by karma.conf.js and loads recursively all the .spec and framework files | ||
|
|
||
| import 'zone.js/dist/zone-testing' | ||
| import 'zone.js' | ||
| import 'zone.js/testing' | ||
| import { getTestBed } from '@angular/core/testing' | ||
| import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing' | ||
|
|
||
| declare const require: any | ||
|
|
||
| // First, initialize the Angular testing environment. | ||
| getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), { | ||
| teardown: { destroyAfterEach: false }, | ||
| }) | ||
| // Then we find all the tests. | ||
| const context = require.context('./', true, /\.spec\.ts$/) | ||
| // And load the modules. | ||
| context.keys().map(context) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,11 @@ | ||
| // This file is required by karma.conf.js and loads recursively all the .spec and framework files | ||
|
|
||
| import 'zone.js/dist/zone' | ||
|
|
||
| import 'zone.js/dist/zone-testing' | ||
| import 'zone.js' | ||
| import 'zone.js/testing' | ||
| import { getTestBed } from '@angular/core/testing' | ||
| import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing' | ||
|
|
||
| declare const require: any | ||
|
|
||
| // First, initialize the Angular testing environment. | ||
| getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), { | ||
| teardown: { destroyAfterEach: false }, | ||
| }) | ||
| // Then we find all the tests. | ||
| const context = require.context('./', true, /\.spec\.ts$/) | ||
| // And load the modules. | ||
| context.keys().map(context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fetchMore method accesses
this.pageInfo.endCursorwithout checking ifthis.pageInfois defined. If fetchMore is called before the initial subscription in the constructor completes, this will throw a runtime error. Consider adding a null check or ensuring pageInfo is initialized before allowing fetchMore to be called.