本文整理匯總了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);
}});
}