Search code examples
reactjsgraphqlapolloapollostack

GitHunt-React: Declaring `loading` Property?


I've duplicated the following code (and all the other relevant code I could find) from GitHunt-React to my app. This code is from CommentsPage.js:

const CommentsPageWithDataAndMutations = graphql(COMMENT_QUERY, {
  options({ params }) {
    return {
      variables: { repoName: `${params.org}/${params.repoName}` },
    };
  },
  props({ data: { loading, currentUser, entry, updateQuery } }) {
    debugger;
    return { loading, currentUser, entry, updateCommentsQuery: updateQuery };
  },
})(CommentsPageWithMutations);

For some reason in my app, loading is sometimes set to true, and sometimes is undefined.When I step through this code in GitHunt-React (not my app but the original sample code), the call stack shows all React internal functions, so I can't trace it back to the code in GitHunt-React that declares loading. Also, doing a text search of the source code in GitHunt-React, doesn't seem to turn up anything setting the value of loading.

In GitHunt-React, what part of the code is responsible for declaring loading and setting its value?


Solution

  • The value of loading comes directly from Apollo Client, and is passed through react-apollo to the UI (GitHunt-React in this case).