Skip to content
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.

How should I update local state after fetching remote data? #331

Closed
tresdev opened this issue Nov 30, 2018 · 1 comment
Closed

How should I update local state after fetching remote data? #331

tresdev opened this issue Nov 30, 2018 · 1 comment

Comments

@tresdev
Copy link

tresdev commented Nov 30, 2018

Well it's more like a question, but so far I'm kinda confused about when to update local state, after fetching data from Remote GraphQL API Server.

For example, I have records of customers in the database and I want to get the information of some customers and save it in cache right away.

So, for fetching from server, it can be like this:

 query getCustomers($age: Int!) {    
  customers(age: $age) {    
    id   
    name   
    gender   
    address   
  }   
}

and to update local cache,

mutation updateCurrentCustomers($customers: [Customer]) {
  updateCurrentCustomers(customers: $customers) @client {
    id
    name
    gender
    address
  }
}

Should I call them separately in the component or somehow make a unified resolver functions in Client State? Or should I create some actions like in redux?

I'm not sure how to make it do things I did with redux, i.e. receiving data from the server and save it in cache with specific keys quite easily.

Maybe I'm misunderstanding the whole concept. I've read the docs and other articles but they are usually all just about local caching, not about dealing with remote and local data together smoothly.

I couldn't really find a standard example source showing how to keep fetched graphql results in the cache, more like, systematically. I believe the idea of apollo and graphql can make things much easier than redux.

@tresdev tresdev changed the title howshould I update local state after fetching remote data? How should I update local state after fetching remote data? Nov 30, 2018
@tresdev
Copy link
Author

tresdev commented Nov 30, 2018

It seems that it's pretty much related to the issue #324 , so I'm closing this issue.

@tresdev tresdev closed this as completed Nov 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant