我正在尝试在 Meteor blaze 项目中使用 Apollo graphql。
我正在使用swydo:blaze-apollo. 使用graphql查询从mongoDB中获取数据是可以的。
// Using this one can get data
const LOCATION_COUNTRY_QUERY = gql`
{
locations(location_type: "Country"){
location_id
name
iso_code
}
}
`;
Template.home.onCreated(function(){
const country = this.gqlQuery({query: LOCATION_COUNTRY_QUERY}).get();
console.log(country.locations); // Which will show an array list of country.
});
Run Code Online (Sandbox Code Playgroud)
但是,我不想在查询中对“国家/地区”进行硬编码。我想将字符串传递到查询中,然后使用其他 location_type 获取数据。但是我找不到任何关于它的文章,而 gql 语法只是阻止了任何参数。
有没有人有类似的经历,可以给点建议吗?