简体   繁体   中英

Apollo query object values from cache

I have a quick question about querying objects from the client cache in apollo.

I have an initial cache state like this:

cache.writeData({
   data: { value1: true, value2: { test: "123" } }
});

That my container where I attach the query data to the component:

import EditModalComponent from "..";
import gql from "graphql-tag";
import { graphql } from "@apollo/react-hoc";
import { compose, pure } from "recompose";

const QUERY2 = gql`
  query data {
    value2 @client {
      test
    }
  }
`;

const query2 = graphql(QUERY2, {
  name: "query2"
});

const EditModalWithData = compose(query2, pure)(EditModalComponent);

export default EditModalWithData;

everything works fine If I try to query value1, but If I try to query value2 with the query above I just receive a query response without any values

This is the response which I receive in my component props:

variables: {}
refetch: ƒ (variables)
fetchMore: ƒ (fetchMoreOptions)
updateQuery: ƒ (mapFn)
startPolling: ƒ (pollInterval)
stopPolling: ƒ ()
subscribeToMore: ƒ (options)
loading: false
networkStatus: 7
error: undefined
called: true
XXXXXX <- here should be something like: test: "123"

Thanks for your help!

I found the solution. You need wirte @client behind booth parameter:

const QUERY2 = gql`
  query data {
    value2 @client {
      test @client
    }
  }
`;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM