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

Fix writing a query with variables to the store. #394

Closed

Conversation

kevbuchanan
Copy link

This issue is also discussed in #357

The ReadWriteTransaction's resolver expects the cache key to be in the object data. When writing to the store, the data will not already have this. The existing tests for this didn't include a query with variables, which would cause the lookup to fail.

I'm not sure if the below is the best way to fix this. Seems like either the data needs to have the cache key added, or the write needs to use a different resolver that just uses the field name.

@apollo-cla
Copy link

@kevbuchanan: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

@kevbuchanan
Copy link
Author

kevbuchanan commented Oct 26, 2018

On further testing of this, it looks like this is an issue at any level of the object, so just updating the top level keys won't work. Using a responseKeyForField on writes seems to work. Not sure how to best write a unit test for this case though, I don't see any obvious queries in StarWarsAPI to use.

@Nickersoft
Copy link
Contributor

Hey @kevbuchanan! You're awesome for taking a stab at tackling this :) Seeing I'm the one who reported the original ticket.. is there anything I can do to help get this feature merged? Also, we should think about making the store class member and other related variables public so users can write to the cache directly as mentioned in the original issue.

@kevbuchanan
Copy link
Author

@Nickersoft Not sure what else needs to be done here. As far as making the store variable public from ApolloClient, I'll leave that for others to implement. I don't have any strong opinions on that as you can currently create and reference the store prior to creating the ApolloClient.

@Nickersoft
Copy link
Contributor

I suppose my concern there @kevbuchanan is just the fact I wasn't sure that if you defined a store, passed it into the ApolloClient constructor, then called a write-to-cache method on the store variable, if it would actually update the Apollo cache. From what I saw the constructor copies to the passed store variable to a member variable by-value, which would mean you'd have to call the write cache method on the class member directly. That is, unless I'm mistaken somewhere. I am relatively new to Swift, and am not 100% on how the cache is handled and propagated internally.

@rad182
Copy link

rad182 commented Nov 15, 2018

please merge this 👍

@Nickersoft
Copy link
Contributor

Can anyone make sense of why the build might be failing? I can't find a solid error message

@Nickersoft
Copy link
Contributor

@kevbuchanan @rad182 Created a separate PR that exposes the methods needed for writing to the store and features this fix: #413. This will ideally let me fix any build issues as they arise and hopefully push this feature through.

@kevbuchanan
Copy link
Author

Closing in favor of #413

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants