【问题标题】:how to add parameter in gql query如何在gql查询中添加参数
【发布时间】:2018-07-05 16:40:57
【问题描述】:

我想在 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;
    });

宁愿添加硬编码的“名字”,我想传递一个参数?有人知道怎么做吗?

感谢您的反馈,

最好的问候,

尼古拉斯·莫让

【问题讨论】:

    标签: node.js graphql apollo gqlquery


    【解决方案1】:

    您可以使用interpolated expression 在查询中传递参数:

    contacteeFirstname: "${firstname}"
    

    【讨论】:

    • @TGrif 如果我要传递整数而不是字符串怎么办
    • @aravind_reddy 我认为您可以省略引号以不将 int 变量转换为字符串。
    猜你喜欢
    • 2018-06-21
    • 1970-01-01
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多