Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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
GraphQL查询中的变量_Graphql - Fatal编程技术网

GraphQL查询中的变量

GraphQL查询中的变量,graphql,Graphql,我试图在GraphQL查询中使用变量,但浏览器响应的请求不正确 这是我的密码 return this.apollo.query({ query: gql `query Project($projectId: String!){ project( where: { id: $projectId } ) { id initials } }`, variables

我试图在GraphQL查询中使用变量,但浏览器响应的请求不正确

这是我的密码

return this.apollo.query({
      query: gql `query Project($projectId: String!){
        project( where: { id: $projectId } )
          {
            id
            initials
          }
      }`,
      variables: { projectId: pid },
      fetchPolicy: 'network-only'
  })
由于某些原因,它不会在查询中拾取项目变量。当我用硬编码的值替换变量时,效果很好。
你能帮我弄明白为什么吗

代码的问题在于$projectd的数据类型。这是数据库中的一个实际id(在我的例子中是prisma)。因此,我将代码更改为:

return this.apollo.query({
      query: gql `query Project($projectId: ID!){
        project( where: { id: $projectId } )
          {
            id
            initials
          }
      }`,
      variables: { projectId: pid },
      fetchPolicy: 'network-only'
  })

它现在可以工作了


我发现graphql非常有用,并在屏幕底部提供了变量。这样可以更快地调试代码

代码的问题在于$projectd的数据类型。这是数据库中的一个实际id(在我的例子中是prisma)。因此,我将代码更改为:

return this.apollo.query({
      query: gql `query Project($projectId: ID!){
        project( where: { id: $projectId } )
          {
            id
            initials
          }
      }`,
      variables: { projectId: pid },
      fetchPolicy: 'network-only'
  })

它现在可以工作了


我发现graphql非常有用,并在屏幕底部提供了变量。这样可以更快地调试代码

我发现了代码的问题,实际上projectId是graphql中的一个ID字段,我将它作为字符串提供。我把它改成了ID,它成功了。你可以提交你自己问题的答案,然后把它标记为接受。我发现我的代码有问题,实际上projectId是graphql中的一个ID字段,我将它作为字符串提供。我把它改成了ID,它成功了。你可以提交你自己问题的答案,然后把它标记为接受。