question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AWSAppSyncClient full support for local state in gql queries (Apollo 2.5)

See original GitHub issue

Do 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:open
  • Created 5 years ago
  • Reactions:39
  • Comments:31 (4 by maintainers)

github_iconTop GitHub Comments

23reactions
idanlocommented, Jun 30, 2019

Anything new with this?

14reactions
manueliglesiascommented, Mar 20, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found