Apollo query object values from cache

Kai Schwetz :

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!

Kai Schwetz :

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

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=174209&siteId=1