本文整理匯總了TypeScript中apollo-angular.Apollo.watchQuery方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Apollo.watchQuery方法的具體用法?TypeScript Apollo.watchQuery怎麽用?TypeScript Apollo.watchQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類apollo-angular.Apollo
的用法示例。
在下文中一共展示了Apollo.watchQuery方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: ngOnInit
ngOnInit() {
this.apollo.watchQuery<QueryResponse>({
query: CurrentProfile
}).subscribe(({data}) => {
this.currentProfile = data.profile;
});
}
示例2: get
get(): ApolloQueryObservable<PostsInterface> {
// Query posts data with observable variables
this.posts = this.apollo.watchQuery<PostsInterface>({
query: GetPostsQuery,
})
// Return only posts, not the whole ApolloQueryResult
.map(result => result.data.posts) as any;
return this.posts;
}
示例3: findAll
findAll(): Observable<Project[]> {
if (!this.publisher) {
this.publisher = this.apollo
.watchQuery({
query: allProjectsQuery,
})
.valueChanges.pipe(map((result: ApolloQueryResult<ProjectsResponse>) => result.data.allProjects));
}
return this.publisher;
}
示例4: getMyChannels
getMyChannels() {
const user: any = this.authenticationService.getUser() || {};
const variables: MyChannelsQuery.Variables = {
userId: user.id
};
return this.apollo.watchQuery<MyChannelsQuery.Result>({
query: myChannelsQuery,
variables,
fetchPolicy: 'cache-and-network',
});
}
示例5: ngOnInit
ngOnInit() {
this.installations$ = this.apollo
.watchQuery<AppHomeQuery>({ query })
.valueChanges.pipe(
map(({ data }) =>
data.installations
.map(installation => ({
...installation,
currentVersion: data.decidim.version
}))
.sort((a, b) => (a.name < b.name ? -1 : 1))
)
);
}
示例6: switchMap
switchMap(({ version, tags }) =>
this.apollo
.watchQuery<AppSearchQuery>({
query,
variables: { version, tags: tags ? tags.split(",") : null }
})
.valueChanges.pipe(
map(({ data }) =>
data.installations
.map(installation => ({
...installation,
currentVersion: data.decidim.version
}))
.sort((a, b) => (a.name < b.name ? -1 : 1))
)
)
示例7: ngOnInit
ngOnInit() {
this.posts = this.apollo.watchQuery<Query>({
query: gql`
query allPosts {
posts {
id
title
votes
author {
id
firstName
lastName
}
}
}
`,
})
.valueChanges
.pipe(
map(result => result.data.posts)
);
}
示例8: getAllCourses
getAllCourses(searchTerm: string) {
return this.apollo.watchQuery <Query> ({
pollInterval: 500,
query: gql `
query allCourses($searchTerm: String) {
allCourses(searchTerm: $searchTerm) {
id
title
author
description
topic
url
voteCount
}
}
`,
variables: {
searchTerm: searchTerm
}
})
.valueChanges
.pipe(map(result => result.data.allCourses));
}
示例9: queryAll
public queryAll(): Observable<ApolloQueryResult<any>> {
return this.apollo.watchQuery({ query: UPLOADS }).valueChanges;
}