本文整理汇总了TypeScript中angular2-apollo.Angular2Apollo.watchQuery方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Angular2Apollo.watchQuery方法的具体用法?TypeScript Angular2Apollo.watchQuery怎么用?TypeScript Angular2Apollo.watchQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular2-apollo.Angular2Apollo
的用法示例。
在下文中一共展示了Angular2Apollo.watchQuery方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: loadSchema
loadSchema() {
return this.apolloClient.watchQuery(schemaQuery).map(({ data: { __schema } }) => {
console.log(__schema);
this.schema = __schema;
return this.schema;
});
}
示例2: syncUser
syncUser(id: string): void {
const subscription = this.client.watchQuery({
query: gql`
query GetUser($id: ID!) {
getUser(id: $id) {
id
username
}
}
`,
variables: {
id: id
}
}).subscribe({
next: ((result: GraphQLResult) => {
this.setUser(result.data['getUser']);
subscription.unsubscribe();
}).bind(this),
error: ((error: Error) => {
console.log(`Error getting user ${error.message}`);
subscription.unsubscribe();
throw error;
}).bind(this)
});
}
示例3: ngOnInit
ngOnInit() {
this.author = this.apollo.watchQuery({
query: getAuthorQuery
})
.subscribe(({data}) => {
this.author = data.author;
});
}
示例4: getProfile
getProfile(): Observable<ApolloQueryResult> {
return this.apollo
.watchQuery({
query: gql`
query getProfile {
user {
firstName
lastName
}
}
`
})
.map(({ data }: ApolloQueryResult) => data.user)
.catch(err => Observable.throw(err));
}
示例5: executeQuery
executeQuery(queryArguments) {
this.apolloClient.watchQuery(this.queryBuilder.buildQuery(queryArguments)).subscribe({next: ({data}) => {
this.queryResults = this.queryBuilder.extractResults(data);
}});
}