Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate types for loadingState exposed for deferred queries #539

Closed
clarencenpy opened this issue Aug 9, 2018 · 0 comments
Closed

Generate types for loadingState exposed for deferred queries #539

clarencenpy opened this issue Aug 9, 2018 · 0 comments
Labels
🎉 feature New addition or enhancement to existing solutions

Comments

@clarencenpy
Copy link

With @defer support coming to Apollo Client, a new field loadingState is exposed on ApolloCurrentResult, so that users are able to use it to distinguish between null and pending states for any field. Reference: apollographql/apollo-client#3686

loadingState mirrors the shape of the data that is returned from the query. For example, for a query below:

query {
  newsFeed {
    stories {
      title
      comments @defer {
        text
      }
    }
  }
}

The data returned as part of the initial response looks like this:

data: {
  newsFeed: {
    stories: {
      title: "...",
      comments: null,
    }
  }
}

And the loadingState looks like this:

loadingState: {
  newsFeed: {
    stories: {
      title: true,
      comments: undefined,
    }
  }
}

After all patches resolve, the leaf nodes of loadingState would all be set to true.

Therefore, the type associated with loadingState has the same structure as data, except that its leaf nodes are typed as undefined | boolean rather than GraphQLOutputType. It will be really nice to have codegen support for this so that users can get autocomplete on the loadingState too.

@shadaj shadaj added the 🎉 feature New addition or enhancement to existing solutions label Aug 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 feature New addition or enhancement to existing solutions
Projects
None yet
Development

No branches or pull requests

3 participants