AWSAppSyncClient full support for local state in gql queries (Apollo 2.5)
See original GitHub issueDo you want to request a feature or report a bug? Feature, please consider upgrading AWSAppSyncClient dependencies from Apollo 2.4 to Apollo 2.5
What is the current behavior?
Local state support in Apollo 2.4
requires lots of boilerplate;
//2.4
const GET_CURRENT_THEATER = gql`
{
currentTheaterId @client
}
`;
const LIST_MOVIES = gql`
query list($theaterId: ID!) {
listMovies(theaterId: $theaterId) {
id,
name
}
}
`;
[...]
render() {
return <Query query={GET_CURRENT_THEATER}>{
queryRes => {
const currentTheaterId = queryRes.data.currentTheaterId;
return <Query query={LIST_MOVIES} variables={{theaterId: currentTheaterId}}>
{this.renderMovies.bind(this)}
</Query>
}
}</Query>;
}
What is the expected behavior?
Apollo 2.5
brings significant improvements by supporting injection of local state directly in the query variables with the @export directive.
//2.5
const LIST_MOVIES = gql`
query list($theaterId: ID!) {
currentTheaterId @client @export(as: "theaterId")
listMovies(theaterId: $theaterId) {
id,
name
}
}
`;
[...]
render() {
return <Query query={LIST_MOVIES}>
{this.renderMovies.bind(this)}
</Query>;
}
See also https://www.apollographql.com/docs/react/essentials/local-state.html#client-variables
Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions? aws-appsync 1.7.2
Issue Analytics
- State:
- Created 5 years ago
- Reactions:39
- Comments:31 (4 by maintainers)
Top Results From Across the Web
Local state management - Apollo GraphQL Docs
Apollo Client (>= 2.5) has built-in local state handling capabilities that allow you to store your local data inside the Apollo cache alongside...
Read more >Need a query to initialize cache when using apollo-state-link · Issue ...
Need a query to initialize cache when using apollo-state-link #330 ... AWSAppSyncClient full support for local state in gql queries (Apollo 2.5) #369....
Read more >AWS AppSync Developer Guide - Amazon S3
custom query messages to Amazon Elasticsearch Service. Settings ... AWS AppSync integrates with the Apollo GraphQL client for building client applications.
Read more >AWS AppSync query returns cached response even when ...
OK I found the issue. Here's an abbreviated version of the code from my question: client.query({ query: gql`.
Read more >React Dashboard: an Ultimate Guide - Cube Blog
Learn how to build a full-stack React Dashboard from the database to ... Apollo GraphQL client to store dashboard items into local storage....
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 FreeTop 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
Top GitHub Comments
Anything new with this?
Thanks for the report, this is on our backlog, we are doing some internal testing and PoC.
I can’t give an ETA, but we’ll keep you posted in this issue