I have a method that that gets data from a GraphQl query. What I am trying to do is pass the variables token and passID into the graphQL query.
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
takes a variables
parameter. See the query documentation.
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',
})
You are right. I did find it in the docs about a day ago. But you answered and this can help someone else who runs into this problem