cache.readQuery using @client raises: Cannot read property 'kind' of undefined

1.8k Views Asked by At

I've created very simple "login" page that is supposed to store 'email' and 'password' in local cache and then, onSubmit, to display stored values on console (this is done with mutation in resolvers.js).

Saving email and password values to the cache seems to work correctly but every time I try to read values from the cache I get "Network error: Cannot read property 'kind' of undefined". Any clues what is wrong with that?

My minimal example: https://codesandbox.io/s/jv6mx6yoo9

1

There are 1 best solutions below

0
On

The problem was the lack of query parameter name in a call to readQuery (thanks to @hwillson on apollo-react #slack for pointing this out):

const LOGIN_DATA_QUERY = gql`
    query GetLoginData {
        email @client      
        password @client      
    }
`;
// (...)

const data = cache.readQuery({ LOGIN_DATA_QUERY });

should be:

const data = cache.readQuery({ query: LOGIN_DATA_QUERY });