本文整理汇总了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;
}