我有一个从GraphQl查询获取数据的方法。我正在尝试做的是将变量标记和passID传递到graphQL查询中。
saveData ( auditid: any ) {
this.storage.get('AccessToken').then((_token) => {
var passID = auditid.toString();
var token = _token;
this.apollo.watchQuery(
{
query: gql`
{
gechecklist( id:$passID, accesstoken:$token )
{
Type,Name,
Sections
}
,ID
}
}
`,
fetchPolicy: 'cache-first',
})
.valueChanges.subscribe(( result: ApolloQueryResult<any> ) => {
let sections = result.data.gechecklist[0].Sections;
this.storage.set( name, JSON.stringify( sections )).then(() => {
this.listKeys();
});
});
});
}
watchQuery
接受一个variables
参数。请参阅查询文档。
var passID = auditid.toString();
var token = _token;
this.apollo.watchQuery({
query: gql`{
gechecklist( id:$passID, accesstoken:$token )
{
Type,Name,
Sections
}
,ID
}
}`,
variables: { passID, token },
fetchPolicy: 'cache-first',
})
你是对的。大约一天前,我确实在文档中找到了它。但是您回答了,这可以帮助遇到此问题的其他人