React GraphQLerror:语法错误:预期名称,找到$

发布于 2025-01-29 17:37:48 字数 787 浏览 5 评论 0原文

我一直在研究Apollo grapghql,并在一个方案中累积了一个我必须将变量传递到查询的情况,但是当我尝试这样做时,我

GraphQLError: Syntax Error: Expected Name, found $

错误

let getFilters=
      {
        userPoliciesGet($filter: PolicyFilter) {
          policiesExternal {
              ${this.requestsPayload}
          }
          policiesImported {
              ${this.requestsPayload}
          }
        }
      }
    `

遇到

import apollo from './client'
apollo.query({
      query: gql`
        ${getFilters}
      `,
      variables: {
        filter: { status: 'ENDED' }
      },
      fetchPolicy: 'no-cache'
    })

会 正确并为其余的API工作。

我不明白这种方式有什么问题, 如果我尝试在没有任何变量的情况下击中此API,则可以正常工作,但是当我使用过滤器变量击中它时,它不行。

I have been working on Apollo Grapghql and come accross a scenario where i had to pass a variable to the query but I am getting an error when i try to do so

GraphQLError: Syntax Error: Expected Name, found $

Here is my query

let getFilters=
      {
        userPoliciesGet($filter: PolicyFilter) {
          policiesExternal {
              ${this.requestsPayload}
          }
          policiesImported {
              ${this.requestsPayload}
          }
        }
      }
    `

and then i am calling this query like

import apollo from './client'
apollo.query({
      query: gql`
        ${getFilters}
      `,
      variables: {
        filter: { status: 'ENDED' }
      },
      fetchPolicy: 'no-cache'
    })

The ApolloClient is configured correct and works for the rest of the api's.

I dont understand what is wrong with this way, if i try to hit this api without any variables, it works fine ,but not when i hit it with the filter varibles

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文