How to load apollo graphQL data
See original GitHub issueI’m trying to load user data from a graphql query, specifically react-apollo hooks. it doesn’t appear useEffect updates are captured. The state.set({…}) doesn’t seem to update; It could be that I’m not processing useQuery() results appropriately. Can you offer me help here? I’m sure apollo and graphql users would appreciate and demonstrate how this use works.
import {useQuery} from 'react-apollo';
function getLoggedUser() {
  const {data, loading} = useQuery(queries.GET_ME);
  const {me} = data || {};
  return {me, loading};
}
Here’s where I create the state
function useUserState( ) {
  const {me, loading} = getLoggedUser();
  const state = createState({
      userName: '', 
      userTitle: '',
   });
  useEffect(() => {
    const init = () => {
      state.set({...me});
    };
    if (me) {
      init();
    }
  }, [me]);
  return useState(state);
}
This is what have in my render function.
function renderUserState(){
   const  userState = useUserState()
   console.log( userState.get());   
}
// {useName:'', useTitle: ''}
Issue Analytics
- State:
 - Created 3 years ago
 - Comments:11 (10 by maintainers)
 
Top Results From Across the Web
Queries - Apollo GraphQL Docs
This article shows how to fetch GraphQL data in React with the useQuery hook and attach the result to your UI. You'll also...
Read more >Fetching data with queries | Full-Stack Quickstart
Apollo Client provides a fetchMore helper function to assist with paginated queries. It enables you to execute the same query with different values...
Read more >Queries - Apollo GraphQL Docs
This article demonstrates how to fetch GraphQL data in React with the useQuery hook and attach the result to your UI. You'll also...
Read more >Connecting to data sources | Full-Stack Quickstart
Let's connect the SpaceX v2 REST API to our server. To do so, we'll use the RESTDataSource class from the apollo-datasource-rest package. This...
Read more >Data sources - Apollo GraphQL Docs
Data sources are classes that Apollo Server can use to encapsulate fetching data from a particular source, such as a database or a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hope it answers your questions. I have use apollo client with Hookstate. It was successful. Although I found later there are lighter GraphQL clients, which do the queries only and do not manage the state - this is what I needed, because the state was managed by Hookstate.
Promise, which you can map to the desired state value and initialize hookstate state directly with it. See async states with Hookstate: https://hookstate.js.org/docs/asynchronous-state