【发布时间】:2019-02-15 03:52:20
【问题描述】:
我使用 Angular 6 用 Apollo 编写我的网站,以便与 graphpl 服务器交互。在将它们添加到我的gql 查询之前,我希望能够对从客户端获取的参数进行转义。
这是我的服务文件:
import { Injectable } from '@angular/core';
import {Apollo} from 'apollo-angular';
import gql from 'graphql-tag';
@Injectable({
providedIn: 'root'
})
export class ProductService {
constructor(private apollo: Apollo) { }
searchForProduct(productName: string) {
return this.apollo.watchQuery<any>({
query: gql`{products_by_p_name_search(lang_id:1,query:"${productName}")
{category_id,price,category_name,id,name,desc,quantity,year_manufacture,image_file}}`
});
}
}
正如您在此处看到的,函数searchForProduct 正在接收我添加到gql 查询中的productName 参数。如何正确转义它,以便查询包含特殊字符时不会被破坏?
谢谢!
【问题讨论】:
标签: angular escaping graphql apollo