Accordingly to the docs this is all it takes to query something from apollo cache but it isn't working and the console.log()
is showing an empty object. The first image show that I have the entity cached.
optimistic
to false doesn't change the resultimport gql from "graphql-tag";
"apollo-client": "^2.6.8",
"graphql-tag": "^2.10.0",
onClick: p => {
const readFragment = apolloClient.readFragment({
id: 141,
fragment: gql`
fragment myMarca on Marca {
id
}
`,
optimistic: true,
});
console.log(readFragment);
}
The problem was that I was passing id: 141
. The right way is Marca:141
. Found it from this answer inside Apollo Spectrum Community.