How to read cache in Apollo client with angular
Asked Answered
S

0

1

I am writing to the cache with the update function after a mutation using Apollo Client. The cache contains the obj as shown below, and it is working properly.enter image description here

However, I can't find the right way to read the object in the cache. I am using readQuery as mentioned in the docs but I can't find any examples to read objects outside the ROOT_QUERY

I have the following code in Angular

ngOnInit() {
    const data = this.apollo.getClient().readQuery({
      query: USER,
      variables: {
        id: '[email protected]',
      },
    });
    console.log(data);
  }

And the query is defined like this:

const USER = gql`
  query User($id: String!) {
    user(id: $id) @client {
      token
    }
  }
`;

Not sure if I have to modify the typeDefs or resolvers when instantiating Apollo Client?

Thanks

Sprout answered 14/4, 2020 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.