代码之家  ›  专栏  ›  技术社区  ›  Zied Hamdi

阿波罗初学者:无法从缓存中读取数据

  •  0
  • Zied Hamdi  · 技术社区  · 6 年前

    const GET_SHOP_FILTER = gql`
      query getFilter {
        name @client
      }
    `;
    
    class ShopSuggestBox extends Component {
        render() {
            return (
                    <div>
                        <div className="name">
                            <Query query={GET_SHOP_FILTER}>
                                {({data, client}) => (
                                        <div>
                                            data is {JSON.stringify(data)}
                                        <input
                                               onChange={e => {
                                                   client.writeData({data: {name: e.target.value}})
                                               }} ...//not relevant
    

    我的问题是,我得到这些错误:

    [GraphQL错误]:消息:无法查询类型“query”上的字段“name”。,位置:[object],路径:未定义 索引js:63[GraphQL错误]:消息:未知指令“client”。,位置:[object],路径:未定义

    1 回复  |  直到 6 年前
        1
  •  3
  •   Zied Hamdi    6 年前

    好 啊

    问题是,即使doc说不需要解析器,您也必须提供一个空的解析器才能让它工作。

    我修改了代码如下(所以 doc 是错误的)

    const client = new ApolloClient({
        //uri: "http://localhost:4000/graphql"
    //  cache,
    
        clientState: {
            defaults: {
                name: "my",
                city: "",
                selectedId: null,
                previewId: null,
                selectedComplaintId: null,
            }, resolvers: {}
        }
    });