Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 如何从.ts方法将id插入GraphQl查询_Typescript_Graphql - Fatal编程技术网

Typescript 如何从.ts方法将id插入GraphQl查询

Typescript 如何从.ts方法将id插入GraphQl查询,typescript,graphql,Typescript,Graphql,我有一个从GraphQl查询中获取数据的方法。我试图做的是将变量token和passID传递到graphQL查询中 saveData ( auditid: any ) { this.storage.get('AccessToken').then((_token) => { var passID = auditid.toString(); var token = _token; this.apollo.watchQuery( {

我有一个从GraphQl查询中获取数据的方法。我试图做的是将变量token和passID传递到graphQL查询中

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();
      });
    });
  });
}
saveData(试听:任何){
this.storage.get('AccessToken')。然后((_token)=>{
var passID=audited.toString();
var-token=_-token;
这是apollo.watchQuery(
{      
查询:gql`
{
gechecklist(id:$passID,accesstoken:$token)
{
类型、名称、,
小节
}
身份证件
}
}
`,
fetchPolicy:“缓存优先”,
})
.valueChanges.subscribe((结果:ApolloQueryResult)=>{
让sections=result.data.gechecklist[0]。sections;
this.storage.set(名称,JSON.stringify(节))。然后(()=>{
this.listKeys();
});
});
});
}

watchQuery
采用
变量
参数。看


你是对的。我确实在一天前的文件里找到了。但是你回答了,这可以帮助其他遇到这个问题的人
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',
})