I'm trying to store data in apollo cache and get this data in my component by graphql HOC
Here I init Apollo Client and add user data to the apollo cache:
const cache = new InMemoryCache();
const client = new ApolloClient({
cache,
resolvers: {}
});
cache.writeQuery({
query: GET_CURRENT_USER,
data: {
userData: {
id: 1,
name: "Alexander",
email: "[email protected]"
}
}
});
const App = () => (
<ApolloProvider client={client}>
<Main />
</ApolloProvider>
);
Here is my GET_CURRENT_USER query:
import { gql } from "apollo-boost";
export const GET_CURRENT_USER = gql`
query getUserData($id: ID!) {
userData @client {
id
name
email
}
}
`;
Here I wrapp my component into graphql HOC:
...
export default graphql(GET_CURRENT_USER)(ProfileScreen);
And I'm checking props.data property into render method of ProfileScreen component, it's fired 2 times:
error: undefined; loading: true; no userData field
error: undefined; loading: false; no userData field
Also I checked Apollo Cache and userData field is stored
Environment:
- "apollo-boost": "^0.4.3",
- "react-apollo": "^2.5.8",
- "react-native": "0.60.4",
- "apollo-cache-inmemory": "^1.6.2",
- "react": "16.8.6"