【问题标题】:Using GQL from Apollo/client default variables results in "Unexpected end of JSON input"使用 Apollo/客户端默认变量中的 GQL 会导致“JSON 输入意外结束”
【发布时间】:2022-06-28 16:10:14
【问题描述】:

我正在尝试将默认变量传递给我在 React 中的 gql 查询:

query getQuery($id: UUID!, $current: Boolean = true) {
  myQuery(id: $id) {
    id
    name
    versions (current: $current) {
      id
    }
  }
}
useQuery(MY_QUERY, {
  fetchPolicy: 'network-only',
  notifyOnNetworkStatusChange: true,
  variables: {
    id: myId
  },
});

但我有一个错误Error: Unexpected end of JSON input

【问题讨论】:

    标签: reactjs graphql apollo-client


    【解决方案1】:

    使用您的默认值看起来一切正常。 这是工作 我认为您应该在另一个地方搜索错误 request payload

    import {gql} from '@apollo/client';
    
    export const getQuery = gql`
        query getQuery($id: UUID!, $current: Boolean = true) {
            myQuery(id: $id) {
                id
                name
                versions (current: $current) {
                    id
                }
            }
        }`;

    【讨论】:

      猜你喜欢
      • 2020-05-29
      • 1970-01-01
      • 2020-02-06
      • 1970-01-01
      • 2020-07-10
      • 2021-04-30
      • 2022-01-20
      • 2015-08-05
      • 1970-01-01
      相关资源
      最近更新 更多