如何在gql查询中添加参数
how to add parameter in gql query
我想在 gql 查询中添加参数:
onSubmit() {
console.log(this.contact);
let SendEmailQuery = gql`
{
sendemail(contactorFirstname:"",
contactorLastname:"",
contactorEmail:"",
contacteeFirstname:"firstname",
contacteeLastname:"",
contacteeEmail:"")
}
`;
this.apollo.watchQuery({ query: SendEmailQuery
}).valueChanges.subscribe(({data, loading}) => {
this.data = data;
this.loading = loading;
});
而不是添加 "firstname" 硬编码,我想传递一个参数?有人知道怎么做吗?
感谢您的反馈,
此致,
尼古拉斯·莫让
您可以使用 interpolated expression 在查询中传递参数:
contacteeFirstname: "${firstname}"
我想在 gql 查询中添加参数:
onSubmit() {
console.log(this.contact);
let SendEmailQuery = gql`
{
sendemail(contactorFirstname:"",
contactorLastname:"",
contactorEmail:"",
contacteeFirstname:"firstname",
contacteeLastname:"",
contacteeEmail:"")
}
`;
this.apollo.watchQuery({ query: SendEmailQuery
}).valueChanges.subscribe(({data, loading}) => {
this.data = data;
this.loading = loading;
});
而不是添加 "firstname" 硬编码,我想传递一个参数?有人知道怎么做吗?
感谢您的反馈,
此致,
尼古拉斯·莫让
您可以使用 interpolated expression 在查询中传递参数:
contacteeFirstname: "${firstname}"